Add multiple links to the links collection
public addLinks ( string $rel, array $links, boolean $overwrite = true ) : boolean | ||
$rel | string | The relation of the links to the document. See RFC 5988. |
$links | array | An array of FOFHalLink objects |
$overwrite | boolean | When false and a link of $rel relation exists, an array of links is created. Otherwise the existing link is overwriten with the new one |
return | boolean | True if the link was added to the collection |
/** * @covers FOF30\Hal\Links::getLinks */ function testGetLinks() { // Create a sample link $newlinks = array('foo' => array(new Link('http://www.example.com/yeah.json', false, 'Something'), new Link('http://www.example.com/another.json', false, 'Something else')), 'bar' => array(new Link('http://www.example.com/foo{?id}.json', true, 'Foo link'), new Link('http://www.example.com/bar{?id}.json', true, 'Bar link'))); $linkset = new Links(); $linkset->addLinks('foo', $newlinks['foo']); $linkset->addLinks('bar', $newlinks['bar']); $links = $linkset->getLinks(); $this->assertArrayHasKey('foo', $links); $this->assertArrayHasKey('bar', $links); $this->assertEquals($newlinks['foo'][0], $links['foo'][0]); $this->assertEquals($newlinks['foo'][1], $links['foo'][1]); $this->assertEquals($newlinks['bar'][0], $links['bar'][0]); $this->assertEquals($newlinks['bar'][1], $links['bar'][1]); $links = $linkset->getLinks('foo'); $this->assertEquals($newlinks['foo'][0], $links[0]); $this->assertEquals($newlinks['foo'][1], $links[1]); $links = $linkset->getLinks('baz'); $this->assertInternalType('array', $links); $this->assertEmpty($links); }
/** * Add links to the document * * @param string $rel The relation of the link to the document. See RFC 5988 * @param array $links An array of FOFHalLink objects * @param boolean $overwrite When false and a link of $rel relation exists, an array of * links is created. Otherwise the existing link is overwriten * with the new one * * @see Links::addLinks * * @return boolean */ public function addLinks($rel, array $links, $overwrite = true) { return $this->_links->addLinks($rel, $links, $overwrite); }