I have two entities in my system: Person
and Phone
as the following code.
class Person
{
/**
* @ORM\\Id
* @ORM\\Colum
frankie567's answer was useful to me. For symfony >= 3.0:
/**
*
* @Assert\Callback()
*/
public function validatePhone(ExecutionContextInterface $context)
{
if (/* Fields are not empty */)
{
$validator = $context->getValidator();
$validator->inContext($context)
->atPath('phone')
// you can pass custom validation instead of null, like new Assert\Valid()
->validate($this->getPhone(), null, array('phone_validation'));
}
}