You are here

final class JsonapiResourceClassResolver in JSON:API Resources 8

Injects JSON:API resource dependencies that are internal to this module.

Many of the injected dependencies should not need to be injected by children of this module's resource base classes because they would leak internal implementation details and doing so would impose an unnecessary BC burden on this module.

@internal

Hierarchy

Expanded class hierarchy of JsonapiResourceClassResolver

1 string reference to 'JsonapiResourceClassResolver'
jsonapi_resources.services.yml in ./jsonapi_resources.services.yml
jsonapi_resources.services.yml
1 service uses JsonapiResourceClassResolver
jsonapi_resources.class_resolver in ./jsonapi_resources.services.yml
Drupal\jsonapi_resources\Unstable\DependencyInjection\JsonapiResourceClassResolver

File

src/Unstable/DependencyInjection/JsonapiResourceClassResolver.php, line 21

Namespace

Drupal\jsonapi_resources\Unstable\DependencyInjection
View source
final class JsonapiResourceClassResolver extends ClassResolver {

  /**
   * {@inheritdoc}
   */
  public function getInstanceFromDefinition($definition) {
    $instance = parent::getInstanceFromDefinition($definition);
    if ($instance instanceof ResourceBase) {
      $this
        ->injectResourceDependencies($instance);
    }
    return $instance;
  }

  /**
   * Injects resource dependencies.
   *
   * @param \Drupal\jsonapi_resources\Resource\ResourceBase $resource
   *   The JSON:API resource.
   */
  protected function injectResourceDependencies(ResourceBase $resource) {
    $resource
      ->setResourceTypeRepository($this->container
      ->get('jsonapi.resource_type.repository'));
    $resource
      ->setResourceResponseFactory($this->container
      ->get('jsonapi_resources.resource_response_factory'));
    $resource
      ->setDocumentExtractor($this->container
      ->get('jsonapi_resources.document_extractor'));
    if ($resource instanceof EntityResourceBase) {
      $resource
        ->setEntityTypeManager($this->container
        ->get('entity_type.manager'));
      $resource
        ->setEntityAccessChecker($this->container
        ->get('jsonapi_resources.entity_access_checker'));
    }
    if ($resource instanceof EntityQueryResourceBase) {
      $resource
        ->setCacheabilityCapturingExecutor($this->container
        ->get('jsonapi_resources.entity_query_executor'));
    }
    if ($resource instanceof ResourceObjectToEntityMapperAwareInterface) {
      $resource
        ->setResourceObjectToEntityMapper($this->container
        ->get('jsonapi_resources.resource_object_to_entity_mapper'));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
JsonapiResourceClassResolver::getInstanceFromDefinition public function Returns a class instance with a given class definition. Overrides ClassResolver::getInstanceFromDefinition
JsonapiResourceClassResolver::injectResourceDependencies protected function Injects resource dependencies.