public function ClassMetadata::addConstraint

Adds a constraint to this element.

Parameters

Constraint $constraint:

Return value

ElementMetadata

Overrides ElementMetadata::addConstraint

1 call to ClassMetadata::addConstraint()
ClassMetadata::mergeConstraints in drupal/core/vendor/symfony/validator/Symfony/Component/Validator/Mapping/ClassMetadata.php
Merges the constraints of the given metadata into this object.

File

drupal/core/vendor/symfony/validator/Symfony/Component/Validator/Mapping/ClassMetadata.php, line 171

Class

ClassMetadata
Represents all the configured constraints on a given class.

Namespace

Symfony\Component\Validator\Mapping

Code

public function addConstraint(Constraint $constraint) {
  if (!in_array(Constraint::CLASS_CONSTRAINT, (array) $constraint
    ->getTargets())) {
    throw new ConstraintDefinitionException(sprintf('The constraint %s cannot be put on classes', get_class($constraint)));
  }
  $constraint
    ->addImplicitGroupName($this
    ->getDefaultGroup());
  parent::addConstraint($constraint);
}