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

__construct(LoggerInterface $logger, ModuleHandlerInterface $module_handler, string $app_root)

Constructs a ResourceResponseValidator object.

static array
getSubscribedEvents()

{@inheritdoc}

setValidator(Validator $validator = NULL)

Sets the validator service if available.

onResponse(ResponseEvent $event)

Validates JSON:API responses.

doValidateResponse(Response $response, Request $request)

Wraps validation in an assert to prevent execution in production.

bool
validateResponse(Response $response, Request $request)

Validates a response against the JSON:API specification.

bool
validateSchema(object $schema, string $response_data)

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.

Parameters

LoggerInterface $logger

The JSON:API logger channel.

ModuleHandlerInterface $module_handler

The module handler.

string $app_root

The application's root file path.

static array getSubscribedEvents()

{@inheritdoc}

Return Value

array

setValidator(Validator $validator = NULL)

Sets the validator service if available.

Parameters

Validator $validator

onResponse(ResponseEvent $event)

Validates JSON:API responses.

Parameters

ResponseEvent $event

The event to process.

doValidateResponse(Response $response, Request $request)

Wraps validation in an assert to prevent execution in production.

Parameters

Response $response
Request $request

See also

self::validateResponse

protected bool validateResponse(Response $response, Request $request)

Validates a response against the JSON:API specification.

Parameters

Response $response

The response to validate.

Request $request

The request containing info about what to validate.

Return Value

bool

FALSE if the response failed validation, otherwise TRUE.

protected bool validateSchema(object $schema, string $response_data)

Validates a string against a JSON Schema. It logs any possible errors.

Parameters

object $schema

The JSON Schema object.

string $response_data

The JSON string to validate.

Return Value

bool

TRUE if the string is a valid instance of the schema. FALSE otherwise.