Skip to content

Commit

Permalink
minor #5257 Let docbot review the constraint docs (WouterJ)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.3 branch.

Discussion
----------

Let docbot review the constraint docs

| Q | A
| --- | ---
| Doc fix? | yes, lots of them :)
| New docs? | no
| Applies to | 2.3+
| Fixed tickets | -

Commits
-------

08178a5 Review other reference articles
c765aa5 Let docbot review the constraint docs
  • Loading branch information
wouterj committed May 16, 2015
2 parents 3ebe1b2 + 08178a5 commit 034e5b4
Show file tree
Hide file tree
Showing 38 changed files with 504 additions and 412 deletions.
20 changes: 10 additions & 10 deletions reference/constraints/All.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ All
When applied to an array (or Traversable object), this constraint allows
you to apply a collection of constraints to each element of the array.

+----------------+------------------------------------------------------------------------+
| Applies to | :ref:`property or method <validation-property-target>` |
+----------------+------------------------------------------------------------------------+
| Options | - `constraints`_ |
+----------------+------------------------------------------------------------------------+
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\All` |
+----------------+------------------------------------------------------------------------+
| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\AllValidator` |
+----------------+------------------------------------------------------------------------+
+----------------+-------------------------------------------------------------------+
| Applies to | :ref:`property or method <validation-property-target>` |
+----------------+-------------------------------------------------------------------+
| Options | - `constraints`_ |
+----------------+-------------------------------------------------------------------+
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\All` |
+----------------+-------------------------------------------------------------------+
| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\AllValidator` |
+----------------+-------------------------------------------------------------------+

Basic Usage
-----------

Suppose that you have an array of strings, and you want to validate each
Suppose that you have an array of strings and you want to validate each
entry in that array:

.. configuration-block::
Expand Down
24 changes: 12 additions & 12 deletions reference/constraints/Blank.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ Blank

Validates that a value is blank, defined as equal to a blank string or equal
to ``null``. To force that a value strictly be equal to ``null``, see the
:doc:`/reference/constraints/Null` constraint. To force that a value is *not*
blank, see :doc:`/reference/constraints/NotBlank`.

+----------------+-----------------------------------------------------------------------+
| Applies to | :ref:`property or method <validation-property-target>` |
+----------------+-----------------------------------------------------------------------+
| Options | - `message`_ |
+----------------+-----------------------------------------------------------------------+
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\Blank` |
+----------------+-----------------------------------------------------------------------+
| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\BlankValidator` |
+----------------+-----------------------------------------------------------------------+
:doc:`/reference/constraints/Null` constraint. To force that a value is
*not* blank, see :doc:`/reference/constraints/NotBlank`.

+----------------+---------------------------------------------------------------------+
| Applies to | :ref:`property or method <validation-property-target>` |
+----------------+---------------------------------------------------------------------+
| Options | - `message`_ |
+----------------+---------------------------------------------------------------------+
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\Blank` |
+----------------+---------------------------------------------------------------------+
| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\BlankValidator` |
+----------------+---------------------------------------------------------------------+

Basic Usage
-----------
Expand Down
59 changes: 36 additions & 23 deletions reference/constraints/Callback.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ Callback
========

The purpose of the Callback assertion is to let you create completely custom
validation rules and to assign any validation errors to specific fields on
your object. If you're using validation with forms, this means that you can
make these custom errors display next to a specific field, instead of simply
at the top of your form.
validation rules and to assign any validation errors to specific fields
on your object. If you're using validation with forms, this means that you
can make these custom errors display next to a specific field, instead of
simply at the top of your form.

This process works by specifying one or more *callback* methods, each of
which will be called during the validation process. Each of those methods
Expand Down Expand Up @@ -92,9 +92,9 @@ Setup
The Callback Method
-------------------

The callback method is passed a special ``ExecutionContextInterface`` object. You
can set "violations" directly on this object and determine to which field
those errors should be attributed::
The callback method is passed a special ``ExecutionContextInterface`` object.
You can set "violations" directly on this object and determine to which
field those errors should be attributed::

