You are here

public function ResourceIdentifier::__construct in Drupal 9

Same name and namespace in other branches
  1. 8 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()

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;
  }
}