瀏覽代碼

Changed recognition of constraints in annoations

Sebastian Hörl 14 年之前
父節點
當前提交
2f78a44175
共有 1 個文件被更改,包括 5 次插入4 次删除
  1. 5 4
      src/Symfony/Component/Validator/Mapping/Loader/AnnotationLoader.php

+ 5 - 4
src/Symfony/Component/Validator/Mapping/Loader/AnnotationLoader.php

@@ -60,11 +60,12 @@ class AnnotationLoader implements LoaderInterface
         foreach ($reflClass->getMethods() as $method) {
             if ($method->getDeclaringClass()->getName() ==  $className) {
                 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 Constraint) {
-                        $metadata->addGetterConstraint($name, $constraint);
+                        if (preg_match( '/^(get|is)(.+)$/', $method->getName(), $matches)) {
+                            $metadata->addGetterConstraint(lcfirst($matches[2]), $constraint);
+                        } else {
+                            throw new MappingException( sprintf( 'Cannot add constraint to %s::%s', $className, $method->getName() ) );
+                        }
                     }
 
                     $loaded = true;