Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Allows adding custom constraints via
Background
I ran in to the problem of custom constraints and via pr #143 by @Maks3w (the factory) the possiblity was available to easily accomplish adding custom constraints.. (this is moved from a @Maks3w fork)
Implementation
This allows applying custom constraints, by name, as either a callable/className/instance.
I am not saying this is how it should be --- all input welcome.
i.e. schema
Can be constrained via
$validator->addConstraint('myCustomCheck', $constraint)
Add a callable constraint
ConstraintInterface->check
signaturefunction ($value, $schema = null, $path = null, $i = null)
Add by Constraint class-name
FQCN
must be of typeJsonSchema\Constraints\ConstraintInterface
Add by Constraint instance
MyCustomConstraint
must be of typeJsonSchema\Constraints\ConstraintInterface