Skip to content

Commit 3754164

Browse files
author
Éric
committed
Callback Validation Constraint: Remove reference to deprecated option
Regression from 2.6: http://symfony.com/doc/2.6/reference/constraints/Callback.html#external-callbacks-and-closures The examples were still using the old, deprecated syntax... And even calling a method not defined anymore (`isAuthorValid` instead of `validate`)
1 parent 61efc58 commit 3754164

File tree

1 file changed

+36
-51
lines changed

1 file changed

+36
-51
lines changed

reference/constraints/Callback.rst

Lines changed: 36 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ Configuration
3535

3636
.. code-block:: php-annotations
3737
38-
// src/AppBundle/Entity/Author.php
39-
namespace AppBundle\Entity;
38+
// src/Acme/BlogBundle/Entity/Author.php
39+
namespace Acme\BlogBundle\Entity;
4040
4141
use Symfony\Component\Validator\Constraints as Assert;
4242
use Symfony\Component\Validator\Context\ExecutionContextInterface;
@@ -56,28 +56,28 @@ Configuration
5656
5757
.. code-block:: yaml
5858
59-
# src/AppBundle/Resources/config/validation.yml
60-
AppBundle\Entity\Author:
59+
# src/Acme/BlogBundle/Resources/config/validation.yml
60+
Acme\BlogBundle\Entity\Author:
6161
constraints:
6262
- Callback: [validate]
6363
6464
.. code-block:: xml
6565
66-
<!-- src/AppBundle/Resources/config/validation.xml -->
66+
<!-- src/Acme/BlogBundle/Resources/config/validation.xml -->
6767
<?xml version="1.0" encoding="UTF-8" ?>
6868
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
6969
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7070
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
7171
72-
<class name="AppBundle\Entity\Author">
72+
<class name="Acme\BlogBundle\Entity\Author">
7373
<constraint name="Callback">validate</constraint>
7474
</class>
7575
</constraint-mapping>
7676
7777
.. code-block:: php
7878
79-
// src/AppBundle/Entity/Author.php
80-
namespace AppBundle\Entity;
79+
// src/Acme/BlogBundle/Entity/Author.php
80+
namespace Acme\BlogBundle\Entity;
8181
8282
use Symfony\Component\Validator\Mapping\ClassMetadata;
8383
use Symfony\Component\Validator\Constraints as Assert;
@@ -187,69 +187,57 @@ You can then use the following configuration to invoke this validator:
187187

188188
.. code-block:: php-annotations
189189
190-
// src/AppBundle/Entity/Author.php
191-
namespace AppBundle\Entity;
190+
// src/Acme/BlogBundle/Entity/Author.php
191+
namespace Acme\BlogBundle\Entity;
192192
193193
use Symfony\Component\Validator\Constraints as Assert;
194194
195195
/**
196-
* @Assert\Callback({"AppBundle\MyStaticValidatorClass", "isAuthorValid"})
196+
* @Assert\Callback({"Vendor\Package\Validator", "validate"})
197197
*/
198198
class Author
199199
{
200200
}
201201
202202
.. code-block:: yaml
203203
204-
# src/AppBundle/Resources/config/validation.yml
205-
AppBundle\Entity\Author:
206-
constraints:
207-
- Callback:
208-
methods:
209-
- [AppBundle\MyStaticValidatorClass, isAuthorValid]
204+
# src/Acme/BlogBundle/Resources/config/validation.yml
205+
Acme\BlogBundle\Entity\Author:
206+
constraints:
207+
- Callback: [Vendor\Package\Validator, validate]
210208
211209
.. code-block:: xml
212210
213-
<!-- src/AppBundle/Resources/config/validation.xml -->
214-
<?xml version="1.0" encoding="UTF-8" ?>
215-
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
216-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
217-
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
218-
219-
<class name="AppBundle\Entity\Author">
220-
<constraint name="Callback">
221-
<option name="methods">
222-
<value>
223-
<value>AppBundle\MyStaticValidatorClass</value>
224-
<value>isAuthorValid</value>
225-
</value>
226-
</option>
227-
</constraint>
228-
</class>
229-
</constraint-mapping>
211+
<!-- src/Acme/BlogBundle/Resources/config/validation.xml -->
212+
<?xml version="1.0" encoding="UTF-8" ?>
213+
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
214+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
215+
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
216+
217+
<class name="Acme\BlogBundle\Entity\Author">
218+
<constraint name="Callback">
219+
<value>Vendor\Package\Validator</value>
220+
<value>validate</value>
221+
</constraint>
222+
</class>
223+
</constraint-mapping>
230224
231225
.. code-block:: php
232226
233-
// src/AppBundle/Entity/Author.php
234-
namespace AppBundle\Entity;
227+
// src/Acme/BlogBundle/Entity/Author.php
228+
namespace Acme\BlogBundle\Entity;
235229
236230
use Symfony\Component\Validator\Mapping\ClassMetadata;
237231
use Symfony\Component\Validator\Constraints as Assert;
238232
239233
class Author
240234
{
241-
public $name;
242-
243235
public static function loadValidatorMetadata(ClassMetadata $metadata)
244236
{
245-
$metadata->addConstraint(new Callback(array(
246-
'methods' => array(
247-
array(
248-
'AppBundle\MyStaticValidatorClass',
249-
'isAuthorValid',
250-
),
251-
),
252-
)));
237+
$metadata->addConstraint(new Assert\Callback(array(
238+
'Vendor\Package\Validator',
239+
'validate',
240+
)));
253241
}
254242
}
255243
@@ -264,11 +252,8 @@ You can then use the following configuration to invoke this validator:
264252
When configuring the constraint via PHP, you can also pass a closure to the
265253
constructor of the Callback constraint::
266254

267-
// src/AppBundle/Entity/Author.php
268-
namespace AppBundle\Entity;
269-
270-
use Symfony\Component\Validator\ExecutionContextInterface;
271-
use AppBundle\Entity\Author;
255+
// src/Acme/BlogBundle/Entity/Author.php
256+
namespace Acme\BlogBundle\Entity;
272257

273258
use Symfony\Component\Validator\Mapping\ClassMetadata;
274259
use Symfony\Component\Validator\Constraints as Assert;

0 commit comments

Comments
 (0)