// ...
use Symfony\Component\Validator\ExecutionContextInterface;
Expand All @@ -111,7 +111,12 @@ those errors should be attributed::

// check if the name is actually a fake name
if (in_array($this->getFirstName(), $fakeNames)) {
$context->addViolationAt('firstname', 'This name sounds totally fake!', array(), null);
$context->addViolationAt(
'firstname',
'This name sounds totally fake!',
array(),
null
);
}
}
}
Expand All @@ -129,9 +134,10 @@ process. Each method can be one of the following formats:

1) **String method name**

If the name of a method is a simple string (e.g. ``isAuthorValid``), that
method will be called on the same object that's being validated and the
``ExecutionContextInterface`` will be the only argument (see the above example).
If the name of a method is a simple string (e.g. ``isAuthorValid``),
that method will be called on the same object that's being validated
and the ``ExecutionContextInterface`` will be the only argument (see
the above example).

2) **Static array callback**

Expand Down Expand Up @@ -197,15 +203,19 @@ process. Each method can be one of the following formats:
{
$metadata->addConstraint(new Callback(array(
'methods' => array(
array('Acme\BlogBundle\MyStaticValidatorClass', 'isAuthorValid'),
array(
'Acme\BlogBundle\MyStaticValidatorClass',
'isAuthorValid',
),
),
)));
}
}
In this case, the static method ``isAuthorValid`` will be called on the
``Acme\BlogBundle\MyStaticValidatorClass`` class. It's passed both the original
object being validated (e.g. ``Author``) as well as the ``ExecutionContextInterface``::
In this case, the static method ``isAuthorValid`` will be called on
the ``Acme\BlogBundle\MyStaticValidatorClass`` class. It's passed both
the original object being validated (e.g. ``Author``) as well as the
``ExecutionContextInterface``::

namespace Acme\BlogBundle;

Expand All @@ -214,17 +224,20 @@ process. Each method can be one of the following formats:

