@param Message $message
@param NodeRef $nodeRef
@param Pbjx    $pbjx

@return GetUserRequest
195732
protected function createGetUserRequest(Message $message, NodeRef $nodeRef, Pbjx $pbjx): GetUserRequest
    {
        /** @var GetUserRequest $request */
        $request = GetUserRequestV1Mixin::findOne()->createMessage();
        return $request;
    }
447147
protected function handle(GetNodeBatchRequest $request, Pbjx $pbjx): GetNodeBatchResponse
    {
        $response = $this->createGetNodeBatchResponse($request, $pbjx);
        $nodeRefs = $request->get('node_refs');

        if (empty($nodeRefs)) {
            return $response;
        }

        $context = $this->createNcrContext($request);
        $nodes = $this->ncr->getNodes($nodeRefs, $request->get('consistent_read'), $context);
        foreach ($nodes as $nodeRef => $node) {
            $this->assertIsNodeSupported($node);
            $response->addToMap('nodes', $nodeRef, $node);
        }

        $missing = array_keys(array_diff_key(array_flip(array_map('strval', $nodeRefs)), $nodes));
        $missing = array_map(function ($str) {
            return NodeRef::fromString($str);
        }, $missing);
        $response->addToSet('missing_node_refs', $missing);

        return $response;
    }
1300189
public function postUser(UserPostMessage $message): User
    {
        $path = sprintf('companies/%d/users', $message->getCompanyId());
        $data = ['api_user' => $message->build()];

        $response = $this->getClient()->sendRequest('POST', $path, $data);

        /** @var User $model */
        $model = $this->getModelFactory()->create(User::class, $response);

        return $model;
    }
804129
protected static function fetchGedcomRecord(string $xref, int $tree_id): ?string
    {
        // We don't know what type of object this is. Try each one in turn.
        $data = Individual::fetchGedcomRecord($xref, $tree_id);
        if ($data !== null) {
            return $data;
        }
        $data = Family::fetchGedcomRecord($xref, $tree_id);
        if ($data !== null) {
            return $data;
        }
        $data = Source::fetchGedcomRecord($xref, $tree_id);
        if ($data !== null) {
            return $data;
        }
        $data = Repository::fetchGedcomRecord($xref, $tree_id);
        if ($data !== null) {
            return $data;
        }
        $data = Media::fetchGedcomRecord($xref, $tree_id);
        if ($data !== null) {
            return $data;
        }
        $data = Note::fetchGedcomRecord($xref, $tree_id);
        if ($data !== null) {
            return $data;
        }

        // Some other type of record...
        return DB::table('other')
            ->where('o_file', '=', $tree_id)
            ->where('o_id', '=', $xref)
            ->value('o_gedcom');
    }
565678
public static Messaging getMessaging(final Jaxb2Marshaller jaxb2Marshaller, final WebServiceMessage message) {

        SoapHeader soapHeader = ((SoapMessage) message).getSoapHeader();
        if (soapHeader == null) {
            throw new RuntimeException("The ebMS header is missing (no SOAP header found in SOAP request)");
        }

        Iterator<SoapHeaderElement> soapHeaderElementIterator = soapHeader.examineHeaderElements(MESSAGING_QNAME);
        if (!soapHeaderElementIterator.hasNext()) {
            throw new RuntimeException("The ebMS header is missing in SOAP header");
        }

        SoapHeaderElement incomingSoapHeaderElement = soapHeaderElementIterator.next();
        try {
            return (Messaging) jaxb2Marshaller.unmarshal(incomingSoapHeaderElement.getSource());
        } catch (Exception e) {
            throw new RuntimeException("The ebMs header failed to unmarshall");
        }

    }
1263185
public function encrypt($message, $userPublicKey, $userAuthToken, $regenerateKeys = false)
    {
        if (self::MAX_MESSAGE_LENGTH < strlen($message)) {
            throw new \RuntimeException(sprintf(
                'Length of message must not be greater than %d octets.', self::MAX_MESSAGE_LENGTH
            ));
        }

        // pad the message
        $message = self::padMessage($message);

        if ($regenerateKeys) {
            $this->initialize();
        }

        $userPublicKey = Base64Url::decode($userPublicKey);
        $userAuthToken = Base64Url::decode($userAuthToken);

        // get the shared secret
        $sharedSecret = $this->getSharedSecret($userPublicKey);

        $ikm = !empty($userAuthToken) ?
            self::hkdf($userAuthToken, $sharedSecret, 'Content-Encoding: auth'.chr(0), 32) :
            $sharedSecret;

        $context = $this->createContext($userPublicKey);

        // derive the Content Encryption Key
        $contentEncryptionKey = self::hkdf($this->salt, $ikm, self::createInfo('aesgcm', $context), 16);

        // derive the nonce
        $nonce = self::hkdf($this->salt, $ikm, self::createInfo('nonce', $context), 12);

        if (version_compare(PHP_VERSION, '7.1') >= 0) {
            $encryptedText = openssl_encrypt($message, 'aes-128-gcm', $contentEncryptionKey, OPENSSL_RAW_DATA, $nonce, $tag);
        } else {
            list($encryptedText, $tag) = \AESGCM\AESGCM::encrypt($contentEncryptionKey, $nonce, $message, '');
        }

        return $encryptedText.$tag;
    }
