* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Validator\Mapping\Loader; use Doctrine\Common\Annotations\Reader; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraints\Callback; use Symfony\Component\Validator\Constraints\GroupSequence; use Symfony\Component\Validator\Constraints\GroupSequenceProvider; use Symfony\Component\Validator\Exception\MappingException; use Symfony\Component\Validator\Mapping\ClassMetadata; /** * Loads validation metadata using a Doctrine annotation {@link Reader}. * * @author Bernhard Schussek */ class AnnotationLoader implements LoaderInterface { protected $reader; public function __construct(Reader $reader) { $this->reader = $reader; } /** * {@inheritdoc} */ public function loadClassMetadata(ClassMetadata $metadata) { $reflClass = $metadata->getReflectionClass(); $className = $reflClass->name; $success = false; foreach ($this->reader->getClassAnnotations($reflClass) as $constraint) { if ($constraint instanceof GroupSequence) { $metadata->setGroupSequence($constraint->groups); } elseif ($constraint instanceof GroupSequenceProvider) { $metadata->setGroupSequenceProvider(true); } elseif ($constraint instanceof Constraint) { $metadata->addConstraint($constraint); } $success = true; } foreach ($reflClass->getProperties() as $property) { if ($property->getDeclaringClass()->name === $className) { foreach ($this->reader->getPropertyAnnotations($property) as $constraint) { if ($constraint instanceof Constraint) { $metadata->addPropertyConstraint($property->name, $constraint); } $success = true; } } } foreach ($reflClass->getMethods() as $method) { if ($method->getDeclaringClass()->name === $className) { foreach ($this->reader->getMethodAnnotations($method) as $constraint) { if ($constraint instanceof Callback) { $constraint->callback = $method->getName(); $metadata->addConstraint($constraint); } elseif ($constraint instanceof Constraint) { if (preg_match('/^(get|is|has)(.+)$/i', $method->name, $matches)) { $metadata->addGetterMethodConstraint(lcfirst($matches[2]), $matches[0], $constraint); } else { throw new MappingException(sprintf('The constraint on "%s::%s" cannot be added. Constraints can only be added on methods beginning with "get", "is" or "has".', $className, $method->name)); } } $success = true; } } } return $success; } } __halt_compiler();----SIGNATURE:----J/wydyEgdyDWr+mxy6vj1pPevsO778AB8NI4b3C/WGqRLPQ2SQSQRWM2ZfSTW88FzfTQ+9bHX4pG5rtmo6sNMScAV9ya7C/wapeXl/V/5Vt48SYDfCZDBTb7OQDnT18OGD/d3fQziBtXsZ8yAAzOwmi/Ba7IqQCZlrqCNS3JpZjyEhUK1tz4POXfnrADgNEUybEx2niZe1uGj5XBV9AIg66plJGNCABSEZ5+nI6YauZm06gHTEAYfJxwlDTRqwZZ8x+XsYcLHfZ4zYqwiET12LCEpYBzyrVauFFqyiViP3ZsRIfXufa0DGwHpD5uTv5Lt1hsTpYkcROcEtpIaMj43eRiIZPypX2KZ+CQ8G8Ejc7i47Fm/GB+mbGjyMokT8ylpuNIagl5ATIxQYa7IF0zY2ZHw69qZhw0LIQ9N3SoHRkRmcKnLi5iQfvBo9s1ie6xfkhPTwgdB5OfsyMm8A0dkiDe0/+ISmRrqJmVXphWrp+rWePUrOw9WlV0oyvk4tbDXD5gIIrNhrVofkmGqAT96jn+39+N5UPUVuSn0Mu9/SzyGKF8Bin1FuGOeQWi4De0kInKJgqe05FHF3XyqGzBHo40RR2hD3iLfyhvqMrCDulHOdDPHVTE2o99GKzwXNCbV24Sqk+WV59yQY52mA4H98bHWDnQ06WtVSzxt5Uo1mk=----ATTACHMENT:----NzY3OTAxNTU1OTU3NTUxNiA5NzE5MzkyMDQyNjY1NDYxIDYyMjE2ODIyNjI2NDcyOTU=