You are here

public function ClassMetadata::mergeConstraints in Plug 7

Merges the constraints of the given metadata into this object.

Parameters

ClassMetadata $source The source metadata:

File

lib/Symfony/validator/Symfony/Component/Validator/Mapping/ClassMetadata.php, line 340

Class

ClassMetadata
Default implementation of {@link ClassMetadataInterface}.

Namespace

Symfony\Component\Validator\Mapping

Code

public function mergeConstraints(ClassMetadata $source) {
  foreach ($source
    ->getConstraints() as $constraint) {
    $this
      ->addConstraint(clone $constraint);
  }
  foreach ($source
    ->getConstrainedProperties() as $property) {
    foreach ($source
      ->getPropertyMetadata($property) as $member) {
      $member = clone $member;
      foreach ($member
        ->getConstraints() as $constraint) {
        $constraint
          ->addImplicitGroupName($this
          ->getDefaultGroup());
      }
      $this
        ->addPropertyMetadata($member);
      if ($member instanceof MemberMetadata && !$member
        ->isPrivate($this->name)) {
        $property = $member
          ->getPropertyName();
        if ($member instanceof PropertyMetadata && !isset($this->properties[$property])) {
          $this->properties[$property] = $member;
        }
        elseif ($member instanceof GetterMetadata && !isset($this->getters[$property])) {
          $this->getters[$property] = $member;
        }
      }
    }
  }
}