772688
function it_should_replace_input_message_references_by_reference_html_link($reference1, $reference2) {
        $reference1->getStartIndice()->willReturn(5);
        $reference1->getEndIndice()->willReturn(10);
        $reference1->getType()->willReturn(ReferenceType::USER);
        $reference1->getData()->willReturn(array(
            "id"          => 6844292,
            "name"        => "John Doe",
            "type"        => "user",
            "offset"      => 5,
            "length"      => 5
        ));

        $reference2->getStartIndice()->willReturn(12);
        $reference2->getEndIndice()->willReturn(17);
        $reference2->getType()->willReturn(ReferenceType::PAGE);
        $reference2->getData()->willReturn(array(
            "id"          => 32425,
            "name"        => "test",
            "type"        => "page",
            "offset"      => 5,
            "length"      => 5
        ));

        $this->format('test @jdoe, @test bar', [$reference2, $reference1])
            ->shouldReturn('test <a href="https://www.facebook.com/6844292" target="_blank">@jdoe</a>, <a href="https://www.facebook.com/32425" target="_blank">@test</a> bar');

        $this->format('foo #média bar', [])
            ->shouldReturn('foo <a href="https://www.facebook.com/hashtag/média" target="_blank">#média</a> bar');

        $this->format('foo http://test.com bar', [])
            ->shouldReturn('foo <a href="http://test.com" target="_blank">http://test.com</a> bar');
    }
294330
protected function createNodeUpdated(UpdateNode $command, Pbjx $pbjx): NodeUpdated
    {
        /** @var NodeUpdated $event */
        $event = $this->createEventFromCommand($command, 'updated');
        return $event;
    }
1311211
public function createRequest(PushMessage $message) : RequestInterface
    {
        $request = new Request(
            'POST',
            $this->getUrl($message),
            $this->getHeaders($message),
            $this->getBody($message)
        );

        return $request;
    }
1221083
protected function canReadStream(GetEventsRequest $request, Pbjx $pbjx): bool
    {
        /** @var StreamId $streamId */
        $streamId = $request->get('stream_id');

        /*
         * a simplistic but mostly correct assertion that requests tend
         * to be named "acme:news:request:get-[node-label]-history-request".
         * If the incoming request is asking for that topic it is allowed.
         *
         * This only exists to prevent someone with permission to get
         * history on one thing but pass in a different stream id
         * (message permission vs message content permission).
         *
         * Override if more complex check is desired or if the convention
         * doesn't match.
         */
        $allowedTopic = str_replace(
            ['get-', '-request', '-history'],
            ['', '', '.history'],
            $request::schema()->getCurie()->getMessage()
        );

        return $allowedTopic === $streamId->getTopic();
    }
12037
protected function createNodeMarkedAsPending(MarkNodeAsPending $command, Pbjx $pbjx): NodeMarkedAsPending
    {
        /** @var NodeMarkedAsPending $event */
        $event = $this->createEventFromCommand($command, 'marked-as-pending');
        return $event;
    }
882475
public function getChartAction(ServerRequestInterface $request, Tree $tree, UserInterface $user): ResponseInterface
    {
        $ajax = (bool) $request->get('ajax');

        $xref  = $request->get('xref', '');
        $xref2 = $request->get('xref2', '');

        $individual1 = Individual::getInstance($xref, $tree);
        $individual2 = Individual::getInstance($xref2, $tree);

        $recursion = (int) $request->get('recursion', '0');
        $ancestors = (int) $request->get('ancestors', '0');

        $ancestors_only = (int) $tree->getPreference('RELATIONSHIP_ANCESTORS', static::DEFAULT_ANCESTORS);
        $max_recursion  = (int) $tree->getPreference('RELATIONSHIP_RECURSION', static::DEFAULT_RECURSION);

        $recursion = min($recursion, $max_recursion);

        if ($individual1 instanceof Individual) {
            Auth::checkIndividualAccess($individual1);
        }

        if ($individual2 instanceof Individual) {
            Auth::checkIndividualAccess($individual2);
        }

        Auth::checkComponentAccess($this, 'chart', $tree, $user);

        if ($individual1 instanceof Individual && $individual2 instanceof Individual) {
            if ($ajax) {
                return $this->chart($individual1, $individual2, $recursion, $ancestors);
            }

            /* I18N: %s are individual’s names */
            $title = I18N::translate('Relationships between %1$s and %2$s', $individual1->fullName(), $individual2->fullName());

            $ajax_url = $this->chartUrl($individual1, [
                'ajax'      => true,
                'xref2'     => $individual2->xref(),
                'recursion' => $recursion,
                'ancestors' => $ancestors,
            ]);
        } else {
            $title = I18N::translate('Relationships');

            $ajax_url = '';
        }

        return $this->viewResponse('modules/relationships-chart/page', [
            'ajax_url'          => $ajax_url,
            'ancestors'         => $ancestors,
            'ancestors_only'    => $ancestors_only,
            'ancestors_options' => $this->ancestorsOptions(),
            'individual1'       => $individual1,
            'individual2'       => $individual2,
            'max_recursion'     => $max_recursion,
            'module_name'       => $this->name(),
            'recursion'         => $recursion,
            'recursion_options' => $this->recursionOptions($max_recursion),
            'title'             => $title,
        ]);
    }
