1.7 KiB
1.7 KiB
src/Constraint
Property constraint
To add a new constraint (let's say represented by foo_contraint) it is expected that:
- The
foo_contraintproperty is registered with the validation schema (property-constraint-schema.v1.json) hereby defines its characteristics (array, boolean, pattern etc.) - A new class is added that implements the
Constraintinterface and interprets thefoo_contraintproperty together with the constraint boundaries - The
foo_contraintproperty and the newly created class are registered with theConstraintRegistry - The newly created
Constraintclass is added to theConstraintFactoryto define the object graph
When adding new constraints, please ensure that:
- Unit tests carefully test the expected behaviour
- The
ConstraintRegistryTestandConstraintFactoryTestare extended
TYPE_DEFERRED
When a constraint is expected to be expensive (in terms of performance, runtime) it should be postponed and be derived from the DeferrableConstraint class to ensure that those checks are run using the DeferredConstraintCheckUpdateJob hereby avoiding unnecessary resource hogging during a page view/GET process.
See also
- How to register a custom constraint