我想对特征使用回调验证。例如:
<?php
namespace Vendor\Bundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\ExecutionContext;
/**
* @Assert\Callback(methods={"validateReview"}, groups={"review"})
*/
trait ReviewableEntity
{
//...
/**
* @param ExecutionContext $context
*/
public function validateReview(ExecutionContext $context)
{
//...
$context->addViolationAt('review', 'Review must be valid', [], null);
//...
}
//...
}
但这似乎不起作用。任何人都知道这是否可能?