- Add MezzioRequestValidation\Middleware\RequestValidatorMiddleware to your pipeline.
- Define an implementation of MezzioRequestValidation\ErrorHandler\ValidationErrorHandler in your container configuration. JsonValidationErrorHandler is provided as a simple option.
- implement the ParameterRuleSet interface on a request handler using the options from https://github.com/rakit/validation
<?php
...
class IndexRequestHandler implements RequestHandlerInterface, ParameterRuleSet
{
public function getParameterRules(): array {
return [
'email' => 'required|email',
'age' => 'numeric'
];
}
public function handle(ServerRequestInterface $request): ResponseInterface
{
...
}
}