|
@@ -14,6 +14,8 @@ namespace Symfony\Component\Validator\Mapping\Loader;
|
|
|
use Symfony\Component\Validator\Exception\MappingException;
|
|
|
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
|
|
use Doctrine\Common\Annotations\AnnotationReader;
|
|
|
+use Symfony\Component\Validator\Constraints\Validation;
|
|
|
+use Symfony\Component\Validator\Constraint;
|
|
|
|
|
|
class AnnotationLoader implements LoaderInterface
|
|
|
{
|
|
@@ -22,8 +24,8 @@ class AnnotationLoader implements LoaderInterface
|
|
|
public function __construct()
|
|
|
{
|
|
|
$this->reader = new AnnotationReader();
|
|
|
- $this->reader->setDefaultAnnotationNamespace('Symfony\Component\Validator\Constraints\\');
|
|
|
$this->reader->setAutoloadAnnotations(true);
|
|
|
+ $this->reader->setAnnotationNamespaceAlias('Symfony\Component\Validator\Constraints\\', 'validation');
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -31,12 +33,15 @@ class AnnotationLoader implements LoaderInterface
|
|
|
*/
|
|
|
public function loadClassMetadata(ClassMetadata $metadata)
|
|
|
{
|
|
|
- $annotClass = 'Symfony\Component\Validator\Constraints\Validation';
|
|
|
$reflClass = $metadata->getReflectionClass();
|
|
|
$loaded = false;
|
|
|
|
|
|
- if ($annot = $this->reader->getClassAnnotation($reflClass, $annotClass)) {
|
|
|
- foreach ($annot->constraints as $constraint) {
|
|
|
+ foreach ($this->reader->getClassAnnotations($reflClass) as $constraint) {
|
|
|
+ if ($constraint instanceof Validation) {
|
|
|
+ foreach ($constraint->constraints as $constraint) {
|
|
|
+ $metadata->addConstraint($constraint);
|
|
|
+ }
|
|
|
+ } elseif ($constraint instanceof Constraint) {
|
|
|
$metadata->addConstraint($constraint);
|
|
|
}
|
|
|
|
|
@@ -44,8 +49,12 @@ class AnnotationLoader implements LoaderInterface
|
|
|
}
|
|
|
|
|
|
foreach ($reflClass->getProperties() as $property) {
|
|
|
- if ($annot = $this->reader->getPropertyAnnotation($property, $annotClass)) {
|
|
|
- foreach ($annot->constraints as $constraint) {
|
|
|
+ foreach ($this->reader->getPropertyAnnotations($property) as $constraint) {
|
|
|
+ if ($constraint instanceof Validation) {
|
|
|
+ foreach ($constraint->constraints as $constraint) {
|
|
|
+ $metadata->addPropertyConstraint($property->getName(), $constraint);
|
|
|
+ }
|
|
|
+ } elseif ($constraint instanceof Constraint) {
|
|
|
$metadata->addPropertyConstraint($property->getName(), $constraint);
|
|
|
}
|
|
|
|
|
@@ -54,11 +63,15 @@ class AnnotationLoader implements LoaderInterface
|
|
|
}
|
|
|
|
|
|
foreach ($reflClass->getMethods() as $method) {
|
|
|
- if ($annot = $this->reader->getMethodAnnotation($method, $annotClass)) {
|
|
|
- foreach ($annot->constraints as $constraint) {
|
|
|
- // TODO: clean this up
|
|
|
- $name = lcfirst(substr($method->getName(), 0, 3)=='get' ? substr($method->getName(), 3) : substr($method->getName(), 2));
|
|
|
+ foreach ($this->reader->getMethodAnnotations($method) as $constraint) {
|
|
|
+ // TODO: clean this up
|
|
|
+ $name = lcfirst(substr($method->getName(), 0, 3)=='get' ? substr($method->getName(), 3) : substr($method->getName(), 2));
|
|
|
|
|
|
+ if ($constraint instanceof Validation) {
|
|
|
+ foreach ($constraint->constraints as $constraint) {
|
|
|
+ $metadata->addGetterConstraint($name, $constraint);
|
|
|
+ }
|
|
|
+ } elseif ($constraint instanceof Constraint) {
|
|
|
$metadata->addGetterConstraint($name, $constraint);
|
|
|
}
|
|
|
|
|
@@ -68,4 +81,4 @@ class AnnotationLoader implements LoaderInterface
|
|
|
|
|
|
return $loaded;
|
|
|
}
|
|
|
-}
|
|
|
+}
|