Difference between symfony2 callbacks and custom validation restrictions

As far as I understand, callback is a restriction that you can configure and set in any field for any type of check.

A custom validation constraint overrides the base class of constraints (creating any type of validation in any field)

I just donโ€™t know what the difference is, why should I use one and not the other? Are there any differences in performance?

+7
source share
1 answer

I have not studied the form component that should be aware of any performance differences, but also why you should choose one of them:

Callbacks

  • It is intended to customize the entire validation process, and not just to limit it. For example, you can specify where the error should be displayed;
  • The goal is always a class; you cannot use it for a property;
  • You cannot reuse it, it is available only for this class / object.

Validator user restrictions

  • You can use it everywhere (as @MrGlass said, you can even use services as a limitation);
  • It can be used for the target of a class and property;
  • You can only tune when something fails, and not what is done after its failure.
+6
source

All Articles