Skip to content

Commit 567419a

Browse files
committed
bug #5793 Callback Validation Constraint: Remove reference to deprecated option (ceithir)
This PR was merged into the 2.7 branch. Discussion ---------- Callback Validation Constraint: Remove reference to deprecated option | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.7 | Fixed tickets | / 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`) Commits ------- 67edbe2 Callback Validation Constraint: Remove reference to deprecated option
2 parents 25d459b + 67edbe2 commit 567419a

File tree

1 file changed

+26
-37
lines changed

1 file changed

+26
-37
lines changed

reference/constraints/Callback.rst

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -193,63 +193,51 @@ You can then use the following configuration to invoke this validator:
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/AppBundle/Resources/config/validation.yml
205+
AppBundle\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/AppBundle/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="AppBundle\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
227+
// src/AppBundle/Entity/Author.php
234228
namespace AppBundle\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
@@ -267,8 +255,9 @@ constructor of the Callback constraint::
267255
// src/AppBundle/Entity/Author.php
268256
namespace AppBundle\Entity;
269257

270-
use Symfony\Component\Validator\ExecutionContextInterface;
271-
use AppBundle\Entity\Author;
258+
use Symfony\Component\Validator\Context\ExecutionContextInterface;
259+
// if you're using the older 2.4 validation API, you'll need this instead
260+
// use Symfony\Component\Validator\ExecutionContextInterface;
272261

273262
use Symfony\Component\Validator\Mapping\ClassMetadata;
274263
use Symfony\Component\Validator\Constraints as Assert;

0 commit comments

Comments
 (0)