Assert bridge for Symfony
This is a simple bridge for using beberlei/assert assertions as constraints for the Symfony Validator component.
Using Composer:
composer require myschoolmanagement/assert-constraint
If you are using your own Assertion
class or your own Exception
class then you must configure these by setting AssertionConstraint\AssertionValidator::$assertClass
and AssertionConstraint\AssertionValidator::$assertExceptionClass
. These are both static properties.
There is a helper for generating the constraint classes in bin
. This is also copied to vendor/bin
.
Usage: generate-constraints.php <path-to-class-file> <fqdn class> <output-namespace> <directory-to-output-classes>
php vendor/bin/generate-constraints.php vendor/beberlei/assert/lib/Assert/Assertion.php Assert\\Assertion MyBundle\\Constraint src/MyBundle/Constraint
This will detect all the assertions on the Assert\Assertion
class and output constraint files in src/MyBundle/Constraint
in the MyBundle\Constraint
namespace.
The generator will give best effort to detect the assertion parameters and add those to the constraint class so they can be configured through the annotation.