示例#1
0
 public function testCanSetLinkUrl()
 {
     $url = 'http://example.com/docs.html';
     $link = new Link('describedby');
     $link->setUrl($url);
     $this->assertEquals($url, $link->getUrl());
 }
示例#2
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 Exception\DomainException(sprintf('Link from resource provided to %s was incomplete; must contain a URL or a route', __METHOD__));
     }
     if ($linkDefinition->hasUrl()) {
         return 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('href' => $path);
     }
     return array('href' => call_user_func($this->serverUrlHelper, $path));
 }