I get this error:
Message: "[Semantical Error] The annotation "@Symfony\Component\Validator\Constraints\Length" in property User::$name does not exist, or could not be auto-loaded."
This is the code on Github https://github.com/symfony/Validator
use Symfony\Component\Validator\Validation;
use Symfony\Component\Validator\Constraints as Assert;
class User {
/**
* @Assert\Length(min = 3)
* @Assert\NotBlank
*/
private $name;
/**
* @Assert\Email
* @Assert\NotBlank
*/
private $email;
public function __construct($name, $email)
{
$this->name = $name;
$this->email = $email;
}
/**
* @Assert\True(message = "The user should have a Google Mail account")
*/
public function isGmailUser()
{
return false !== strpos($this->email, '@gmail.com');
}
}
$validator = Validation::createValidatorBuilder()
->enableAnnotationMapping()
->getValidator();
$user = new User('John Doe', '[email protected]');
$violations = $validator->validate($user);
How can I fix this problem ?