/** * Add a link * * @param Link $link * @param bool $overwrite * @return self * @throws Exception\DomainException */ public function add(Link $link, $overwrite = false) { $relation = $link->getRelation(); if (!isset($this->links[$relation]) || $overwrite || 'self' == $relation) { $this->links[$relation] = $link; return $this; } if ($this->links[$relation] instanceof Link) { $this->links[$relation] = array($this->links[$relation]); } if (!is_array($this->links[$relation])) { $type = (is_object($this->links[$relation]) ? get_class($this->links[$relation]) : gettype($this->links[$relation])); throw new Exception\DomainException(sprintf( '%s::$links should be either a %s\Link or an array; however, it is a "%s"', __CLASS__, __NAMESPACE__, $type )); } $this->links[$relation][] = $link; return $this; }
public function testConstructorTakesLinkRelationName() { $link = new Link('describedby'); $this->assertEquals('describedby', $link->getRelation()); }