You are here

public function DocumentResolver::supports in JSON:API Resources 8

File

src/Unstable/Controller/ArgumentResolver/DocumentResolver.php, line 38

Class

DocumentResolver
Deserializes POST, PATCH and DELETE request documents.

Namespace

Drupal\jsonapi_resources\Unstable\Controller\ArgumentResolver

Code

public function supports(Request $request, ArgumentMetadata $argument) {
  $supported_method = in_array($request
    ->getMethod(), [
    'POST',
    'PATCH',
  ]);
  $is_delete = $request
    ->isMethod('DELETE');
  $is_relationship = $request->attributes
    ->has('_jsonapi_relationship_field_name');
  $supported_method = $supported_method || $is_delete && $is_relationship;
  $supported_format = $request
    ->getRequestFormat() === 'api_json';
  $correct_type = $argument
    ->getType() === JsonApiDocumentTopLevel::class;
  return $supported_method && $supported_format && $correct_type;
}