Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
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()
;
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question