class IncludeResolver (View source)

internal  JSON:API maintains no PHP API since its API is the HTTP API. This class may change at any time and this will break any dependencies on it.
 

Resolves included resources for an entity or collection of entities.

Properties

protected EntityTypeManagerInterface $entityTypeManager

The entity type manager.

protected EntityAccessChecker $entityAccessChecker

The JSON:API entity access checker.

Methods

__construct(EntityTypeManagerInterface $entity_type_manager, EntityAccessChecker $entity_access_checker)

IncludeResolver constructor.

resolve(ResourceIdentifierInterface|ResourceObjectData $data, string $include_parameter)

Resolves included resources.

resolveIncludeTree(array $include_tree, Data $data, Data $includes = NULL)

Receives a tree of include field names and resolves resources for it.

static array
toIncludeTree(ResourceObjectData $data, string $include_parameter)

Returns a tree of field names to include from an include parameter.

static array
resolveInternalIncludePaths(ResourceType $base_resource_type, array $paths)

Resolves an array of public field paths.

static array
buildTree(array $paths)

Takes an array of exploded paths and builds a tree of field names.

Details

__construct(EntityTypeManagerInterface $entity_type_manager, EntityAccessChecker $entity_access_checker)

IncludeResolver constructor.

Parameters

EntityTypeManagerInterface $entity_type_manager
EntityAccessChecker $entity_access_checker

IncludedData resolve(ResourceIdentifierInterface|ResourceObjectData $data, string $include_parameter)

Resolves included resources.

Parameters

ResourceIdentifierInterface|ResourceObjectData $data

The resource(s) for which to resolve includes.

string $include_parameter

The include query parameter to resolve.

Return Value

IncludedData

An IncludedData object of resolved resources to be included.

Exceptions

PluginNotFoundException
InvalidPluginDefinitionException

protected Data resolveIncludeTree(array $include_tree, Data $data, Data $includes = NULL)

Receives a tree of include field names and resolves resources for it.

This method takes a tree of relationship field names and JSON:API Data object. For the top-level of the tree and for each entity in the collection, it gets the target entity type and IDs for each relationship field. The method then loads all of those targets and calls itself recursively with the next level of the tree and those loaded resources.

Parameters

array $include_tree

The include paths, represented as a tree.

Data $data

The entity collection from which includes should be resolved.

Data $includes

(Internal use only) Any prior resolved includes.

Return Value

Data

A JSON:API Data of included items.

Exceptions

PluginNotFoundException
InvalidPluginDefinitionException

static protected array toIncludeTree(ResourceObjectData $data, string $include_parameter)

Returns a tree of field names to include from an include parameter.

Parameters

ResourceObjectData $data

The base resources for which includes should be resolved.

string $include_parameter

The raw include parameter value.

Return Value

array

A multi-dimensional array representing a tree of field names to be included. Array keys are the field names. Leaves are empty arrays.

static protected array resolveInternalIncludePaths(ResourceType $base_resource_type, array $paths)

Resolves an array of public field paths.

Parameters

ResourceType $base_resource_type

The base resource type from which to resolve an internal include path.

array $paths

An array of exploded include paths.

Return Value

array

An array of all possible internal include paths derived from the given public include paths.

See also

self::buildTree

static protected array buildTree(array $paths)

Takes an array of exploded paths and builds a tree of field names.

Input example: [ ['one', 'two', 'three'], ['one', 'two', 'four'], ['one', 'two', 'internal'], ]

Output example: [ 'one' => [ 'two' [ 'three' => [], 'four' => [], 'internal' => [], ], ], ]

Parameters

array $paths

An array of exploded include paths.

Return Value

array

A multi-dimensional array representing a tree of field names to be included. Array keys are the field names. Leaves are empty arrays.