Closed
Description
In the controller I use an attribute to which I pass as parameter the class of the RequestClass. A subscriber then loads the post content and validates it using the RequestClass. Subsequently, an instance of the RequestClass, with the values of the request, is passed as an argument to the controller method.
If the validation fails, the call throws a bad request exception.
Example:
class IndexAction {
#[RequestValidator(class: IndexRequest::class)]
public function __invoke(IndexRequest $request) {
...
}
}
class IndexRequest {
#[Assert\NotNull]
#[Assert\Type(type: 'string')]
public $username
public function getUsername(): string {
return $this->string;
}
}
Originally posted by @y4roc in #46991 (comment)