class InputValidation implements MiddlewareInterface

Input validation middleware.

Traits

Basic content negotiation.

Properties

protected int $httpStatusCode Default HTTP status code for invalid requests.
protected string $errorsFlashKey Session flash key for errors.
protected string $oldInputFlashKey Session flash key for old input.
protected string $errorsVariableName Errors view variable name.
protected string $oldInputVariableName Old input view variable name.
protected string $defaultMessage Default error message.
protected Request $request Request.
protected Response $response Response.
protected URLBuilder $urlBuilder URL builder.
protected Session|null $session Session.
protected ViewFactory|null $viewFactory View factory.

Methods

bool
expectsType(array $mimeTypes, string|null $suffix = null)

Does the client expect the provided mime type?

bool
expectsJson()

Does the client expect JSON?

bool
expectsXml()

Does the client expect XML?

bool
respondWithType(array $mimeTypes, string|null $suffix = null)

Should we respond with the provided mime type?

bool
respondWithJson()

Should we respond with JSON?

bool
respondWithXml()

Should we respond with XML?

__construct(Request $request, Response $response, URLBuilder $urlBuilder, Session|null $session = null, ViewFactory|null $viewFactory = null)

Constructor.

bool
shouldRedirect(Request $request, ValidationException $exception)

Should we redirect the client?

string
getRedirectUrl(ValidationException $exception)

Get the redirect URL.

handleRedirect(Response $response, ValidationException $exception)

Add errors to flash data and redirect.

string
buildXmlFromException(ValidationException $exception, string $charset)

Builds XML based on the exception.

handleOutput(Response $response, ValidationException $exception)

Output errors.

execute(Request $request, Response $response, Closure $next)

Executes the middleware.

Details

protected bool expectsType(array $mimeTypes, string|null $suffix = null)

Does the client expect the provided mime type?

Parameters

array $mimeTypes Mime types
string|null $suffix Mime type suffix

Return Value

bool

protected bool expectsJson()

Does the client expect JSON?

Return Value

bool

protected bool expectsXml()

Does the client expect XML?

Return Value

bool

protected bool respondWithType(array $mimeTypes, string|null $suffix = null)

Should we respond with the provided mime type?

Parameters

array $mimeTypes Mime types
string|null $suffix Mime type suffix

Return Value

bool

protected bool respondWithJson()

Should we respond with JSON?

Return Value

bool

protected bool respondWithXml()

Should we respond with XML?

Return Value

bool

at line 122
__construct(Request $request, Response $response, URLBuilder $urlBuilder, Session|null $session = null, ViewFactory|null $viewFactory = null)

Constructor.

Parameters

Request $request Request
Response $response Response
URLBuilder $urlBuilder URL builder
Session|null $session Session
ViewFactory|null $viewFactory View factory

at line 142
protected bool shouldRedirect(Request $request, ValidationException $exception)

Should we redirect the client?

Parameters

Request $request Request
ValidationException $exception Validation exception

Return Value

bool

at line 158
protected string getRedirectUrl(ValidationException $exception)

Get the redirect URL.

Parameters

ValidationException $exception Validation exception

Return Value

string

at line 170
protected Response handleRedirect(Response $response, ValidationException $exception)

Add errors to flash data and redirect.

Parameters

Response $response Response
ValidationException $exception Validation exception

Return Value

Response

at line 188
protected string buildXmlFromException(ValidationException $exception, string $charset)

Builds XML based on the exception.

Parameters

ValidationException $exception Validation exception
string $charset Character set

Return Value

string

at line 211
protected Response handleOutput(Response $response, ValidationException $exception)

Output errors.

Parameters

Response $response Response
ValidationException $exception Validation exception

Return Value

Response

at line 241
Response execute(Request $request, Response $response, Closure $next)

Executes the middleware.

Parameters

Request $request Request
Response $response Response
Closure $next Next layer

Return Value

Response