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
- class \Drupal\Core\DependencyInjection\ClassResolver implements \Symfony\Component\DependencyInjection\ContainerAwareInterface, ClassResolverInterface uses \Symfony\Component\DependencyInjection\ContainerAwareTrait, DependencySerializationTrait
- class \Drupal\jsonapi_resources\Unstable\DependencyInjection\JsonapiResourceClassResolver
Expanded class hierarchy of JsonapiResourceClassResolver
1 string reference to 'JsonapiResourceClassResolver'
1 service uses JsonapiResourceClassResolver
File
- src/
Unstable/ DependencyInjection/ JsonapiResourceClassResolver.php, line 21
Namespace
Drupal\jsonapi_resources\Unstable\DependencyInjectionView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
JsonapiResourceClassResolver:: |
public | function |
Returns a class instance with a given class definition. Overrides ClassResolver:: |
|
JsonapiResourceClassResolver:: |
protected | function | Injects resource dependencies. |