Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitff52222

Browse files
committed
Removing the alias stuff - not required aftersymfony/symfony#17074
1 parent80594da commitff52222

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

‎cookbook/validation/custom_constraint.rst‎

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -167,44 +167,41 @@ Constraint Validators with Dependencies
167167
If your constraint validator has dependencies, such as a database connection,
168168
it will need to be configured as a service in the Dependency Injection
169169
Container. This service must include the ``validator.constraint_validator``
170-
tagand should include an ``alias`` attribute to be used inthevalidatedBy method of your validator class:
170+
tagso thatthevalidation system knows about it::
171171

172172
..configuration-block::
173173

174174
..code-block::yaml
175175
176176
# app/config/services.yml
177177
services:
178-
validator.unique.your_validator_name:
179-
class:Fully\Qualified\Validator\Class\Name
178+
validator.contains_alphanumeric:
179+
class:AppBundle\Validator\Constraints\ContainsAlphanumericValidator
180180
tags:
181-
-{ name: validator.constraint_validator, alias: alias_name }
181+
-{ name: validator.constraint_validator }
182182
183183
..code-block::xml
184184
185185
<!-- app/config/services.xml-->
186-
<serviceid="validator.unique.your_validator_name"class="Fully\Qualified\Validator\Class\Name">
186+
<serviceid="validator.contains_alphanumeric"class="AppBundle\Validator\Constraints\ContainsAlphanumericValidator">
187187
<argumenttype="service"id="doctrine.orm.default_entity_manager" />
188-
<tagname="validator.constraint_validator"alias="alias_name"/>
188+
<tagname="validator.constraint_validator" />
189189
</service>
190190
191191
..code-block::php
192192
193193
// app/config/services.php
194194
$container
195-
->register('validator.unique.your_validator_name', 'Fully\Qualified\Validator\Class\Name')
196-
->addTag('validator.constraint_validator', array('alias' => 'alias_name'));
195+
->register('validator.contains_alphanumeric', 'AppBundle\Validator\Constraints\ContainsAlphanumericValidator')
196+
->addTag('validator.constraint_validator');
197197
198-
As mentioned above,Symfonywill automatically lookfora class named after
199-
the constraint, with ``Validator`` appended. You can overridethisin your constraint class::
198+
Now, whenSymfonylooksforthe ``ContainsAlphanumericValidator`` validator, it will
199+
loadthisservice from the container.
200200

201-
public function validatedBy()
202-
{
203-
return 'Fully\Qualified\ConstraintValidator\Class\Name'; // or 'alias_name' if provided
204-
}
205-
206-
Make sure to use the 'alias_name' when you have configured your validator as a service. Otherwise your validator class
207-
will be simply instantiated without your dependencies.
201+
..note::
202+
In earlier versions of Symfony, the tag required an ``alias`` key (usually set
203+
to the class name). This is still allowed your constraint's ``validateBy``
204+
method can return this alias (instead of a class name).
208205

209206
Class Constraint Validator
210207
~~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp