public function MemberMetadata::addConstraint in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony/validator/Mapping/MemberMetadata.php \Symfony\Component\Validator\Mapping\MemberMetadata::addConstraint()
Adds a constraint.
If the constraint {@link Valid} is added, the cascading strategy will be changed to {@link CascadingStrategy::CASCADE}. Depending on the properties $traverse and $deep of that constraint, the traversal strategy will be set to one of the following:
- {@link TraversalStrategy::IMPLICIT} if $traverse is enabled and $deep is enabled
- {@link TraversalStrategy::IMPLICIT} | {@link TraversalStrategy::STOP_RECURSION} if $traverse is enabled, but $deep is disabled
- {@link TraversalStrategy::NONE} if $traverse is disabled
Parameters
Constraint $constraint The constraint to add:
Return value
GenericMetadata This object
Throws
ConstraintDefinitionException When trying to add the {@link Traverse} constraint
Overrides GenericMetadata::addConstraint
File
- vendor/
symfony/ validator/ Mapping/ MemberMetadata.php, line 97
Class
- MemberMetadata
- Stores all metadata needed for validating a class property.
Namespace
Symfony\Component\Validator\MappingCode
public function addConstraint(Constraint $constraint) {
if (!in_array(Constraint::PROPERTY_CONSTRAINT, (array) $constraint
->getTargets())) {
throw new ConstraintDefinitionException(sprintf('The constraint %s cannot be put on properties or getters', get_class($constraint)));
}
parent::addConstraint($constraint);
return $this;
}