カスタム制約バリデーターを作成しようとしていますが、機能させることができません。次のエラーが発生しています。
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()
解決策を検索しましたが、何も見つかりませんでした。:/