· 7 years ago · Feb 12, 2019, 10:24 AM
1Message: "[Semantical Error] The annotation "@SymfonyComponentValidatorConstraintsLength" in property
2
3use SymfonyComponentValidatorValidation;
4use SymfonyComponentValidatorConstraints as Assert;
5
6class User {
7 /**
8 * @AssertLength(min = 3)
9 * @AssertNotBlank
10 */
11 private $name;
12
13 /**
14 * @AssertEmail
15 * @AssertNotBlank
16 */
17 private $email;
18
19 public function __construct($name, $email)
20 {
21 $this->name = $name;
22 $this->email = $email;
23 }
24
25 /**
26 * @AssertTrue(message = "The user should have a Google Mail account")
27 */
28 public function isGmailUser()
29 {
30 return false !== strpos($this->email, '@gmail.com');
31 }
32}
33
34$validator = Validation::createValidatorBuilder()
35 ->enableAnnotationMapping()
36 ->getValidator();
37
38$user = new User('John Doe', 'john@example.com');
39
40$violations = $validator->validate($user);
41
42AnnotationRegistry::registerAutoloadNamespace("SymfonyComponentValidatorConstraint", "path/to/symfony/library/validator");