Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit322972e

Browse files
committed
featuresymfony#3803 [Book][Validation] configuration examples for the GroupSequenceProvider (xabbuh)
This PR was merged into the 2.3 branch.Discussion----------[Book][Validation] configuration examples for the GroupSequenceProvider| Q | A| ------------- | ---| Doc fix? | yes| New docs? | no| Applies to | all| Fixed tickets |This pull requests adds examples in different formats for the GroupSequenceProvider feature of the Validator component (it's the completion ofsymfony#3369).Commits-------bfd2af4 [Book][Validation] configuration examples for the GroupSequenceProvider
2 parents55442b5 +bfd2af4 commit322972e

File tree

1 file changed

+63
-10
lines changed

1 file changed

+63
-10
lines changed

‎book/validation.rst

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -839,8 +839,8 @@ Group Sequence
839839
--------------
840840

841841
In some cases, you want to validate your groups by steps. To do this, you can
842-
use the ``GroupSequence`` feature. In this case, an object defines a group sequence
843-
, which determines the order groups should be validated.
842+
use the ``GroupSequence`` feature. In this case, an object defines a group
843+
sequence, which determines the order groups should be validated.
844844

845845
For example, suppose you have a ``User`` class and want to validate that the
846846
username and the password are different only if all other validation passes
@@ -1082,21 +1082,14 @@ Now, change the ``User`` class to implement
10821082
:class:`Symfony\\Component\\Validator\\GroupSequenceProviderInterface` and
10831083
add the
10841084
:method:`Symfony\\Component\\Validator\\GroupSequenceProviderInterface::getGroupSequence`,
1085-
which should return an array of groups to use. Also, add the
1086-
``@Assert\GroupSequenceProvider`` annotation to the class (or ``group_sequence_provider: true`` to the YAML). If you imagine
1087-
that a method called ``isPremium`` returns true if the user is a premium member,
1088-
then your code might look like this::
1085+
which should return an array of groups to use::
10891086

10901087
// src/Acme/DemoBundle/Entity/User.php
10911088
namespace Acme\DemoBundle\Entity;
10921089

10931090
// ...
10941091
use Symfony\Component\Validator\GroupSequenceProviderInterface;
10951092

1096-
/**
1097-
* @Assert\GroupSequenceProvider
1098-
* ...
1099-
*/
11001093
class User implements GroupSequenceProviderInterface
11011094
{
11021095
// ...
@@ -1113,6 +1106,66 @@ then your code might look like this::
11131106
}
11141107
}
11151108

1109+
At last, you have to notify the Validator component that your ``User`` class
1110+
provides a sequence of groups to be validated:
1111+
1112+
..configuration-block::
1113+
1114+
..code-block::yaml
1115+
1116+
# src/Acme/DemoBundle/Resources/config/validation.yml
1117+
Acme\DemoBundle\Entity\User:
1118+
group_sequence_provider:~
1119+
1120+
..code-block::php-annotations
1121+
1122+
// src/Acme/DemoBundle/Entity/User.php
1123+
namespace Acme\DemoBundle\Entity;
1124+
1125+
// ...
1126+
1127+
/**
1128+
* @Assert\GroupSequenceProvider
1129+
*/
1130+
class User implements GroupSequenceProviderInterface
1131+
{
1132+
// ...
1133+
}
1134+
1135+
..code-block::xml
1136+
1137+
<!-- src/Acme/DemoBundle/Resources/config/validation.xml-->
1138+
<?xml version="1.0" encoding="UTF-8" ?>
1139+
<constraint-mappingxmlns="http://symfony.com/schema/dic/constraint-mapping"
1140+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1141+
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping
1142+
http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd"
1143+
>
1144+
<classname="Acme\DemoBundle\Entity\User">
1145+
<group-sequence-provider />
1146+
<!-- ...-->
1147+
</class>
1148+
</constraint-mapping>
1149+
1150+
..code-block::php
1151+
1152+
// src/Acme/DemoBundle/Entity/User.php
1153+
namespace Acme\DemoBundle\Entity;
1154+
1155+
// ...
1156+
use Symfony\Component\Validator\Mapping\ClassMetadata;
1157+
1158+
class User implements GroupSequenceProviderInterface
1159+
{
1160+
// ...
1161+
1162+
public static function loadValidatorMetadata(ClassMetadata $metadata)
1163+
{
1164+
$metadata->setGroupSequenceProvider(true);
1165+
// ...
1166+
}
1167+
}
1168+
11161169
.. _book-validation-raw-values:
11171170

11181171
Validating Values and Arrays

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp