class InputValidation implements MiddlewareInterface

Input validation middleware.

Traits

Basic content negotiation.

Properties

protected Request $request Request.
protected Response $response Response.
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 $defaultErrorMessage Default error message.
protected array $dontInclude Keys that will be removed from the old input.
protected URLBuilder $urlBuilder URL builder.
protected Session|null $session Session.
protected ViewFactory|null $viewFactory View factory.
protected HttpInputInterface|null $input Input.

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(URLBuilder $urlBuilder, Session|null $session = null, ViewFactory|null $viewFactory = null)

Constructor.

setInput(HttpInputInterface|null $input)

Set the input.

bool
shouldRedirect()

Should we redirect the client if possible?

bool
shouldIncludeOldInput()

Should the old input be included?

array
getOldInput()

Returns the old input.

string
getRedirectUrl()

Returns the redirect URL.

handleRedirect(ValidationException $exception)

Add errors to flash data and redirect.

string
getErrorMessage()

Returns the error message.

string
buildXmlFromException(ValidationException $exception, string $charset)

Builds XML based on the exception.

handleOutput(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 135
__construct(URLBuilder $urlBuilder, Session|null $session = null, ViewFactory|null $viewFactory = null)

Constructor.

Parameters

URLBuilder $urlBuilder URL builder
Session|null $session Session
ViewFactory|null $viewFactory View factory

at line 149
protected setInput(HttpInputInterface|null $input)

Set the input.

Parameters

HttpInputInterface|null $input Input

at line 159
protected bool shouldRedirect()

Should we redirect the client if possible?

Return Value

bool

at line 174
protected bool shouldIncludeOldInput()

Should the old input be included?

Return Value

bool

at line 189
protected array getOldInput()

Returns the old input.

Return Value

array

at line 208
protected string getRedirectUrl()

Returns the redirect URL.

Return Value

string

at line 224
protected Response handleRedirect(ValidationException $exception)

Add errors to flash data and redirect.

Parameters

ValidationException $exception Validation exception

Return Value

Response

at line 243
protected string getErrorMessage()

Returns the error message.

Return Value

string

at line 260
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 282
protected Response handleOutput(ValidationException $exception)

Output errors.

Parameters

ValidationException $exception Validation exception

Return Value

Response

at line 312
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