ResourceIdentifier
class ResourceIdentifier implements ResourceIdentifierInterface (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 a JSON:API resource identifier object.
The official JSON:API JSON-Schema document requires that no two resource identifier objects are duplicates, however Drupal allows multiple entity reference items to the same entity. Here, these are termed "parallel" relationships (as in "parallel edges" of a graph).
This class adds a concept of an @code arity @endcode member under each its
Constants
| ARITY_KEY |
|
Properties
| protected string | $resourceTypeName | The JSON:API resource type name. |
|
| protected ResourceType | $resourceType | The JSON:API resource type. |
|
| protected string | $id | The resource ID. |
|
| protected array | $meta | The relationship's metadata. |
Methods
ResourceIdentifier constructor.
Gets the ResourceIdentifier's JSON:API resource type name.
Gets the resource identifier's JSON:API resource type.
Gets the ResourceIdentifier's ID.
Whether this ResourceIdentifier has an arity.
Gets the ResourceIdentifier's arity.
Returns a copy of the given ResourceIdentifier with the given arity.
Gets the resource identifier objects metadata.
Determines if two ResourceIdentifiers are the same.
Determines if two ResourceIdentifiers identify the same resource object.
Deduplicates an array of ResourceIdentifier objects.
Determines if an array of ResourceIdentifier objects is duplicate free.
Creates a ResourceIdentifier object.
Creates an array of ResourceIdentifier objects.
Creates an array of ResourceIdentifier objects with arity on every value.
Helper method to determine which field item property contains an entity.
Creates a ResourceIdentifier for a NULL or FALSE entity reference item.
Details
__construct(ResourceType|string $resource_type, string $id, array $meta = [])
ResourceIdentifier constructor.
string
getTypeName()
Gets the ResourceIdentifier's JSON:API resource type name.
ResourceType
getResourceType()
Gets the resource identifier's JSON:API resource type.
string
getId()
Gets the ResourceIdentifier's ID.
int
hasArity()
Whether this ResourceIdentifier has an arity.
int
getArity()
Gets the ResourceIdentifier's arity.
One must check self::hasArity() before calling this method.
ResourceIdentifier
withArity(int $arity)
Returns a copy of the given ResourceIdentifier with the given arity.
array
getMeta()
Gets the resource identifier objects metadata.
static bool
isDuplicate(ResourceIdentifier $a, ResourceIdentifier $b)
Determines if two ResourceIdentifiers are the same.
This method does not consider parallel relationships with different arity values to be duplicates. For that, use the isParallel() method.
static bool
isParallel(ResourceIdentifier $a, ResourceIdentifier $b)
Determines if two ResourceIdentifiers identify the same resource object.
This method does not consider arity.
static int
compare(ResourceIdentifier $a, ResourceIdentifier $b)
Compares ResourceIdentifier objects.
static ResourceIdentifier[]
deduplicate(array $resource_identifiers)
Deduplicates an array of ResourceIdentifier objects.
static bool
areResourceIdentifiersUnique(array $resource_identifiers)
Determines if an array of ResourceIdentifier objects is duplicate free.
static ResourceIdentifier
toResourceIdentifier(EntityReferenceItem $item, int $arity = NULL)
Creates a ResourceIdentifier object.
static ResourceIdentifier[]
toResourceIdentifiers(EntityReferenceFieldItemListInterface $items)
Creates an array of ResourceIdentifier objects.
static ResourceIdentifier[]
toResourceIdentifiersWithArityRequired(EntityReferenceFieldItemListInterface $items)
Creates an array of ResourceIdentifier objects with arity on every value.
static ResourceIdentifier
fromEntity(EntityInterface $entity)
Creates a ResourceIdentifier object.
static protected string
getDataReferencePropertyName(EntityReferenceItem $item)
Helper method to determine which field item property contains an entity.
static protected ResourceIdentifier
getVirtualOrMissingResourceIdentifier(EntityReferenceItem $item)
Creates a ResourceIdentifier for a NULL or FALSE entity reference item.