Class LinkProvider
PSR-13 LinkProvider implementation.
Collects and provides hypermedia links.
Usage
$provider = new LinkProvider([
new Link('/api/users', 'self'),
new Link('/api/users?page=2', 'next'),
]);
foreach ($provider->getLinks() as $link) {
echo $link->getHref();
}
Method Summary
-
__construct() public
Constructor.
-
getLinks() public
Returns an iterable of LinkInterface objects.
-
getLinksByRel() public
Returns an iterable of LinkInterface objects that have a specific relationship.
-
withLink() public
Returns an instance with the specified link included.
-
withoutLink() public
Returns an instance with the specifed link removed.
Method Detail
__construct() ¶ public
__construct(iterable<Psr\Link\LinkInterface> $links = [])
Constructor.
Parameters
-
iterable<Psr\Link\LinkInterface>$links optional Initial links.
getLinks() ¶ public
getLinks(): iterable<LinkInterface>
Returns an iterable of LinkInterface objects.
The iterable may be an array or any PHP \Traversable object. If no links are available, an empty array or \Traversable MUST be returned.
Returns
iterable<LinkInterface>getLinksByRel() ¶ public
getLinksByRel(string $rel): iterable<LinkInterface>
Returns an iterable of LinkInterface objects that have a specific relationship.
The iterable may be an array or any PHP \Traversable object. If no links with that relationship are available, an empty array or \Traversable MUST be returned.
Parameters
-
string$rel
Returns
iterable<LinkInterface>withLink() ¶ public
withLink(LinkInterface $link): static
Returns an instance with the specified link included.
If the specified link is already present, this method MUST return normally without errors. The link is present if $link is === identical to a link object already in the collection.
Parameters
-
LinkInterface$link
Returns
staticwithoutLink() ¶ public
withoutLink(LinkInterface $link): static
Returns an instance with the specifed link removed.
If the specified link is not present, this method MUST return normally without errors. The link is present if $link is === identical to a link object already in the collection.
Parameters
-
LinkInterface$link
Returns
static