abstract class Data implements IteratorAggregate, Countable (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 and included objects of a top-level object.

Properties

protected ResourceIdentifierInterface[] $data

Various representations of JSON:API objects.

protected int $cardinality

The number of resources permitted in this collection.

protected bool $hasNextPage

Holds a boolean indicating if there is a next page.

protected int $count

Holds the total count of entities.

Methods

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

Instantiates a Data object.

getIterator()

Returns an iterator for entities.

int
count()

Returns the number of entities.

getTotalCount()

{@inheritdoc}

setTotalCount($count)

{@inheritdoc}

toArray()

Returns the collection as an array.

bool
hasNextPage()

Checks if there is a next page in the collection.

setHasNextPage(bool $has_next_page)

Sets the has next page flag.

int
getCardinality()

Gets the cardinality of this collection.

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

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

static Data
deduplicate(Data $collection)

Returns a new, deduplicated Data object.

Details

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

Instantiates a Data object.

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.

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.