symfony.com/doc/current/reference/constraints/Call...use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
class Model
{
/**
* @var string
*/
public $foo;
/**
* @var string
*/
public $bar;
/**
* @Assert\Callback()
*
* @param ExecutionContextInterface $context
* @param $payload
*/
public function validateFooBar(ExecutionContextInterface $context, $payload)
{
$fooViolations = $context->getValidator()->validate($this->foo, new Assert\NotBlank());
$barViolations = $context->getValidator()->validate($this->bar, new Assert\NotBlank());
if ($fooViolations->count() > 0 && $barViolations->count() > 0) {
$context->buildViolation('foo или bar должны быть заполнены')
->addViolation()
;
}
}
}