class ResourceObjectData extends Data implements TopLevelDataInterface (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 primary data for individual and collection documents.

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)

ResourceObjectData 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
getData()

Returns the data for the top-level data member of a JSON:API document.

getAccessible()

Gets only data to be exposed.

getOmissions()

Gets only data to be omitted.

getMergedLinks(LinkCollection $top_level_links)

Merges the object's links with the top-level links.

array
getMergedMeta(array $top_level_meta)

Merges the object's meta member with the top-level meta member.

Details

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

ResourceObjectData 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.

Data getData()

Returns the data for the top-level data member of a JSON:API document.

Return Value

Data

The top-level data.

ResourceObjectData getAccessible()

Gets only data to be exposed.

Return Value

ResourceObjectData

OmittedData getOmissions()

Gets only data to be omitted.

Return Value

OmittedData

The omitted data.

Merges the object's links with the top-level links.

Parameters

LinkCollection $top_level_links

The top-level links to merge.

Return Value

LinkCollection

The merged links.

array getMergedMeta(array $top_level_meta)

Merges the object's meta member with the top-level meta member.

Parameters

array $top_level_meta

The top-level links to merge.

Return Value

array

The merged meta member.