final class DocumentResolver in JSON:API Resources 8
Deserializes POST, PATCH and DELETE request documents.
@internal
Hierarchy
- class \Drupal\jsonapi_resources\Unstable\Controller\ArgumentResolver\DocumentResolver implements \Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface
Expanded class hierarchy of DocumentResolver
1 string reference to 'DocumentResolver'
1 service uses DocumentResolver
File
- src/
Unstable/ Controller/ ArgumentResolver/ DocumentResolver.php, line 16
Namespace
Drupal\jsonapi_resources\Unstable\Controller\ArgumentResolverView source
final class DocumentResolver implements ArgumentValueResolverInterface {
/**
* The document extractor.
*
* @var \Drupal\jsonapi_resources\Unstable\DocumentExtractor
*/
protected $documentExtractor;
/**
* Constructs a JSON:API document argument resolver.
*
* @param \Drupal\jsonapi_resources\Unstable\DocumentExtractor $document_extractor
* The document extractor.
*/
public function __construct(DocumentExtractor $document_extractor) {
$this->documentExtractor = $document_extractor;
}
/**
* {@inheritdoc}
*/
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;
}
/**
* {@inheritdoc}
*/
public function resolve(Request $request, ArgumentMetadata $argument) {
(yield $this->documentExtractor
->getDocument($request));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DocumentResolver:: |
protected | property | The document extractor. | |
DocumentResolver:: |
public | function | ||
DocumentResolver:: |
public | function | ||
DocumentResolver:: |
public | function | Constructs a JSON:API document argument resolver. |