final class LinkCollection implements IteratorAggregate (View source)

internal  JSON:API maintains no PHP API. The API is the HTTP API. This class may change at any time and could break any dependencies on it.
 

Contains a set of JSON:API Link objects.

Properties

$links

The links in the collection, keyed by unique strings.

protected JsonApiDocumentTopLevel|ResourceObject|Relationship $context

The link context.

Methods

__construct(array $links, JsonApiDocumentTopLevel|ResourceObject|Relationship $context = NULL)

LinkCollection constructor.

getIterator()

{@inheritdoc}

withLink(string $key, Link $new_link)

Gets a new LinkCollection with the given link inserted.

bool
hasLinkWithKey(string $key)

Whether a link with the given key exists.

withContext(JsonApiDocumentTopLevel|ResourceObject|Relationship $context)

Establishes a new context for a LinkCollection.

getContext()

Gets the LinkCollection's context object.

filter(callable $f)

Filters a LinkCollection using the provided callback.

static LinkCollection
merge(LinkCollection $a, LinkCollection $b)

Merges two LinkCollections.

static bool
validKey(string $key)

Ensures that a link key is valid.

Details

__construct(array $links, JsonApiDocumentTopLevel|ResourceObject|Relationship $context = NULL)

LinkCollection constructor.

Parameters

array $links

An associated array of key names and JSON:API Link objects.

JsonApiDocumentTopLevel|ResourceObject|Relationship $context

(internal use only) The context object. Use the self::withContext() method to establish a context. This should be done automatically when a LinkCollection is passed into a context object.

getIterator()

{@inheritdoc}

Gets a new LinkCollection with the given link inserted.

Parameters

string $key

A key for the link. If the key already exists and the link shares an href, link relation type and attributes with an existing link with that key, those links will be merged together.

Link $new_link

The link to insert.

Return Value

LinkCollection

A new LinkCollection with the given link inserted or merged with the current set of links.

bool hasLinkWithKey(string $key)

Whether a link with the given key exists.

Parameters

string $key

The key.

Return Value

bool

TRUE if a link with the given key exist, FALSE otherwise.

LinkCollection withContext(JsonApiDocumentTopLevel|ResourceObject|Relationship $context)

Establishes a new context for a LinkCollection.

Parameters

JsonApiDocumentTopLevel|ResourceObject|Relationship $context

The new context object.

Return Value

LinkCollection

A new LinkCollection with the given context.

JsonApiDocumentTopLevel|ResourceObject|Relationship getContext()

Gets the LinkCollection's context object.

Return Value

JsonApiDocumentTopLevel|ResourceObject|Relationship

The LinkCollection's context.

LinkCollection filter(callable $f)

Filters a LinkCollection using the provided callback.

Parameters

callable $f

The filter callback. The callback has the signature below.

Return Value

LinkCollection

A new, filtered LinkCollection.

static LinkCollection merge(LinkCollection $a, LinkCollection $b)

Merges two LinkCollections.

Parameters

LinkCollection $a

The first link collection.

LinkCollection $b

The second link collection.

Return Value

LinkCollection

A new LinkCollection with the links of both inputs.

static protected bool validKey(string $key)

Ensures that a link key is valid.

Parameters

string $key

A key name.

Return Value

bool

TRUE if the key is valid, FALSE otherwise.