1190524
protected function _watch($message)
    {
        $reference = $message->reference();
        if (!$reference) {
            Suite::register($message->name());
            return $message;
        }
        if (is_object($reference)) {
            Suite::register(get_class($reference));
        }
        Suite::register(Suite::hash($reference));
        return $message;
    }
144386
private function prepareRequest(MessageInterface $message, RecipientInterface $recipient) {
        $uri = new Uri($recipient->getEndpoint());
        return Pusher::createStandardRequest($message, $recipient)->withUri($uri);
    }
1166865
public function getChartAction(ServerRequestInterface $request, Tree $tree, UserInterface $user): ResponseInterface
    {
        Auth::checkComponentAccess($this, 'chart', $tree, $user);

        $ajax      = (bool) $request->get('ajax');
        $xrefs     = (array) $request->get('xrefs', []);
        $addxref   = $request->get('addxref', '');
        $addfam    = (bool) $request->get('addfam', false);
        $placename = $request->get('placename', '');
        $start     = $request->get('start', '');
        $end       = $request->get('end', '');

        $place      = new Place($placename, $tree);
        $start_date = new Date($start);
        $end_date   = new Date($end);

        $xrefs = array_unique($xrefs);

        // Add an individual, and family members
        $individual = Individual::getInstance($addxref, $tree);
        if ($individual !== null) {
            $xrefs[] = $addxref;
            if ($addfam) {
                $xrefs = array_merge($xrefs, $this->closeFamily($individual));
            }
        }

        // Select by date and/or place.
        if ($start_date->isOK() && $end_date->isOK() && $placename !== '') {
            $date_xrefs  = $this->findIndividualsByDate($start_date, $end_date, $tree);
            $place_xrefs = $this->findIndividualsByPlace($place, $tree);
            $xrefs       = array_intersect($date_xrefs, $place_xrefs);
        } elseif ($start_date->isOK() && $end_date->isOK()) {
            $xrefs = $this->findIndividualsByDate($start_date, $end_date, $tree);
        } elseif ($placename !== '') {
            $xrefs = $this->findIndividualsByPlace($place, $tree);
        }

        // Filter duplicates and private individuals.
        $xrefs = array_unique($xrefs);
        $xrefs = array_filter($xrefs, static function (string $xref) use ($tree): bool {
            $individual = Individual::getInstance($xref, $tree);

            return $individual !== null && $individual->canShow();
        });

        if ($ajax) {
            $subtitle = $this->subtitle(count($xrefs), $start_date, $end_date, $placename);

            return $this->chart($tree, $xrefs, $subtitle);
        }

        $ajax_url = route('module', [
            'ajax'   => true,
            'module' => $this->name(),
            'action' => 'Chart',
            'ged'    => $tree->name(),
            'xrefs'  => $xrefs,
        ]);

        $reset_url = route('module', [
            'module' => $this->name(),
            'action' => 'Chart',
            'ged'    => $tree->name(),
        ]);

        return $this->viewResponse('modules/lifespans-chart/page', [
            'ajax_url'    => $ajax_url,
            'module_name' => $this->name(),
            'reset_url'   => $reset_url,
            'title'       => $this->title(),
            'xrefs'       => $xrefs,
        ]);
    }
244527
public static function forNodeRef(NodeRef $nodeRef, ?\Throwable $previous = null): self
    {
        $e = new self("The node ({$nodeRef->toString()}) could not be found.", $previous);
        $e->nodeRef = $nodeRef;
        return $e;
    }
113609
public function getConversation(Message $message, User $user)
    {
        return $this->messageRepo->findAncestors($message, $user);
    }