Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Router] Validate Request in Router #48908

Copy link
Copy link
Closed
@y4roc

Description

@y4roc
Issue body actions

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.