0

I'm trying to understand what Symfony ValidationMiddleware do when it is enabled. Validate what and how and when? I didn't see any difference in my app when it's enabled or disabled. Except performance. Validating messages takes a really long time. I'm not sure that disabling it without good knowledge of what it do is a good thing but I can't find any detailed information what it do.

So, question is what ValidationMiddleware in Symfony do? How it do it? When it validate commands? And should I do someting special if I want to disable it.

I've tried to find some more information in the internet, in Symfony docs, on Symfonycasts and generally google for answer but maybe I am dumb because I still not sure that I understand what it do.

deoomen
  • 153
  • 11

1 Answers1

1

As you can read in the official documentation:

Add the validation middleware if you need to validate the message object using the Validator component before handling it. If validation fails, a ValidationFailedException will be thrown. The ValidationStamp can be used to configure the validation groups.

Nico Haase
  • 11,420
  • 35
  • 43
  • 69
  • Ok. I understand that it validates message object. But what validates and how? Checks that string property is string? This will also cause native PHP error without validator. Checks that object is handled by right handler? That will also cause native PHP error when using types in method definitions. – deoomen Apr 20 '23 at 05:50
  • Ok. I done some more tests and now I understand it. When add some `Symfony\Component\Validator\Constraints` asserts to props in command object it will be checked before handling command. Now all is clear for me. I never use asserts in command objects so far. Should be more example somewhere... – deoomen Apr 20 '23 at 06:07