class RequestHandler implements ContainerInjectionInterface (View source)

Acts as intermediate request forwarder for resource plugins.

Properties

protected ConfigFactoryInterface $configFactory

The config factory.

protected SerializerInterface|DecoderInterface $serializer

The serializer.

Methods

__construct(ConfigFactoryInterface $config_factory, SerializerInterface $serializer)

Creates a new RequestHandler instance.

static 
create(ContainerInterface $container)

Instantiates a new instance of this class.

handle(RouteMatchInterface $route_match, Request $request, RestResourceConfigInterface $_rest_resource_config)

Handles a REST API request.

handleRaw(RouteMatchInterface $route_match, Request $request, RestResourceConfigInterface $_rest_resource_config)

Handles a REST API request without deserializing the request body.

prepareResponse(ResourceResponseInterface $response, RestResourceConfigInterface $resource_config)

Prepares the REST resource response.

static string
getNormalizedRequestMethod(RouteMatchInterface $route_match)

Gets the normalized HTTP request method of the matched route.

array|null
deserialize(RouteMatchInterface $route_match, Request $request, ResourceInterface $resource)

Deserializes request body, if any.

delegateToRestResourcePlugin(RouteMatchInterface $route_match, Request $request, mixed|null $unserialized, ResourceInterface $resource)

Delegates an incoming request to the appropriate REST resource plugin.

createArgumentResolver(RouteMatchInterface $route_match, mixed $unserialized, Request $request)

Creates an argument resolver, containing all REST parameters.

array
getLegacyParameters(RouteMatchInterface $route_match, mixed $unserialized, Request $request) deprecated

Provides the parameter usable without an argument resolver.

Details

__construct(ConfigFactoryInterface $config_factory, SerializerInterface $serializer)

Creates a new RequestHandler instance.

Parameters

ConfigFactoryInterface $config_factory

The config factory.

SerializerInterface $serializer

The serializer.

static create(ContainerInterface $container)

Instantiates a new instance of this class.

This is a factory method that returns a new instance of this class. The factory should pass any needed dependencies into the constructor of this class, but not the container itself. Every call to this method must return a new instance of this class; that is, it may not implement a singleton.

Parameters

ContainerInterface $container

The service container this instance should use.

ResourceResponseInterface|Response handle(RouteMatchInterface $route_match, Request $request, RestResourceConfigInterface $_rest_resource_config)

Handles a REST API request.

Parameters

RouteMatchInterface $route_match

The route match.

Request $request

The HTTP request object.

RestResourceConfigInterface $_rest_resource_config

The REST resource config entity.

Return Value

ResourceResponseInterface|Response

The REST resource response.

Response|ResourceResponseInterface handleRaw(RouteMatchInterface $route_match, Request $request, RestResourceConfigInterface $_rest_resource_config)

Handles a REST API request without deserializing the request body.

Parameters

RouteMatchInterface $route_match

The route match.

Request $request

The HTTP request object.

RestResourceConfigInterface $_rest_resource_config

The REST resource config entity.

Return Value

Response|ResourceResponseInterface

The REST resource response.

protected ResourceResponseInterface prepareResponse(ResourceResponseInterface $response, RestResourceConfigInterface $resource_config)

Prepares the REST resource response.

Parameters

ResourceResponseInterface $response

The REST resource response.

RestResourceConfigInterface $resource_config

The REST resource config entity.

Return Value

ResourceResponseInterface

The prepared REST resource response.

static protected string getNormalizedRequestMethod(RouteMatchInterface $route_match)

Gets the normalized HTTP request method of the matched route.

Parameters

RouteMatchInterface $route_match

The route match.

Return Value

string

The normalized HTTP request method.

protected array|null deserialize(RouteMatchInterface $route_match, Request $request, ResourceInterface $resource)

Deserializes request body, if any.

Parameters

RouteMatchInterface $route_match

The route match.

Request $request

The HTTP request object.

ResourceInterface $resource

The REST resource plugin.

Return Value

array|null

An object normalization, ikf there is a valid request body. NULL if there is no request body.

Exceptions

BadRequestHttpException
UnprocessableEntityHttpException

protected Response|ResourceResponseInterface delegateToRestResourcePlugin(RouteMatchInterface $route_match, Request $request, mixed|null $unserialized, ResourceInterface $resource)

Delegates an incoming request to the appropriate REST resource plugin.

Parameters

RouteMatchInterface $route_match

The route match.

Request $request

The HTTP request object.

mixed|null $unserialized

The unserialized request body, if any.

ResourceInterface $resource

The REST resource plugin.

Return Value

Response|ResourceResponseInterface

The REST resource response.

protected ArgumentsResolver createArgumentResolver(RouteMatchInterface $route_match, mixed $unserialized, Request $request)

Creates an argument resolver, containing all REST parameters.

Parameters

RouteMatchInterface $route_match

The route match.

mixed $unserialized

The unserialized data.

Request $request

The request.

Return Value

ArgumentsResolver

An instance of the argument resolver containing information like the 'entity' we process and the 'unserialized' content from the request body.

protected array getLegacyParameters(RouteMatchInterface $route_match, mixed $unserialized, Request $request) deprecated

deprecated in drupal:8.4.0 and is removed from drupal:9.0.0. Use the argument resolver method instead, see ::createArgumentResolver().

Provides the parameter usable without an argument resolver.

This creates an list of parameters in a statically defined order.

Parameters

RouteMatchInterface $route_match

The route match

mixed $unserialized

The unserialized data.

Request $request

The request.

Return Value

array

An array of parameters.

See also

https://www.drupal.org/node/2894819