@@ -26,7 +26,7 @@ you can create your own named set or requirements to be reused consistently ever
26
26
.. configuration-block ::
27
27
28
28
.. code-block :: php-annotations
29
-
29
+
30
30
// src/Validator/Constraints/PasswordRequirements.php
31
31
namespace App\Validator\Constraints;
32
32
@@ -69,7 +69,7 @@ you can create your own named set or requirements to be reused consistently ever
69
69
new Assert\NotCompromisedPassword(),
70
70
];
71
71
}
72
- }
72
+ }
73
73
74
74
Add ``@Annotation `` or ``#[\Attribute] `` to the constraint class if you want to
75
75
use it as an annotation/attribute in other classes. If the constraint has
@@ -87,38 +87,38 @@ You can now use it anywhere you need it:
87
87
88
88
.. code-block :: php-annotations
89
89
90
- // src/User/RegisterUser .php
91
- namespace App\User;
90
+ // src/Entity/User .php
91
+ namespace App\Entity\ User;
92
92
93
- use App\Validator\Constraints as AcmeAssert ;
93
+ use App\Validator\Constraints as Assert ;
94
94
95
- class RegisterUser
95
+ class User
96
96
{
97
97
/**
98
- * @AcmeAssert \PasswordRequirements()
98
+ * @Assert \PasswordRequirements()
99
99
*/
100
- public $password ;
100
+ public $plainPassword ;
101
101
}
102
102
103
103
.. code-block :: php-attributes
104
104
105
- // src/User/RegisterUser .php
106
- namespace App\User;
105
+ // src/Entity/User .php
106
+ namespace App\Entity\ User;
107
107
108
- use App\Validator\Constraints as AcmeAssert ;
108
+ use App\Validator\Constraints as Assert ;
109
109
110
- class RegisterUser
110
+ class User
111
111
{
112
- #[AcmeAssert \PasswordRequirements]
113
- public $password ;
112
+ #[Assert \PasswordRequirements]
113
+ public $plainPassword ;
114
114
}
115
115
116
116
.. code-block :: yaml
117
117
118
118
# config/validator/validation.yaml
119
- App\User\RegisterUser :
119
+ App\Entity\User :
120
120
properties :
121
- password :
121
+ plainPassword :
122
122
- App\Validator\Constraints\PasswordRequirements : ~
123
123
124
124
.. code-block :: xml
@@ -129,26 +129,26 @@ You can now use it anywhere you need it:
129
129
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
130
130
xsi : schemaLocation =" http://symfony.com/schema/dic/constraint-mapping https://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd" >
131
131
132
- <class name =" App\User\RegisterUser " >
133
- <property name =" password " >
132
+ <class name =" App\Entity\User " >
133
+ <property name =" plainPassword " >
134
134
<constraint name =" App\Validator\Constraints\PasswordRequirements" />
135
135
</property >
136
136
</class >
137
137
</constraint-mapping >
138
138
139
139
.. code-block :: php
140
140
141
- // src/User/RegisterUser .php
142
- namespace App\User;
141
+ // src/Entity/User .php
142
+ namespace App\Entity\ User;
143
143
144
- use App\Validator\Constraints as AcmeAssert ;
144
+ use App\Validator\Constraints as Assert ;
145
145
use Symfony\Component\Validator\Mapping\ClassMetadata;
146
146
147
- class RegisterUser
147
+ class User
148
148
{
149
149
public static function loadValidatorMetadata(ClassMetadata $metadata)
150
150
{
151
- $metadata->addPropertyConstraint('password ', new AcmeAssert \PasswordRequirements());
151
+ $metadata->addPropertyConstraint('plainPassword ', new Assert \PasswordRequirements());
152
152
}
153
153
}
154
154
0 commit comments