自定义约束验证器不存在,或者无法自动加载


Custom constraint validator does not exist, or could not be auto-loaded

我试图创建一个自定义约束验证器,但我无法让它工作,这是我的错误:

AnnotationException: [Semantical Error] The annotation  
"@Cmpny'MyBundle'Validator'IsGifImage" in property           
Cmpny'MyBundle'Entity'Post::$src does not exist, or could not be auto-loaded.  

这是我的项目树:

src/Cmpny/MyBundle/Validator/
└── Constraint
    ├── isGifImage.php
    └── isGifImageValidator.php  

isGifImage.php

<?php
namespace Appinest'WhenayBundle'Validator'Constraint;  
use Symfony'Component'Validator'Constraint;
/**  
* @Annotation  
*/  
class IsGifImage extends Constraint¬
{
    public $message = 'This is not a gif image!';
}
?>

isGifImageValidator

  3 namespace Appinest'WhenayBundle'Validator'Constraint;¬
  2 ¬
  1 use Symfony'Component'Validator'Constraint;¬
  0 use Symfony'Component'Validator'ConstraintValidator;¬
  1 ¬
  2 class IsGifImageValidator extends ConstraintValidator¬
  3 {¬
  4     public function isValid($value, Constraint $constraint)¬
  5     {¬
  6         //My function
 22     }¬
    }

然后在实体类中导入:

use Cmpny'WhenayBundle'Validator'Constraint as CmpnyAssert;

然后使用上面我想要验证的断言:

@CmpnyAssert'IsGifImage()

我搜索解决方案,但没有找到任何关于它,任何帮助?:/

只是一个想法:重命名您的php脚本(camel-case)的第一个字母是小写的'is…