ResourceResponseValidator
class ResourceResponseValidator implements EventSubscriberInterface (View source)
| internal | JSON:API maintains no PHP API. The API is the HTTP API. This class may change at any time and could break any dependencies on it. |
Response subscriber that validates a JSON:API response.
This must run after ResourceResponseSubscriber.
Properties
| protected LoggerInterface | $logger | The JSON:API logger channel. |
|
| protected Validator|null | $validator | The schema validator. |
|
| protected ModuleHandlerInterface | $moduleHandler | The module handler. |
|
| protected string | $appRoot | The application's root file path. |
Methods
Constructs a ResourceResponseValidator object.
{@inheritdoc}
Sets the validator service if available.
Validates JSON:API responses.
Wraps validation in an assert to prevent execution in production.
Validates a response against the JSON:API specification.
Validates a string against a JSON Schema. It logs any possible errors.
Details
__construct(LoggerInterface $logger, ModuleHandlerInterface $module_handler, string $app_root)
Constructs a ResourceResponseValidator object.
static
getSubscribedEvents()
{@inheritdoc}
setValidator(Validator $validator = NULL)
Sets the validator service if available.
onResponse(FilterResponseEvent $event)
Validates JSON:API responses.
doValidateResponse(Response $response, Request $request)
Wraps validation in an assert to prevent execution in production.
protected bool
validateResponse(Response $response, Request $request)
Validates a response against the JSON:API specification.
protected bool
validateSchema(object $schema, string $response_data)
Validates a string against a JSON Schema. It logs any possible errors.