Ejemplo n.º 1
0
 /**
  * @inheritDoc
  */
 public function extract(Link $object)
 {
     if (!$object->isComplete()) {
         throw new DomainException(sprintf('Link from resource provided to %s was incomplete; must contain a URL or a route', __METHOD__));
     }
     $representation = $object->getProps();
     if ($object->hasUrl()) {
         $representation['href'] = $object->getUrl();
         return $representation;
     }
     $reuseMatchedParams = true;
     $options = $object->getRouteOptions();
     if (isset($options['reuse_matched_params'])) {
         $reuseMatchedParams = (bool) $options['reuse_matched_params'];
         unset($options['reuse_matched_params']);
     }
     $representation['href'] = $this->linkUrlBuilder->buildLinkUrl($object->getRoute(), $object->getRouteParams(), $options, $reuseMatchedParams);
     return $representation;
 }
Ejemplo n.º 2
0
 /**
  * @inheritDoc
  */
 public function extract(Link $object)
 {
     if (!$object->isComplete()) {
         throw new DomainException(sprintf('Link from resource provided to %s was incomplete; must contain a URL or a route', __METHOD__));
     }
     $representation = $object->getProps();
     if ($object->hasUrl()) {
         $representation['href'] = $object->getUrl();
         return $representation;
     }
     $reuseMatchedParams = true;
     $options = $object->getRouteOptions();
     if (isset($options['reuse_matched_params'])) {
         $reuseMatchedParams = (bool) $options['reuse_matched_params'];
         unset($options['reuse_matched_params']);
     }
     $path = call_user_func($this->urlHelper, $object->getRoute(), $object->getRouteParams(), $options, $reuseMatchedParams);
     if (substr($path, 0, 4) == 'http') {
         $representation['href'] = $path;
     } else {
         $representation['href'] = $this->getServerUrl() . $path;
     }
     return $representation;
 }
Ejemplo n.º 3
0
 public function testIsCompleteReturnsTrueWhenRouteIsSet()
 {
     $link = new Link('describedby');
     $link->setRoute('api/docs');
     $this->assertTrue($link->isComplete());
 }
Ejemplo n.º 4
0
 /**
  * Create a URL from a Link
  *
  * @param  Link $linkDefinition
  * @return array
  * @throws Exception\DomainException if Link is incomplete
  */
 public function fromLink(Link $linkDefinition)
 {
     if (!$linkDefinition->isComplete()) {
         throw new DomainException(sprintf('Link from resource provided to %s was incomplete; must contain a URL or a route', __METHOD__));
     }
     $representation = $linkDefinition->getProps();
     if ($linkDefinition->hasUrl()) {
         return array_merge($representation, array('href' => $linkDefinition->getUrl()));
     }
     $reuseMatchedParams = true;
     $options = $linkDefinition->getRouteOptions();
     if (isset($options['reuse_matched_params'])) {
         $reuseMatchedParams = (bool) $options['reuse_matched_params'];
         unset($options['reuse_matched_params']);
     }
     $path = call_user_func($this->urlHelper, $linkDefinition->getRoute(), $linkDefinition->getRouteParams(), $options, $reuseMatchedParams);
     if (substr($path, 0, 4) == 'http') {
         return array_merge($representation, array('href' => $path));
     }
     return array_merge($representation, array('href' => call_user_func($this->serverUrlHelper, $path)));
 }