@@ -36,7 +36,7 @@ your application::
3636
3737 class Author
3838 {
39- public $name;
39+ private $name;
4040 }
4141
4242So far, this is just an ordinary class that serves some purpose inside your
@@ -55,6 +55,7 @@ following:
5555 .. code-block :: php-annotations
5656
5757 // src/Entity/Author.php
58+ namespace App\Entity;
5859
5960 // ...
6061 use Symfony\Component\Validator\Constraints as Assert;
@@ -64,7 +65,7 @@ following:
6465 /**
6566 * @Assert\NotBlank
6667 */
67- public $name;
68+ private $name;
6869 }
6970
7071 .. code-block :: yaml
@@ -94,14 +95,14 @@ following:
9495 .. code-block :: php
9596
9697 // src/Entity/Author.php
97-
98+ namespace App\Entity;
9899 // ...
99100 use Symfony\Component\Validator\Constraints\NotBlank;
100101 use Symfony\Component\Validator\Mapping\ClassMetadata;
101102
102103 class Author
103104 {
104- public $name;
105+ private $name;
105106
106107 public static function loadValidatorMetadata(ClassMetadata $metadata)
107108 {
@@ -111,8 +112,9 @@ following:
111112
112113 .. tip ::
113114
114- Protected and private properties can also be validated, as well as "getter"
115- methods (see :ref: `validator-constraint-targets `).
115+ Symfony's validator uses PHP reflection, as well as *"getter" * methods, to
116+ get the value of any property, so they can be public, private or protected
117+ (see :ref: `validator-constraint-targets `).
116118
117119.. index ::
118120 single: Validation; Using the validator
@@ -325,6 +327,7 @@ literature genre mostly associated with the author, which can be set to either
325327 .. code-block :: php-annotations
326328
327329 // src/Entity/Author.php
330+ namespace App\Entity;
328331
329332 // ...
330333 use Symfony\Component\Validator\Constraints as Assert;
@@ -337,7 +340,7 @@ literature genre mostly associated with the author, which can be set to either
337340 * message = "Choose a valid genre."
338341 * )
339342 */
340- public $genre;
343+ private $genre;
341344
342345 // ...
343346 }
@@ -378,14 +381,15 @@ literature genre mostly associated with the author, which can be set to either
378381 .. code-block :: php
379382
380383 // src/Entity/Author.php
384+ namespace App\Entity;
381385
382386 // ...
383387 use Symfony\Component\Validator\Constraints as Assert;
384388 use Symfony\Component\Validator\Mapping\ClassMetadata;
385389
386390 class Author
387391 {
388- public $genre;
392+ private $genre;
389393
390394 // ...
391395
@@ -412,6 +416,7 @@ options can be specified in this way.
412416 .. code-block :: php-annotations
413417
414418 // src/Entity/Author.php
419+ namespace App\Entity;
415420
416421 // ...
417422 use Symfony\Component\Validator\Constraints as Assert;
@@ -421,7 +426,7 @@ options can be specified in this way.
421426 /**
422427 * @Assert\Choice({"fiction", "non-fiction"})
423428 */
424- protected $genre;
429+ private $genre;
425430
426431 // ...
427432 }
@@ -459,14 +464,15 @@ options can be specified in this way.
459464 .. code-block :: php
460465
461466 // src/Entity/Author.php
467+ namespace App\Entity;
462468
463469 // ...
464470 use Symfony\Component\Validator\Constraints as Assert;
465471 use Symfony\Component\Validator\Mapping\ClassMetadata;
466472
467473 class Author
468474 {
469- protected $genre;
475+ private $genre;
470476
471477 public static function loadValidatorMetadata(ClassMetadata $metadata)
472478 {
@@ -579,6 +585,7 @@ class to have at least 3 characters.
579585 .. code-block :: php
580586
581587 // src/Entity/Author.php
588+ namespace App\Entity;
582589
583590 // ...
584591 use Symfony\Component\Validator\Constraints as Assert;
@@ -620,6 +627,7 @@ this method must return ``true``:
620627 .. code-block :: php-annotations
621628
622629 // src/Entity/Author.php
630+ namespace App\Entity;
623631
624632 // ...
625633 use Symfony\Component\Validator\Constraints as Assert;
@@ -664,6 +672,7 @@ this method must return ``true``:
664672 .. code-block :: php
665673
666674 // src/Entity/Author.php
675+ namespace App\Entity;
667676
668677 // ...
669678 use Symfony\Component\Validator\Constraints as Assert;
0 commit comments