Closed
Description
Q | A |
---|---|
Bug report? | yes |
Feature request? | no |
BC Break report? | no |
RFC? | no |
Symfony version | 2.8.14 |
If I try to use the Assert\Choice
inside the Assert\All
, like following I receive a The choice constraint expects a valid callback
error message.
// src/AppBundle/Entity/User.php
namespace AppBundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class User
{
/**
* @Assert\Count(min="1")
* @Assert\All({
* @Assert\Choice(callback={"getValidColors"})
* })
*/
protected $favoriteColors = array();
public static function getValidColors()
{
return array('red', 'green', 'blue');
}
}
To walkaround this problem, I've added the full-qualified-class-name to the first paramater of the callback option of the Assert\Choice
, as follow:
// src/AppBundle/Entity/User.php
namespace AppBundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class User
{
/**
* @Assert\Count(min="1")
* @Assert\All({
* @Assert\Choice(callback={"AppBundle\Entity\User", "getValidColors"})
* })
*/
protected $favoriteColors = array();
public static function getValidColors()
{
return array('red', 'green', 'blue');
}
}
And this way it has worked, but this method is not covered at any documentation. I'm willing to help if I know what needs to be done.