Skip to content

Commit

Permalink
Merge branch '2.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverryan committed Apr 28, 2014
2 parents c8bfde6 + fed881d commit 69b52c7
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 18 deletions.
73 changes: 63 additions & 10 deletions book/validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,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
Expand Down Expand Up @@ -1085,21 +1085,14 @@ 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;

// ...
use Symfony\Component\Validator\GroupSequenceProviderInterface;

/**
* @Assert\GroupSequenceProvider
* ...
*/
class User implements GroupSequenceProviderInterface
{
// ...
Expand All @@ -1116,6 +1109,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
<!-- src/Acme/DemoBundle/Resources/config/validation.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping
http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd"
>
<class name="Acme\DemoBundle\Entity\User">
<group-sequence-provider />
<!-- ... -->
</class>
</constraint-mapping>
.. 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
Expand Down
7 changes: 4 additions & 3 deletions components/console/helpers/dialoghelper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,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
Expand All @@ -140,8 +141,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.

Expand Down
8 changes: 4 additions & 4 deletions components/expression_language/syntax.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ to JavaScript::
)
);

This will print ``Honeycrisp``.
This will print out ``Honeycrisp``.

Calling Methods
~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -79,7 +79,7 @@ JavaScript::
)
);

This will print ``Hi Hi Hi!``.
This will print out ``Hi Hi Hi!``.

.. _component-expression-functions:

Expand All @@ -97,7 +97,7 @@ constant::
'constant("DB_USER")'
);

This will print ``root``.
This will print out ``root``.

.. tip::

Expand All @@ -121,7 +121,7 @@ array keys, similar to JavaScript::
)
);

This will print ``42``.
This will print out ``42``.

Supported Operators
-------------------
Expand Down
5 changes: 4 additions & 1 deletion contributing/code/standards.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 69b52c7

Please sign in to comment.