@@ -161,7 +161,7 @@ Constraint Validators with Dependencies
161
161
If your constraint validator has dependencies, such as a database connection,
162
162
it will need to be configured as a service in the Dependency Injection
163
163
Container. This service must include the ``validator.constraint_validator ``
164
- tag and an ``alias `` attribute:
164
+ tag and may include an ``alias `` attribute:
165
165
166
166
.. configuration-block ::
167
167
@@ -189,21 +189,14 @@ tag and an ``alias`` attribute:
189
189
->register('validator.unique.your_validator_name', 'Fully\Qualified\Validator\Class\Name')
190
190
->addTag('validator.constraint_validator', array('alias' => 'alias_name'));
191
191
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 ::
194
194
195
195
public function validatedBy()
196
196
{
197
- return 'alias_name';
197
+ return 'Fully\Qualified\ConstraintValidator\Class\Name'; // or 'alias_name' if provided
198
198
}
199
199
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
-
207
200
Class Constraint Validator
208
201
~~~~~~~~~~~~~~~~~~~~~~~~~~
209
202
0 commit comments