You are here

public function JsonapiResourceController::processRequest in JSON:API Resources 8

Processes a request and returns a JSON:API ResourceResponse.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request object.

\Drupal\Core\Routing\RouteMatchInterface $current_route: The route matched by the request.

Return value

\Drupal\jsonapi\ResourceResponse A process JSON:API ResourceResponse.

File

src/Unstable/Controller/JsonapiResourceController.php, line 62

Class

JsonapiResourceController
An interstitial controller between raw requests & JSON:API resource objects.

Namespace

Drupal\jsonapi_resources\Unstable\Controller

Code

public function processRequest(Request $request, RouteMatchInterface $current_route) : ResourceResponse {
  $resource = $this
    ->getJsonapiResource($current_route);
  $args = $this->argumentResolver
    ->getArguments($request, [
    $resource,
    'process',
  ]);

  // The process() method is guaranteed to exist because
  // \Drupal\jsonapi_resources\Unstable\Routing\ResourceRoutes::ensureResourceImplementationValid()
  // uses reflection to ensure that it does.
  $response = $resource
    ->process(...$args);
  assert($response instanceof ResourceResponse, 'JSON:API resource request processors must return a Drupal\\jsonapi\\ResourceResponse object.');
  $this
    ->ensureValidResponseDataResourceTypes($response, $request);
  return $response;
}