final class ResourceEnhancer in JSON:API Resources 8
Route enhancer for JSON:API Resource routes.
Hierarchy
- class \Drupal\jsonapi_resources\Unstable\Routing\Enhancer\ResourceEnhancer implements EnhancerInterface
Expanded class hierarchy of ResourceEnhancer
1 file declares its use of ResourceEnhancer
- ResourceEnhancerTest.php in tests/
src/ Kernel/ Routing/ ResourceEnhancerTest.php
1 string reference to 'ResourceEnhancer'
1 service uses ResourceEnhancer
File
- src/
Unstable/ Routing/ Enhancer/ ResourceEnhancer.php, line 14
Namespace
Drupal\jsonapi_resources\Unstable\Routing\EnhancerView source
final class ResourceEnhancer implements EnhancerInterface {
/**
* A class resolver.
*
* @var \Drupal\Core\DependencyInjection\ClassResolverInterface
*/
protected $classResolver;
/**
* The current route match.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;
/**
* ResourceEnhancer constructor.
*
* @param \Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver
* A class resolver to load the appropriate JSON:API resource for the
* matched route.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route matched by the request.
*/
public function __construct(ClassResolverInterface $class_resolver, RouteMatchInterface $route_match) {
$this->classResolver = $class_resolver;
$this->routeMatch = $route_match;
}
/**
* {@inheritdoc}
*/
public function enhance(array $defaults, Request $request) {
if (!isset($defaults['_jsonapi_resource'])) {
return $defaults;
}
$defaults['_controller'] = 'controller.jsonapi_resource:processRequest';
if (!isset($defaults['resource_types'])) {
$resource = $this->classResolver
->getInstanceFromDefinition($defaults['_jsonapi_resource']);
assert($resource instanceof ResourceBase);
$defaults['resource_types'] = $resource
->getRouteResourceTypes($defaults['_route_object'], $defaults['_route']);
}
return $defaults;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ResourceEnhancer:: |
protected | property | A class resolver. | |
ResourceEnhancer:: |
protected | property | The current route match. | |
ResourceEnhancer:: |
public | function | Update the defaults based on its own data and the request. | |
ResourceEnhancer:: |
public | function | ResourceEnhancer constructor. |