@@ -132,112 +132,111 @@ methods
132132This is an array of the methods that should be executed during the validation
133133process. Each method can be one of the following formats:
134134
135- 1) **String method name **
135+ 1) String method name
136+ .....................
136137
137- If the name of a method is a simple string (e.g. ``isAuthorValid ``),
138- that method will be called on the same object that's being validated
139- and the ``ExecutionContextInterface `` will be the only argument (see
140- the above example).
138+ If the name of a method is a simple string (e.g. ``isAuthorValid ``), that method
139+ will be called on the same object that's being validated and the
140+ ``ExecutionContextInterface `` will be the only argument (see the above example).
141141
1421422) **Static array callback **
143+ ............................
143144
144- Each method can also be specified as a standard array callback:
145+ Each method can also be specified as a standard array callback:
145146
146- .. configuration-block ::
147+ .. configuration-block ::
147148
148- .. code-block :: php-annotations
149+ .. code-block :: php-annotations
149150
150- // src/AppBundle/Entity/Author.php
151- use Symfony\Component\Validator\Constraints as Assert;
151+ // src/AppBundle/Entity/Author.php
152+ use Symfony\Component\Validator\Constraints as Assert;
152153
153- /**
154- * @Assert\Callback(methods={
155- * { "AppBundle\MyStaticValidatorClass", "isAuthorValid" }
156- * })
157- */
158- class Author
159- {
160- }
154+ /**
155+ * @Assert\Callback(methods={
156+ * { "AppBundle\MyStaticValidatorClass", "isAuthorValid" }
157+ * })
158+ */
159+ class Author
160+ {
161+ }
161162
162- .. code-block :: yaml
163+ .. code-block :: yaml
163164
164- # src/AppBundle/Resources/config/validation.yml
165- AppBundle\Entity\Author :
166- constraints :
167- - Callback :
168- methods :
169- - [AppBundle\MyStaticValidatorClass, isAuthorValid]
165+ # src/AppBundle/Resources/config/validation.yml
166+ AppBundle\Entity\Author :
167+ constraints :
168+ - Callback :
169+ methods :
170+ - [AppBundle\MyStaticValidatorClass, isAuthorValid]
170171
171- .. code-block :: xml
172+ .. code-block :: xml
172173
173- <!-- src/AppBundle/Resources/config/validation.xml -->
174- <?xml version =" 1.0" encoding =" UTF-8" ?>
175- <constraint-mapping xmlns =" http://symfony.com/schema/dic/constraint-mapping"
176- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
177- xsi : schemaLocation =" http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd" >
174+ <!-- src/AppBundle/Resources/config/validation.xml -->
175+ <?xml version =" 1.0" encoding =" UTF-8" ?>
176+ <constraint-mapping xmlns =" http://symfony.com/schema/dic/constraint-mapping"
177+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
178+ xsi : schemaLocation =" http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd" >
178179
179- <class name =" AppBundle\Entity\Author" >
180- <constraint name =" Callback" >
181- <option name =" methods" >
182- <value >
183- <value >AppBundle\MyStaticValidatorClass</value >
184- <value >isAuthorValid</value >
185- </value >
186- </option >
187- </constraint >
188- </class >
189- </constraint-mapping >
180+ <class name =" AppBundle\Entity\Author" >
181+ <constraint name =" Callback" >
182+ <option name =" methods" >
183+ <value >
184+ <value >AppBundle\MyStaticValidatorClass</value >
185+ <value >isAuthorValid</value >
186+ </value >
187+ </option >
188+ </constraint >
189+ </class >
190+ </constraint-mapping >
190191
191- .. code-block :: php
192+ .. code-block :: php
192193
193- // src/AppBundle/Entity/Author.php
194+ // src/AppBundle/Entity/Author.php
194195
195- use Symfony\Component\Validator\Mapping\ClassMetadata;
196- use Symfony\Component\Validator\Constraints\Callback;
196+ use Symfony\Component\Validator\Mapping\ClassMetadata;
197+ use Symfony\Component\Validator\Constraints\Callback;
197198
198- class Author
199+ class Author
200+ {
201+ public $name;
202+
203+ public static function loadValidatorMetadata(ClassMetadata $metadata)
199204 {
200- public $name;
201-
202- public static function loadValidatorMetadata(ClassMetadata $metadata)
203- {
204- $metadata->addConstraint(new Callback(array(
205- 'methods' => array(
206- array(
207- 'AppBundle\MyStaticValidatorClass',
208- 'isAuthorValid',
209- ),
205+ $metadata->addConstraint(new Callback(array(
206+ 'methods' => array(
207+ array(
208+ 'AppBundle\MyStaticValidatorClass',
209+ 'isAuthorValid',
210210 ),
211- )));
212- }
211+ ),
212+ )));
213213 }
214+ }
214215
215- In this case, the static method ``isAuthorValid `` will be called on
216- the ``AppBundle\MyStaticValidatorClass `` class. It's passed both
217- the original object being validated (e.g. ``Author ``) as well as the
218- ``ExecutionContextInterface ``::
216+ In this case, the static method ``isAuthorValid `` will be called on the
217+ ``AppBundle\MyStaticValidatorClass `` class. It's passed both the original object
218+ being validated (e.g. ``Author ``) as well as the ``ExecutionContextInterface ``::
219219
220- namespace AppBundle;
220+ namespace AppBundle;
221221
222- use Symfony\Component\Validator\ExecutionContextInterface;
223- use AppBundle\Entity\Author;
222+ use Symfony\Component\Validator\ExecutionContextInterface;
223+ use AppBundle\Entity\Author;
224224
225- class MyStaticValidatorClass
226- {
227- public static function isAuthorValid(
228- Author $author,
229- ExecutionContextInterface $context
230- ) {
231- // ...
232- }
225+ class MyStaticValidatorClass
226+ {
227+ public static function isAuthorValid(
228+ Author $author,
229+ ExecutionContextInterface $context
230+ ) {
231+ // ...
233232 }
233+ }
234234
235- .. tip ::
235+ .. tip ::
236236
237- If you specify your ``Callback `` constraint via PHP, then you also
238- have the option to make your callback either a PHP closure or a
239- non-static callback. It is *not * currently possible, however, to
240- specify a :term: `service ` as a constraint. To validate using a service,
241- you should :doc: `create a custom validation constraint
242- </cookbook/validation/custom_constraint>` and add that new constraint
243- to your class.
237+ If you specify your ``Callback `` constraint via PHP, then you also have the
238+ option to make your callback either a PHP closure or a non-static callback.
239+ It is *not * currently possible, however, to specify a :term: `service ` as a
240+ constraint. To validate using a service, you should :doc: `create a custom
241+ validation constraint </cookbook/validation/custom_constraint>` and add that
242+ new constraint to your class.
0 commit comments