function GenericMetadata::addConstraint
Adds a constraint.
If the constraint {@link Valid} is added, the cascading strategy will be changed to {@link CascadingStrategy::CASCADE}. Depending on the $traverse property of that constraint, the traversal strategy will be set to one of the following:
- {@link TraversalStrategy::IMPLICIT} if $traverse is enabled
- {@link TraversalStrategy::NONE} if $traverse is disabled
Return value
$this
Throws
ConstraintDefinitionException When trying to add the {@link Cascade} or {@link Traverse} constraint
6 calls to GenericMetadata::addConstraint()
- ClassMetadata::addConstraint in vendor/
symfony/ validator/ Mapping/ ClassMetadata.php - If the constraint {@link Cascade} is added, the cascading strategy will be changed to {@link CascadingStrategy::CASCADE}.
- ClassMetadata::addConstraint in vendor/
symfony/ validator/ Mapping/ ClassMetadata.php - If the constraint {@link Cascade} is added, the cascading strategy will be changed to {@link CascadingStrategy::CASCADE}.
- GenericMetadata::addConstraints in vendor/
symfony/ validator/ Mapping/ GenericMetadata.php - Adds an list of constraints.
- GenericMetadata::__clone in vendor/
symfony/ validator/ Mapping/ GenericMetadata.php - Clones this object.
- MemberMetadata::addConstraint in vendor/
symfony/ validator/ Mapping/ MemberMetadata.php - Adds a constraint.
2 methods override GenericMetadata::addConstraint()
- ClassMetadata::addConstraint in vendor/
symfony/ validator/ Mapping/ ClassMetadata.php - If the constraint {@link Cascade} is added, the cascading strategy will be changed to {@link CascadingStrategy::CASCADE}.
- MemberMetadata::addConstraint in vendor/
symfony/ validator/ Mapping/ MemberMetadata.php - Adds a constraint.
File
-
vendor/
symfony/ validator/ Mapping/ GenericMetadata.php, line 133
Class
- GenericMetadata
- A generic container of {@link Constraint} objects.
Namespace
Symfony\Component\Validator\MappingCode
public function addConstraint(Constraint $constraint) : static {
if ($constraint instanceof Traverse || $constraint instanceof Cascade) {
throw new ConstraintDefinitionException(\sprintf('The constraint "%s" can only be put on classes. Please use "Symfony\\Component\\Validator\\Constraints\\Valid" instead.', get_debug_type($constraint)));
}
if ($constraint instanceof Valid && null === $constraint->groups) {
$this->cascadingStrategy = CascadingStrategy::CASCADE;
if ($constraint->traverse) {
$this->traversalStrategy = TraversalStrategy::IMPLICIT;
}
else {
$this->traversalStrategy = TraversalStrategy::NONE;
}
return $this;
}
if ($constraint instanceof DisableAutoMapping || $constraint instanceof EnableAutoMapping) {
$this->autoMappingStrategy = $constraint instanceof EnableAutoMapping ? AutoMappingStrategy::ENABLED : AutoMappingStrategy::DISABLED;
// The constraint is not added
return $this;
}
$this->constraints[] = $constraint;
foreach ($constraint->groups as $group) {
$this->constraintsByGroup[$group][] = $constraint;
}
return $this;
}