class RelationshipData extends Data (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 the data of a relationship object or relationship document.

Properties

protected ResourceIdentifierInterface[] $data

Various representations of JSON:API objects.

from  Data
protected int $cardinality

The number of resources permitted in this collection.

from  Data
protected bool $hasNextPage

Holds a boolean indicating if there is a next page.

from  Data
protected int $count

Holds the total count of entities.

from  Data

Methods

__construct(array $data, int $cardinality = -1)

RelationshipData constructor.

getIterator()

Returns an iterator for entities.

from  Data
int
count()

Returns the number of entities.

from  Data
getTotalCount()

{@inheritdoc}

from  Data
setTotalCount($count)

{@inheritdoc}

from  Data
toArray()

Returns the collection as an array.

from  Data
bool
hasNextPage()

Checks if there is a next page in the collection.

from  Data
setHasNextPage(bool $has_next_page)

Sets the has next page flag.

from  Data
int
getCardinality()

Gets the cardinality of this collection.

from  Data
static Data
merge(Data $a, Data $b)

Returns a new Data object containing the entities of $this and $other.

from  Data
static Data
deduplicate(Data $collection)

Returns a new, deduplicated Data object.

from  Data

Details

__construct(array $data, int $cardinality = -1)

RelationshipData constructor.

Parameters

array $data

The resources or resource identifiers for the collection.

int $cardinality

The number of resources that this collection may contain. Related resource collections may handle both to-one or to-many relationships. A to-one relationship should have a cardinality of 1. Use -1 for unlimited cardinality.

See also

Data::__construct

ArrayIterator getIterator()

Returns an iterator for entities.

Return Value

ArrayIterator

An \ArrayIterator instance

int count()

Returns the number of entities.

Return Value

int

The number of parameters

getTotalCount()

{@inheritdoc}

setTotalCount($count)

{@inheritdoc}

Parameters

$count

EntityInterface[] toArray()

Returns the collection as an array.

Return Value

EntityInterface[]

The array of entities.

bool hasNextPage()

Checks if there is a next page in the collection.

Return Value

bool

TRUE if the collection has a next page.

setHasNextPage(bool $has_next_page)

Sets the has next page flag.

Once the collection query has been executed and we build the entity collection, we now if there will be a next page with extra entities.

Parameters

bool $has_next_page

TRUE if the collection has a next page.

int getCardinality()

Gets the cardinality of this collection.

Return Value

int

The cardinality of the resource collection. -1 for unlimited cardinality.

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

Returns a new Data object containing the entities of $this and $other.

Parameters

Data $a

A Data object object to be merged.

Data $b

A Data object to be merged.

Return Value

Data

A new merged Data object.

static Data deduplicate(Data $collection)

Returns a new, deduplicated Data object.

Parameters

Data $collection

The Data object to deduplicate.

Return Value

Data

A new merged Data object.