Skip to content

Commit 3364cbb

Browse files
richsageweaverryan
authored andcommitted
Clarified the use of the validatedBy method for custom contraint validators.
1 parent 546b1dd commit 3364cbb

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

cookbook/validation/custom_constraint.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,17 @@ tag and an ``alias`` attribute:
9898
->addTag('validator.constraint_validator', array('alias' => 'alias_name'))
9999
;
100100
101-
Your constraint class may now use this alias to reference the appropriate
101+
Your constraint class should now use this alias to reference the appropriate
102102
validator::
103103

104104
public function validatedBy()
105105
{
106106
return 'alias_name';
107-
}
107+
}
108+
109+
As mentioned above, Symfony2 will automatically look for a class named after
110+
the constraint, with ``Validator`` appended. If your constraint validator
111+
is defined as a service, it's important that you override the
112+
``validatedBy()`` method to return the alias used when defining your service,
113+
otherwise Symfony2 won't use the constraint validator service, and will
114+
instantiate the class instead, without any dependencies injected.

0 commit comments

Comments
 (0)