function ResourceIdentifier::__construct

Same name in other branches
  1. 8.9.x core/modules/jsonapi/src/JsonApiResource/ResourceIdentifier.php \Drupal\jsonapi\JsonApiResource\ResourceIdentifier::__construct()
  2. 10 core/modules/jsonapi/src/JsonApiResource/ResourceIdentifier.php \Drupal\jsonapi\JsonApiResource\ResourceIdentifier::__construct()
  3. 11.x core/modules/jsonapi/src/JsonApiResource/ResourceIdentifier.php \Drupal\jsonapi\JsonApiResource\ResourceIdentifier::__construct()

ResourceIdentifier constructor.

Parameters

\Drupal\jsonapi\ResourceType\ResourceType|string $resource_type: The JSON:API resource type or a JSON:API resource type name.

string $id: The resource ID.

array $meta: Any metadata for the ResourceIdentifier.

File

core/modules/jsonapi/src/JsonApiResource/ResourceIdentifier.php, line 80

Class

ResourceIdentifier
Represents a JSON:API resource identifier object.

Namespace

Drupal\jsonapi\JsonApiResource

Code

public function __construct($resource_type, $id, array $meta = []) {
    assert(is_string($resource_type) || $resource_type instanceof ResourceType);
    assert(!isset($meta[static::ARITY_KEY]) || is_int($meta[static::ARITY_KEY]) && $meta[static::ARITY_KEY] >= 0);
    $this->resourceTypeName = is_string($resource_type) ? $resource_type : $resource_type->getTypeName();
    $this->id = $id;
    $this->meta = $meta;
    if (!is_string($resource_type)) {
        $this->resourceType = $resource_type;
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.