From bfd2af43a0f8e98c2d711835f49b42718676594b Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 15 Apr 2014 18:36:55 +0200 Subject: [PATCH 1/4] [Book][Validation] configuration examples for the GroupSequenceProvider --- book/validation.rst | 73 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 63 insertions(+), 10 deletions(-) diff --git a/book/validation.rst b/book/validation.rst index 307420b2f8e..f0a54ab9b59 100644 --- a/book/validation.rst +++ b/book/validation.rst @@ -839,8 +839,8 @@ Group Sequence -------------- In some cases, you want to validate your groups by steps. To do this, you can -use the ``GroupSequence`` feature. In this case, an object defines a group sequence -, which determines the order groups should be validated. +use the ``GroupSequence`` feature. In this case, an object defines a group +sequence, which determines the order groups should be validated. For example, suppose you have a ``User`` class and want to validate that the username and the password are different only if all other validation passes @@ -1082,10 +1082,7 @@ Now, change the ``User`` class to implement :class:`Symfony\\Component\\Validator\\GroupSequenceProviderInterface` and add the :method:`Symfony\\Component\\Validator\\GroupSequenceProviderInterface::getGroupSequence`, -which should return an array of groups to use. Also, add the -``@Assert\GroupSequenceProvider`` annotation to the class (or ``group_sequence_provider: true`` to the YAML). If you imagine -that a method called ``isPremium`` returns true if the user is a premium member, -then your code might look like this:: +which should return an array of groups to use:: // src/Acme/DemoBundle/Entity/User.php namespace Acme\DemoBundle\Entity; @@ -1093,10 +1090,6 @@ then your code might look like this:: // ... use Symfony\Component\Validator\GroupSequenceProviderInterface; - /** - * @Assert\GroupSequenceProvider - * ... - */ class User implements GroupSequenceProviderInterface { // ... @@ -1113,6 +1106,66 @@ then your code might look like this:: } } +At last, you have to notify the Validator component that your ``User`` class +provides a sequence of groups to be validated: + +.. configuration-block:: + + .. code-block:: yaml + + # src/Acme/DemoBundle/Resources/config/validation.yml + Acme\DemoBundle\Entity\User: + group_sequence_provider: ~ + + .. code-block:: php-annotations + + // src/Acme/DemoBundle/Entity/User.php + namespace Acme\DemoBundle\Entity; + + // ... + + /** + * @Assert\GroupSequenceProvider + */ + class User implements GroupSequenceProviderInterface + { + // ... + } + + .. code-block:: xml + + + + + + + + + + + .. code-block:: php + + // src/Acme/DemoBundle/Entity/User.php + namespace Acme\DemoBundle\Entity; + + // ... + use Symfony\Component\Validator\Mapping\ClassMetadata; + + class User implements GroupSequenceProviderInterface + { + // ... + + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->setGroupSequenceProvider(true); + // ... + } + } + .. _book-validation-raw-values: Validating Values and Arrays From d8059e245d970d2913b8cd6ea5252edf13927cb3 Mon Sep 17 00:00:00 2001 From: Andrew M Date: Wed, 16 Apr 2014 10:18:39 +0300 Subject: [PATCH 2/4] Add missing autocomplete argument in askAndValidate method --- components/console/helpers/dialoghelper.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/components/console/helpers/dialoghelper.rst b/components/console/helpers/dialoghelper.rst index 3abf50b4a47..6917d807235 100644 --- a/components/console/helpers/dialoghelper.rst +++ b/components/console/helpers/dialoghelper.rst @@ -130,7 +130,8 @@ This methods has 2 new arguments, the full signature is:: string|array $question, callback $validator, integer $attempts = false, - string $default = null + string $default = null, + array $autocomplete = null ) The ``$validator`` is a callback which handles the validation. It should @@ -139,8 +140,8 @@ in the console, so it is a good practice to put some useful information in it. T function should also return the value of the user's input if the validation was successful. You can set the max number of times to ask in the ``$attempts`` argument. -If you reach this max number it will use the default value, which is given -in the last argument. Using ``false`` means the amount of attempts is infinite. +If you reach this max number it will use the default value. +Using ``false`` means the amount of attempts is infinite. The user will be asked as long as they provide an invalid answer and will only be able to proceed if their input is valid. From 3b8e644f82c4b33833487513c7bcdd567bd94e00 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Wed, 16 Apr 2014 14:16:23 +0200 Subject: [PATCH 3/4] Added some exceptions to the method order in CS --- contributing/code/standards.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contributing/code/standards.rst b/contributing/code/standards.rst index aadcb34ef90..7082565cee9 100644 --- a/contributing/code/standards.rst +++ b/contributing/code/standards.rst @@ -101,7 +101,10 @@ Structure * Declare class properties before methods; -* Declare public methods first, then protected ones and finally private ones; +* Declare public methods first, then protected ones and finally private ones. + The exceptions to this rule are the class constructor and the ``setUp`` and + ``tearDown`` methods of PHPUnit tests, which should always be the first methods + to increase readability. * Use parentheses when instantiating classes regardless of the number of arguments the constructor has; From b453fa60c3f48638f3b942a3787c10148d6b6a47 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Mon, 28 Apr 2014 17:49:03 -0500 Subject: [PATCH 4/4] [#3807] Fixing period to semicolon thanks to @xabbuh --- contributing/code/standards.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contributing/code/standards.rst b/contributing/code/standards.rst index 7082565cee9..bef7fc3af51 100644 --- a/contributing/code/standards.rst +++ b/contributing/code/standards.rst @@ -104,7 +104,7 @@ Structure * Declare public methods first, then protected ones and finally private ones. The exceptions to this rule are the class constructor and the ``setUp`` and ``tearDown`` methods of PHPUnit tests, which should always be the first methods - to increase readability. + to increase readability; * Use parentheses when instantiating classes regardless of the number of arguments the constructor has;