Recommend this page to a friend! |
Classes of Murat Cileli | Papernic | vendor/symfony/symfony/src/Symfony/Component/Validator/README.md | Download |
|
DownloadValidator ComponentThis component is based on the JSR-303 Bean Validation specification and enables specifying validation rules for classes using XML, YAML, PHP or annotations, which can then be checked against instances of these classes. UsageThe component provides "validation constraints", which are simple objects containing the rules for the validation. Let's validate a simple string as an example:
This validation will fail because the given string is shorter than ten characters. The precise errors, here called "constraint violations", are returned by the validator. You can analyze these or return them to the user. If the violation list is empty, validation succeeded. Validation of arrays is possible using the
Again, the validator returns the list of violations. Validation of objects is possible using "constraint mapping". With such a mapping you can put constraints onto properties and objects of classes. Whenever an object of this class is validated, its properties and method results are matched against the constraints.
This example uses the annotation support of Doctrine Common to map constraints to properties and methods. You can also map constraints using XML, YAML or plain PHP, if you dislike annotations or don't want to include Doctrine. Check the documentation for more information about these drivers. ResourcesSilex integration: https://github.com/silexphp/Silex/blob/master/src/Silex/Provider/ValidatorServiceProvider.php Documentation: https://symfony.com/doc/2.8/book/validation.html JSR-303 Specification: http://jcp.org/en/jsr/detail?id=303 You can run the unit tests with the following command:
|