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

Commit954a9ef

Browse files
committed
Merge branch '2.1' into 2.2
2 parents4618929 +9aad603 commit954a9ef

File tree

5 files changed

+138
-10
lines changed

5 files changed

+138
-10
lines changed

‎book/validation.rst

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,9 @@ With this configuration, there are two validation groups:
781781

782782
* ``Default`` - contains the constraints not assigned to any other group;
783783

784+
* ``User`` - contains the constraints that belongs to group ``Default``
785+
(this group is useful for:ref:`book-validation-group-sequence`);
786+
784787
* ``registration`` - contains the constraints on the ``email`` and ``password``
785788
fields only.
786789

@@ -789,13 +792,138 @@ as the second argument to the ``validate()`` method::
789792

790793
$errors = $validator->validate($author, array('registration'));
791794

795+
If no groups are specified, all constraints that belong in group ``Default``
796+
will be applied.
797+
792798
Of course, you'll usually work with validation indirectly through the form
793799
library. For information on how to use validation groups inside forms, see
794800
:ref:`book-forms-validation-groups`.
795801

796802
..index::
797803
single: Validation; Validating raw values
798804

805+
.. _book-validation-group-sequence:
806+
807+
Group Sequence
808+
--------------
809+
810+
In some cases, you want to validate your groups by steps. To do this, you can
811+
use the ``GroupSequence`` feature. In the case, an object defines a group sequence,
812+
and then the groups in the group sequence are validated in order.
813+
814+
..tip::
815+
816+
Group sequences cannot contain the group ``Default``, as this would create
817+
a loop. Instead, use the group ``{ClassName}`` (e.g. ``User``) instead.
818+
819+
For example, suppose you have a ``User`` class and want to validate that the
820+
username and the password are different only if all other validation passes
821+
(in order to avoid multiple error messages).
822+
823+
..configuration-block::
824+
825+
..code-block::yaml
826+
827+
# src/Acme/BlogBundle/Resources/config/validation.yml
828+
Acme\BlogBundle\Entity\User:
829+
group_sequence:
830+
-User
831+
-Strict
832+
getters:
833+
passwordLegal:
834+
-"True":
835+
message:"The password cannot match your username"
836+
groups:[Strict]
837+
properties:
838+
username:
839+
-NotBlank:~
840+
password:
841+
-NotBlank:~
842+
843+
..code-block::php-annotations
844+
845+
// src/Acme/BlogBundle/Entity/User.php
846+
namespace Acme\BlogBundle\Entity;
847+
848+
use Symfony\Component\Security\Core\User\UserInterface;
849+
use Symfony\Component\Validator\Constraints as Assert;
850+
851+
/**
852+
* @Assert\GroupSequence({"Strict", "User"})
853+
*/
854+
class User implements UserInterface
855+
{
856+
/**
857+
* @Assert\NotBlank
858+
*/
859+
private $username;
860+
861+
/**
862+
* @Assert\NotBlank
863+
*/
864+
private $password;
865+
866+
/**
867+
* @Assert\True(message="The password cannot match your username", groups={"Strict"})
868+
*/
869+
public function isPasswordLegal()
870+
{
871+
return ($this->username !== $this->password);
872+
}
873+
}
874+
875+
..code-block::xml
876+
877+
<!-- src/Acme/BlogBundle/Resources/config/validation.xml-->
878+
<classname="Acme\BlogBundle\Entity\User">
879+
<propertyname="username">
880+
<constraintname="NotBlank" />
881+
</property>
882+
<propertyname="password">
883+
<constraintname="NotBlank" />
884+
</property>
885+
<getterproperty="passwordLegal">
886+
<constraintname="True">
887+
<optionname="message">The password cannot match your username</option>
888+
<optionname="groups">
889+
<value>Strict</value>
890+
</option>
891+
</constraint>
892+
</getter>
893+
<group-sequence>
894+
<value>User</value>
895+
<value>Strict</value>
896+
</group-sequence>
897+
</class>
898+
899+
..code-block::php
900+
901+
// src/Acme/BlogBundle/Entity/User.php
902+
namespace Acme\BlogBundle\Entity;
903+
904+
use Symfony\Component\Validator\Mapping\ClassMetadata;
905+
use Symfony\Component\Validator\Constraints as Assert;
906+
907+
class User
908+
{
909+
public static function loadValidatorMetadata(ClassMetadata $metadata)
910+
{
911+
$metadata->addPropertyConstraint('username', new Assert\NotBlank());
912+
$metadata->addPropertyConstraint('password', new Assert\NotBlank());
913+
914+
$metadata->addGetterConstraint('passwordLegal', new Assert\True(array(
915+
'message' => 'The password cannot match your first name',
916+
'groups' => array('Strict'),
917+
)));
918+
919+
$metadata->setGroupSequence(array('User', 'Strict'));
920+
}
921+
}
922+
923+
In this example, it will first validate all constraints in the group ``User``
924+
(which is the same as the ``Default`` group). Only if all constraints in
925+
that group are valid, the second group, ``Strict``, will be validated.
926+
799927
.. _book-validation-raw-values:
800928

