コード例 #1
0
 /**
  * Executes the specified link and embeds the response in the current instance entity.
  *
  * @param \Gedcomx\Links\Link                              $link
  * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,...
  *
  * @throws Exception\GedcomxApplicationException
  */
 protected function embed(Link $link, StateTransitionOption $option = null)
 {
     if ($link->getHref() != null) {
         $this->lastEmbeddedRequest = $this->createRequestForEmbeddedResource('GET', $link);
         $this->lastEmbeddedResponse = $this->passOptionsTo('invoke', array($this->lastEmbeddedRequest), func_get_args());
         if ($this->lastEmbeddedResponse->getStatusCode() == 200) {
             $json = json_decode($this->lastEmbeddedResponse->getBody(), true);
             $entityClass = get_class($this->entity);
             $this->entity->embed(new $entityClass($json));
         } else {
             if (floor($this->lastEmbeddedResponse->getStatusCode() / 100) == 5) {
                 throw new GedcomxApplicationException(sprintf("Unable to load embedded resources: server says \"%s\" at %s.", $this->lastEmbeddedResponse . getClientResponseStatus() . getReasonPhrase(), $this->lastEmbeddedRequest . getURI()), $this->lastEmbeddedResponse);
             } else {
                 //todo: log a warning? throw an error?
             }
         }
     }
 }
コード例 #2
0
 /**
  * Create a request object to retrieve embedded resources
  *
  * @param string              $method
  * @param \Gedcomx\Links\Link $link
  *
  * @return \GuzzleHttp\Psr7\Request
  */
 protected function createRequestForEmbeddedResource($method, Link $link)
 {
     return $this->createAuthenticatedGedcomxRequest($method, $link->getHref(), FamilySearchRequest::getMediaTypes());
 }
コード例 #3
0
 /**
  * Delete a discussion reference
  *
  * @param \Gedcomx\Extensions\FamilySearch\Platform\Tree\DiscussionReference $reference
  * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,...
  *
  * @throws \Gedcomx\Rs\Client\Exception\GedcomxApplicationException
  * @return FamilyTreePersonState
  */
 public function deleteDiscussionReference(DiscussionReference $reference, StateTransitionOption $option = null)
 {
     $link = null;
     if ($reference->getLinks() != null) {
         $link = $reference->getLink(Rel::DISCUSSION_REFERENCE);
         if ($link == null) {
             $link = $reference->getLink(Rel::SELF);
         }
     }
     if ($link == null) {
         $link = new Link();
         $link->setHref($reference->getResource());
     }
     if ($link == null || $link->getHref() == null) {
         throw new GedcomxApplicationException("Discussion reference cannot be deleted: missing link.");
     }
     $request = $this->createAuthenticatedRequest('DELETE', $link->getHref(), FamilySearchRequest::getMediaTypes());
     return $this->stateFactory->createState('PersonState', $this->client, $request, $this->passOptionsTo('invoke', array($request), func_get_args()), $this->accessToken);
 }