Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Messenger] Document the validation middleware #10474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ogizanagi opened this issue Oct 11, 2018 · 4 comments · Fixed by #16337
Closed

[Messenger] Document the validation middleware #10474

ogizanagi opened this issue Oct 11, 2018 · 4 comments · Fixed by #16337
Labels
hasPR A Pull Request has already been submitted for this issue. Keep open Messenger

Comments

@ogizanagi
Copy link
Contributor

Original PR: symfony/symfony#26648

An issue was already opened some times ago: #9641
and closed by 2099d48 but there is actually no mention to the ValidationMiddleware and how to use it (ValidationFailedException should also be explained, as it allows getting the violations).

Only the ValidationConfiguration is mentioned in https://symfony.com/doc/current/components/messenger.html#adding-metadata-to-messages-envelopes but I think this middleware deserves its own section/guide.

@Nek-
Copy link
Contributor

Nek- commented Jun 7, 2020

This one looks critical to me. Can any maintainer say what kind of documentation you want?

Possibilities I see are:

  • a new dedicated page
  • a new section inside the middleware

For the record adding it to the middleware list is to do like this:

framework:
    messenger:
        buses:
            command_bus:
                middleware:
                    - messenger.middleware.validation
class CreateUser
{
    /**
     * @Assert\Uuid()
     * @Assert\NotBlank()
     */
    private $uuid;

    /**
     * @Assert\Lenght(min=3)
     * @Assert\NotBlank()
     */
    private $username;

    public function __construct(string $uuid, string $username)
    {
        $this->uuid = $uuid;
        $this->username = $username;
    }

    public function getUuid(): string
    {
        return $this->uuid;
    }

    public function getUsername(): string
    {
         return $this->username;
    }
}

The middleware will throw a ValidationFailedException that you may handle onKernelException and return formatted errors (in the case of an API for instance).

@carsonbot
Copy link
Collaborator

Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?

@Nek-
Copy link
Contributor

Nek- commented Jun 8, 2021

no

@94noni
Copy link
Contributor

94noni commented Dec 31, 2021

@Nek- @ogizanagi I’ve opened a related PR
Feel free to discuss it :)

@xabbuh xabbuh added the hasPR A Pull Request has already been submitted for this issue. label Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hasPR A Pull Request has already been submitted for this issue. Keep open Messenger
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants