myschoolmanagement/assert-constraint

Symfony validator constraints using beberlei/assert

2.02 2022-12-01 14:12 UTC

This package is auto-updated.

Last update: 2024-03-29 03:03:47 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

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.