class MyStaticValidatorClass
{
public static function isAuthorValid(Author $author, ExecutionContextInterface $context)
{
public static function isAuthorValid(
Author $author,
ExecutionContextInterface $context
) {
// ...
}
}

.. tip::

If you specify your ``Callback`` constraint via PHP, then you also have
the option to make your callback either a PHP closure or a non-static
callback. It is *not* currently possible, however, to specify a :term:`service`
as a constraint. To validate using a service, you should
:doc:`create a custom validation constraint </cookbook/validation/custom_constraint>`
and add that new constraint to your class.
If you specify your ``Callback`` constraint via PHP, then you also
have the option to make your callback either a PHP closure or a
non-static callback. It is *not* currently possible, however, to
specify a :term:`service` as a constraint. To validate using a service,
you should :doc:`create a custom validation constraint
</cookbook/validation/custom_constraint>` and add that new constraint
to your class.
20 changes: 12 additions & 8 deletions reference/constraints/CardScheme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ CardScheme
.. versionadded:: 2.2
The ``CardScheme`` constraint was introduced in Symfony 2.2.

This constraint ensures that a credit card number is valid for a given credit card
company. It can be used to validate the number before trying to initiate a payment
through a payment gateway.
This constraint ensures that a credit card number is valid for a given credit
card company. It can be used to validate the number before trying to initiate
a payment through a payment gateway.

+----------------+--------------------------------------------------------------------------+
| Applies to | :ref:`property or method <validation-property-target>` |
Expand Down Expand Up @@ -37,7 +37,10 @@ on an object that will contain a credit card number.
class Transaction
{
/**
* @Assert\CardScheme(schemes = {"VISA"}, message = "Your credit card number is invalid.")
* @Assert\CardScheme(
* schemes={"VISA"},
* message="Your credit card number is invalid."
* )
*/
protected $cardNumber;
}
Expand Down Expand Up @@ -103,9 +106,9 @@ schemes

**type**: ``mixed`` [:ref:`default option <validation-default-option>`]

This option is required and represents the name of the number scheme used to
validate the credit card number, it can either be a string or an array. Valid
values are:
This option is required and represents the name of the number scheme used
to validate the credit card number, it can either be a string or an array.
Valid values are:

* ``AMEX``
* ``CHINA_UNIONPAY``
Expand All @@ -118,7 +121,8 @@ values are:
* ``MASTERCARD``
* ``VISA``

For more information about the used schemes, see `Wikipedia: Issuer identification number (IIN)`_.
For more information about the used schemes, see
`Wikipedia: Issuer identification number (IIN)`_.

message
~~~~~~~
Expand Down
53 changes: 27 additions & 26 deletions reference/constraints/Choice.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ This constraint is used to ensure that the given value is one of a given
set of *valid* choices. It can also be used to validate that each item in
an array of items is one of those valid choices.

+----------------+-----------------------------------------------------------------------+
| Applies to | :ref:`property or method <validation-property-target>` |
+----------------+-----------------------------------------------------------------------+
| Options | - `choices`_ |
| | - `callback`_ |
| | - `multiple`_ |
| | - `min`_ |
| | - `max`_ |
| | - `message`_ |
| | - `multipleMessage`_ |
| | - `minMessage`_ |
| | - `maxMessage`_ |
| | - `strict`_ |
+----------------+-----------------------------------------------------------------------+
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\Choice` |
+----------------+-----------------------------------------------------------------------+
| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\ChoiceValidator` |
+----------------+-----------------------------------------------------------------------+
+----------------+----------------------------------------------------------------------+
| Applies to | :ref:`property or method <validation-property-target>` |
+----------------+----------------------------------------------------------------------+
| Options | - `choices`_ |
| | - `callback`_ |
| | - `multiple`_ |
| | - `min`_ |
| | - `max`_ |
| | - `message`_ |
| | - `multipleMessage`_ |
| | - `minMessage`_ |
| | - `maxMessage`_ |
| | - `strict`_ |
+----------------+----------------------------------------------------------------------+
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\Choice` |
+----------------+----------------------------------------------------------------------+
| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\ChoiceValidator` |
+----------------+----------------------------------------------------------------------+

Basic Usage
-----------
Expand Down Expand Up @@ -275,8 +275,8 @@ callback
**type**: ``string|array|Closure``

This is a callback method that can be used instead of the `choices`_ option
to return the choices array. See `Supplying the Choices with a Callback Function`_
for details on its usage.
to return the choices array. See
`Supplying the Choices with a Callback Function`_ for details on its usage.

multiple
~~~~~~~~
Expand Down Expand Up @@ -313,16 +313,17 @@ message

**type**: ``string`` **default**: ``The value you selected is not a valid choice.``

This is the message that you will receive if the ``multiple`` option is set
to ``false``, and the underlying value is not in the valid array of choices.
This is the message that you will receive if the ``multiple`` option is
set to ``false`` and the underlying value is not in the valid array of
choices.

multipleMessage
~~~~~~~~~~~~~~~

**type**: ``string`` **default**: ``One or more of the given values is invalid.``

This is the message that you will receive if the ``multiple`` option is set
to ``true``, and one of the values on the underlying array being checked
This is the message that you will receive if the ``multiple`` option is
set to ``true`` and one of the values on the underlying array being checked
is not in the array of valid choices.

minMessage
Expand All @@ -347,5 +348,5 @@ strict
**type**: ``Boolean`` **default**: ``false``

If true, the validator will also check the type of the input value. Specifically,
this value is passed to as the third argument to the PHP :phpfunction:`in_array` method
when checking to see if a value is in the valid choices array.
this value is passed to as the third argument to the PHP :phpfunction:`in_array`
method when checking to see if a value is in the valid choices array.
Loading

0 comments on commit 034e5b4

Please sign in to comment.