final class Link implements CacheableDependencyInterface (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.
 

Represents an RFC8288 based link.

Traits

Trait for \Drupal\Core\Cache\CacheableDependencyInterface.

Properties

protected string[] $cacheContexts

Cache contexts.

from  CacheableDependencyTrait
protected string[] $cacheTags

Cache tags.

from  CacheableDependencyTrait
protected int $cacheMaxAge

Cache max-age.

from  CacheableDependencyTrait
protected Url $uri

The link URI.

protected string $href

The URI, as a string.

protected string[] $rel

The link relation types.

protected string[] $attributes

The link target attributes.

Methods

$this
setCacheability(CacheableDependencyInterface $cacheability)

Sets cacheability; useful for value object constructors.

getCacheTags()

{@inheritdoc}

__construct(CacheableMetadata $cacheability, Url $url, string $link_relation_type, array $target_attributes = [])

JSON:API Link constructor.

Url
getUri()

Gets the link's URI.

string
getHref()

Gets the link's URI as a string.

string
getLinkRelationType()

Gets the link's relation type.

string[]
getTargetAttributes()

Gets the link's target attributes.

static int
compare(Link $a, Link $b)

Compares two links.

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

Merges two equivalent links into one link with the merged cacheability.

Details

protected $this setCacheability(CacheableDependencyInterface $cacheability)

Sets cacheability; useful for value object constructors.

Parameters

CacheableDependencyInterface $cacheability

The cacheability to set.

Return Value

$this

getCacheTags()

{@inheritdoc}

getCacheContexts()

{@inheritdoc}

getCacheMaxAge()

{@inheritdoc}

__construct(CacheableMetadata $cacheability, Url $url, string $link_relation_type, array $target_attributes = [])

JSON:API Link constructor.

Parameters

CacheableMetadata $cacheability

Any cacheability metadata associated with the link. For example, a 'call-to-action' link might reference a registration resource if an event has vacancies or a wait-list resource otherwise. Therefore, the link's cacheability might be depend on a certain entity's values other than the entity on which the link will appear.

Url $url

The Url object for the link.

string $link_relation_type

An array of registered or extension RFC8288 link relation types.

array $target_attributes

An associative array of target attributes for the link.

See also

https://tools.ietf.org/html/rfc8288#section-2.1

Url getUri()

Gets the link's URI.

Return Value

Url

The link's URI as a Url object.

string getHref()

Gets the link's URI as a string.

Return Value

string

The link's URI as a string.

string getLinkRelationType()

Gets the link's relation type.

Return Value

string

The link's relation type.

string[] getTargetAttributes()

Gets the link's target attributes.

Return Value

string[]

The link's target attributes.

static int compare(Link $a, Link $b)

Compares two links.

Parameters

Link $a

The first link.

Link $b

The second link.

Return Value

int

0 if the links can be considered identical, an integer greater than or less than 0 otherwise.

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

Merges two equivalent links into one link with the merged cacheability.

The links must share the same URI, link relation type and attributes.

Parameters

Link $a

The first link.

Link $b

The second link.

Return Value

Link

A new JSON:API Link object with the cacheability of both links merged.