801929
Validating Values and Arrays

‎contributing/code/patches.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ Set up your user information with your real name and a working email address:
3434

3535
..tip::
3636

37-
If your IDE creates configuration files inside project's directory,
37+
If your IDE creates configuration files insidetheproject's directory,
3838
you can use global ``.gitignore`` file (for all projects) or
3939
``.git/info/exclude`` file (per project) to ignore them. See
4040
`Github's documentation`_.
4141

4242
..tip::
4343

4444
Windows users: when installing Git, the installer will ask what to do with
45-
line endings and suggeststo replaceallLf by CRLF. This is the wrong
45+
line endings, and suggestsreplacingallLF with CRLF. This is the wrong
4646
setting if you wish to contribute to Symfony! Selecting the as-is method is
4747
your best choice, as git will convert your line feeds to the ones in the
4848
repository. If you have already installed Git, you can check the value of
@@ -52,8 +52,8 @@ Set up your user information with your real name and a working email address:
5252
5353
$ git config core.autocrlf
5454
55-
This will return either "false", "input" or "true", "true" and "false" being
56-
the wrong values.Set it toanother value by typing:
55+
This will return either "false", "input" or "true"; "true" and "false" being
56+
the wrong values.Change it to"input" by typing:
5757

5858
..code-block::bash
5959
@@ -344,7 +344,7 @@ because you want early feedback on your work, add an item to todo-list:
344344
..code-block::text
345345
346346
- [ ] finish the code
347-
- [ ] gather feedback my changes
347+
- [ ] gather feedbackformy changes
348348
349349
As long as you have items in the todo-list, please prefix the pull request
350350
title with "[WIP]".

‎contributing/code/standards.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ example containing most features described below:
4949
5050
/**
5151
* @param string $dummy Some argument description
52-
* @param array $options
52+
* @param array$options
5353
*
5454
* @return string|null Transformed input
5555
*/
56-
private function transformText($dummy, $options = array())
56+
private function transformText($dummy,array$options = array())
5757
{
5858
$mergedOptions = array_merge(
5959
$options,

‎reference/dic_tags.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ Finally, apply the filter:
194194
You can also apply your filter via the ``assetic.filters.my_filter.apply_to``
195195
config option as it's described here: :doc:`/cookbook/assetic/apply_to_option`.
196196
In order to do that, you must define your filter service in a separate xml
197-
config file and point to this file's via the ``assetic.filters.my_filter.resource``
197+
config file and point to this file'spathvia the ``assetic.filters.my_filter.resource``
198198
configuration key.
199199
200200
assetic.formula_loader

‎reference/forms/types/options/max_length.rst.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ max_length
33

44
**type**: ``integer``
55

6-
Thisoptionisusedtoadda ``max_length`` attribute, whichisusedby
7-
somebrowserstolimittheamountoftextinafield.
6+
Thisoptionisusedtoadda ``maxlength`` attribute, whichisusedby
7+
somebrowserstolimittheamountoftextinafield.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp