Skip to content

Commit d00066c

Browse files
committed
minor #15383 [Validator] Use more realistic example (OskarStark)
This PR was squashed before being merged into the 5.2 branch. Discussion ---------- [Validator] Use more realistic example Commits ------- 6aea5cc [Validator] Use more realistic example
2 parents ae7081d + 6aea5cc commit d00066c

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

reference/constraints/Compound.rst

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ you can create your own named set or requirements to be reused consistently ever
2626
.. configuration-block::
2727

2828
.. code-block:: php-annotations
29-
29+
3030
// src/Validator/Constraints/PasswordRequirements.php
3131
namespace App\Validator\Constraints;
3232
@@ -69,7 +69,7 @@ you can create your own named set or requirements to be reused consistently ever
6969
new Assert\NotCompromisedPassword(),
7070
];
7171
}
72-
}
72+
}
7373
7474
Add ``@Annotation`` or ``#[\Attribute]`` to the constraint class if you want to
7575
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:
8787

8888
.. code-block:: php-annotations
8989
90-
// src/User/RegisterUser.php
91-
namespace App\User;
90+
// src/Entity/User.php
91+
namespace App\Entity\User;
9292
93-
use App\Validator\Constraints as AcmeAssert;
93+
use App\Validator\Constraints as Assert;
9494
95-
class RegisterUser
95+
class User
9696
{
9797
/**
98-
* @AcmeAssert\PasswordRequirements()
98+
* @Assert\PasswordRequirements()
9999
*/
100-
public $password;
100+
public $plainPassword;
101101
}
102102
103103
.. code-block:: php-attributes
104104
105-
// src/User/RegisterUser.php
106-
namespace App\User;
105+
// src/Entity/User.php
106+
namespace App\Entity\User;
107107
108-
use App\Validator\Constraints as AcmeAssert;
108+
use App\Validator\Constraints as Assert;
109109
110-
class RegisterUser
110+
class User
111111
{
112-
#[AcmeAssert\PasswordRequirements]
113-
public $password;
112+
#[Assert\PasswordRequirements]
113+
public $plainPassword;
114114
}
115115
116116
.. code-block:: yaml
117117
118118
# config/validator/validation.yaml
119-
App\User\RegisterUser:
119+
App\Entity\User:
120120
properties:
121-
password:
121+
plainPassword:
122122
- App\Validator\Constraints\PasswordRequirements: ~
123123
124124
.. code-block:: xml
@@ -129,26 +129,26 @@ You can now use it anywhere you need it:
129129
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
130130
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping https://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
131131
132-
<class name="App\User\RegisterUser">
133-
<property name="password">
132+
<class name="App\Entity\User">
133+
<property name="plainPassword">
134134
<constraint name="App\Validator\Constraints\PasswordRequirements"/>
135135
</property>
136136
</class>
137137
</constraint-mapping>
138138
139139
.. code-block:: php
140140
141-
// src/User/RegisterUser.php
142-
namespace App\User;
141+
// src/Entity/User.php
142+
namespace App\Entity\User;
143143
144-
use App\Validator\Constraints as AcmeAssert;
144+
use App\Validator\Constraints as Assert;
145145
use Symfony\Component\Validator\Mapping\ClassMetadata;
146146
147-
class RegisterUser
147+
class User
148148
{
149149
public static function loadValidatorMetadata(ClassMetadata $metadata)
150150
{
151-
$metadata->addPropertyConstraint('password', new AcmeAssert\PasswordRequirements());
151+
$metadata->addPropertyConstraint('plainPassword', new Assert\PasswordRequirements());
152152
}
153153
}
154154

0 commit comments

Comments
 (0)