myschoolmanagement / assert-constraint
Symfony validator constraints using beberlei/assert
Requires
- php: >=7.2
- beberlei/assert: ^v3.2
- symfony/validator: ^v4.2|^v5.0
README
This is a simple bridge for using beberlei/assert assertions as constraints for the Symfony Validator component.
Installation
Using Composer:
composer require myschoolmanagement/assert-constraint
Configuration
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.
Generating new constraints
There is a helper for generating the constraint classes in bin
. This is also copied to vendor/bin
.
Prototype
Usage: generate-constraints.php <path-to-class-file> <fqdn class> <output-namespace> <directory-to-output-classes>
Example Usage:
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.