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

Appearance settings

Commit dc7cc73

Browse filesBrowse files
committed
minor #6300 Document constraint validator alias optional (Triiistan)
This PR was merged into the 2.3 branch. Discussion ---------- Document constraint validator alias optional | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no (symfony/symfony#17074) | Applies to | 2.3 | Fixed tickets | Same as #6055 but on the 2.3 branch as the relevant Symfony PR symfony/symfony#17074 was merged on 2.3. Commits ------- 873ede0 Document constraint validator alias optional
2 parents d8af809 + 873ede0 commit dc7cc73
Copy full SHA for dc7cc73

File tree

Expand file treeCollapse file tree

1 file changed

+4
-11
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+4
-11
lines changed

‎cookbook/validation/custom_constraint.rst

Copy file name to clipboardExpand all lines: cookbook/validation/custom_constraint.rst
+4-11Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ Constraint Validators with Dependencies
161161
If your constraint validator has dependencies, such as a database connection,
162162
it will need to be configured as a service in the Dependency Injection
163163
Container. This service must include the ``validator.constraint_validator``
164-
tag and an ``alias`` attribute:
164+
tag and may include an ``alias`` attribute:
165165

166166
.. configuration-block::
167167

@@ -189,21 +189,14 @@ tag and an ``alias`` attribute:
189189
->register('validator.unique.your_validator_name', 'Fully\Qualified\Validator\Class\Name')
190190
->addTag('validator.constraint_validator', array('alias' => 'alias_name'));
191191
192-
Your constraint class should now use this alias to reference the appropriate
193-
validator::
192+
As mentioned above, Symfony will automatically look for a class named after
193+
the constraint, with ``Validator`` appended. You can override this in your constraint class::
194194

195195
public function validatedBy()
196196
{
197-
return 'alias_name';
197+
return 'Fully\Qualified\ConstraintValidator\Class\Name'; // or 'alias_name' if provided
198198
}
199199

200-
As mentioned above, Symfony will automatically look for a class named after
201-
the constraint, with ``Validator`` appended. If your constraint validator
202-
is defined as a service, it's important that you override the
203-
``validatedBy()`` method to return the alias used when defining your service,
204-
otherwise Symfony won't use the constraint validator service, and will
205-
instantiate the class instead, without any dependencies injected.
206-
207200
Class Constraint Validator
208201
~~~~~~~~~~~~~~~~~~~~~~~~~~
209202

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.