From 635c8c8dee2646918550660f21f0129cb691e18b Mon Sep 17 00:00:00 2001 From: WouterJ Date: Fri, 3 May 2013 15:10:51 +0200 Subject: [PATCH 1/8] Added documentation for the EqualConstraint --- reference/constraints.rst | 2 + reference/constraints/EqualTo.rst | 106 ++++++++++++++++++++++++++++++ reference/constraints/map.rst.inc | 5 ++ 3 files changed, 113 insertions(+) create mode 100644 reference/constraints/EqualTo.rst diff --git a/reference/constraints.rst b/reference/constraints.rst index 1ed9b35649b..3eab0ce9a52 100644 --- a/reference/constraints.rst +++ b/reference/constraints.rst @@ -21,6 +21,8 @@ Validation Constraints Reference constraints/Range + constraints/EqualTo + constraints/Date constraints/DateTime constraints/Time diff --git a/reference/constraints/EqualTo.rst b/reference/constraints/EqualTo.rst new file mode 100644 index 00000000000..2d13904b540 --- /dev/null +++ b/reference/constraints/EqualTo.rst @@ -0,0 +1,106 @@ +EqualTo +======= + +.. versionadded:: 2.3 + This constraint is new in version 2.3. + +Validates that a value is equal to another value, defined in the options. To +force that a value is *not* equal, see :doc:`/reference/constraints/NotEqual`. + +.. caution:: + + This constraint compares using ``==``, so ``3`` and ``"3"`` are considered + equal. Use :doc:`/reference/constraints/IdenticalTo` to compare with + ``===``. + ++----------------+-----------------------------------------------------------------------+ +| Applies to | :ref:`property or method` | ++----------------+-----------------------------------------------------------------------+ +| Options | - `value`_ | +| | - `message`_ | ++----------------+-----------------------------------------------------------------------+ +| Class | :class:`Symfony\\Component\\Validator\\Constraints\\EqualTo` | ++----------------+-----------------------------------------------------------------------+ +| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\EqualToValidator` | ++----------------+-----------------------------------------------------------------------+ + +Basic Usage +----------- + +If you want to ensure that the ``age`` of a ``Person`` class is equal to +``20``, you could do the following: + +.. configuration-block:: + + .. code-block:: yaml + + # src/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - EqualTo: + value: 20 + + .. code-block:: php-annotations + + // src/Acme/SocialBundle/Entity/Person.php + namespace Acme\SocialBundle\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Person + { + /** + * @Assert\EqualTo( + * value = 20 + * ) + */ + protected $age; + } + + .. code-block:: xml + + + + + + + + + + + .. code-block:: php + + // src/Acme/SocialBundle/Entity/Person.php + namespace Acme\SocialBundle\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Person + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('age', new Assert\EqualTo(array( + 'value' => 20, + ))); + } + } + +Options +------- + +value +~~~~~ + +**type**: ``mixed`` + +This option is required. It defines the value to compare to. It can be a +string, number or object. + +message +~~~~~~~ + +**type**: ``string`` **default**: ``This value should be equal to {{ compared_value }}`` + +This is the message that will be shown if the value is not equal. diff --git a/reference/constraints/map.rst.inc b/reference/constraints/map.rst.inc index 3d10d637ccf..69b47c10162 100644 --- a/reference/constraints/map.rst.inc +++ b/reference/constraints/map.rst.inc @@ -26,6 +26,11 @@ Number Constraints * :doc:`Range ` +Comparison Constraints +~~~~~~~~~~~~~~~~~~~~~~ + +* :doc:`EqualTo ` + Date Constraints ~~~~~~~~~~~~~~~~ From 48ca4f0d89d01e421960a58e0bf7d68aa7be21d4 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Fri, 3 May 2013 16:05:28 +0200 Subject: [PATCH 2/8] Added docs for NotEqualTo validator --- reference/constraints.rst | 1 + reference/constraints/EqualTo.rst | 10 +- reference/constraints/NotEqualTo.rst | 101 ++++++++++++++++++ .../_comparison-value-option.rst.inc | 7 ++ reference/constraints/map.rst.inc | 1 + 5 files changed, 112 insertions(+), 8 deletions(-) create mode 100644 reference/constraints/NotEqualTo.rst create mode 100644 reference/constraints/_comparison-value-option.rst.inc diff --git a/reference/constraints.rst b/reference/constraints.rst index 3eab0ce9a52..425248c26c3 100644 --- a/reference/constraints.rst +++ b/reference/constraints.rst @@ -22,6 +22,7 @@ Validation Constraints Reference constraints/Range constraints/EqualTo + constraints/NotEqualTo constraints/Date constraints/DateTime diff --git a/reference/constraints/EqualTo.rst b/reference/constraints/EqualTo.rst index 2d13904b540..f698223e721 100644 --- a/reference/constraints/EqualTo.rst +++ b/reference/constraints/EqualTo.rst @@ -5,7 +5,7 @@ EqualTo This constraint is new in version 2.3. Validates that a value is equal to another value, defined in the options. To -force that a value is *not* equal, see :doc:`/reference/constraints/NotEqual`. +force that a value is *not* equal, see :doc:`/reference/constraints/NotEqualTo`. .. caution:: @@ -90,13 +90,7 @@ If you want to ensure that the ``age`` of a ``Person`` class is equal to Options ------- -value -~~~~~ - -**type**: ``mixed`` - -This option is required. It defines the value to compare to. It can be a -string, number or object. +.. include:: /reference/constraints/_comparison-value-option.rst.inc message ~~~~~~~ diff --git a/reference/constraints/NotEqualTo.rst b/reference/constraints/NotEqualTo.rst new file mode 100644 index 00000000000..bea2bf6eb38 --- /dev/null +++ b/reference/constraints/NotEqualTo.rst @@ -0,0 +1,101 @@ +NotEqualTo +========== + +.. versionadded:: 2.3 + This constraint is new in version 2.3. + +Validates that a value is **not** equal to another value, defined in the +options. To force that a value is equal, see +:doc:`/reference/constraints/EqualTo`. + +.. caution:: + + This constraint compares using ``!=``, so ``3`` and ``"3"`` are considered + equal. Use :doc:`/reference/constraints/NotIdenticalTo` to compare with + ``!==``. + ++----------------+-------------------------------------------------------------------------+ +| Applies to | :ref:`property or method` | ++----------------+-------------------------------------------------------------------------+ +| Options | - `value`_ | +| | - `message`_ | ++----------------+-------------------------------------------------------------------------+ +| Class | :class:`Symfony\\Component\\Validator\\Constraints\\NotEqualTo` | ++----------------+-------------------------------------------------------------------------+ +| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\NotEqualToValidator`| ++----------------+-------------------------------------------------------------------------+ + +Basic Usage +----------- + +If you want to ensure that the ``age`` of a ``Person`` class is not equal to +``15``, you could do the following: + +.. configuration-block:: + + .. code-block:: yaml + + # src/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - NotEqualTo: + value: 15 + + .. code-block:: php-annotations + + // src/Acme/SocialBundle/Entity/Person.php + namespace Acme\SocialBundle\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Person + { + /** + * @Assert\NotEqualTo( + * value = 15 + * ) + */ + protected $age; + } + + .. code-block:: xml + + + + + + + + + + + .. code-block:: php + + // src/Acme/SocialBundle/Entity/Person.php + namespace Acme\SocialBundle\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Person + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('age', new Assert\NotEqualTo(array( + 'value' => 15, + ))); + } + } + +Options +------- + +.. include:: /reference/constraints/_comparison-value-option.rst.inc + +message +~~~~~~~ + +**type**: ``string`` **default**: ``This value should not be equal to {{ compared_value }}`` + +This is the message that will be shown if the value is not equal. diff --git a/reference/constraints/_comparison-value-option.rst.inc b/reference/constraints/_comparison-value-option.rst.inc new file mode 100644 index 00000000000..9d799c27dc7 --- /dev/null +++ b/reference/constraints/_comparison-value-option.rst.inc @@ -0,0 +1,7 @@ +value +~~~~~ + +**type**: ``mixed`` + +This option is required. It defines the value to compare to. It can be a +string, number or object. diff --git a/reference/constraints/map.rst.inc b/reference/constraints/map.rst.inc index 69b47c10162..7cb9f0f3b1b 100644 --- a/reference/constraints/map.rst.inc +++ b/reference/constraints/map.rst.inc @@ -30,6 +30,7 @@ Comparison Constraints ~~~~~~~~~~~~~~~~~~~~~~ * :doc:`EqualTo ` +* :doc:`NotEqualTo ` Date Constraints ~~~~~~~~~~~~~~~~ From 372e80095dd61b11ea4ef9cffbe896c92121560f Mon Sep 17 00:00:00 2001 From: WouterJ Date: Fri, 3 May 2013 16:46:40 +0200 Subject: [PATCH 3/8] Added docs for IdenticalTo validator --- reference/constraints.rst | 1 + reference/constraints/IdenticalTo.rst | 101 ++++++++++++++++++++++++++ reference/constraints/map.rst.inc | 1 + 3 files changed, 103 insertions(+) create mode 100644 reference/constraints/IdenticalTo.rst diff --git a/reference/constraints.rst b/reference/constraints.rst index 425248c26c3..55bf6683159 100644 --- a/reference/constraints.rst +++ b/reference/constraints.rst @@ -23,6 +23,7 @@ Validation Constraints Reference constraints/EqualTo constraints/NotEqualTo + constraints/IdenticalTo constraints/Date constraints/DateTime diff --git a/reference/constraints/IdenticalTo.rst b/reference/constraints/IdenticalTo.rst new file mode 100644 index 00000000000..8a4aa080b55 --- /dev/null +++ b/reference/constraints/IdenticalTo.rst @@ -0,0 +1,101 @@ +IdenticalTo +=========== + +.. versionadded:: 2.3 + This constraint is new in version 2.3. + +Validates that a value is identical to another value, defined in the options. +To force that a value is *not* equal, see +:doc:`/reference/constraints/NotIdenticalTo`. + +.. caution:: + + This constraint compares using ``===``, so ``3`` and ``"3"`` are *not* + considered equal. Use :doc:`/reference/constraints/EqualTo` to compare + with ``==``. + ++----------------+--------------------------------------------------------------------------+ +| Applies to | :ref:`property or method` | ++----------------+--------------------------------------------------------------------------+ +| Options | - `value`_ | +| | - `message`_ | ++----------------+--------------------------------------------------------------------------+ +| Class | :class:`Symfony\\Component\\Validator\\Constraints\\IdenticalTo` | ++----------------+--------------------------------------------------------------------------+ +| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\IdenticalToValidator`| ++----------------+--------------------------------------------------------------------------+ + +Basic Usage +----------- + +If you want to ensure that the ``age`` of a ``Person`` class is equal to +``20`` and an integer, you could do the following: + +.. configuration-block:: + + .. code-block:: yaml + + # src/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - IdenticalTo: + value: 20 + + .. code-block:: php-annotations + + // src/Acme/SocialBundle/Entity/Person.php + namespace Acme\SocialBundle\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Person + { + /** + * @Assert\IdenticalTo( + * value = 20 + * ) + */ + protected $age; + } + + .. code-block:: xml + + + + + + + + + + + .. code-block:: php + + // src/Acme/SocialBundle/Entity/Person.php + namespace Acme\SocialBundle\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Person + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('age', new Assert\IdenticalTo(array( + 'value' => 20, + ))); + } + } + +Options +------- + +.. include:: /reference/constraints/_comparison-value-option.rst.inc + +message +~~~~~~~ + +**type**: ``string`` **default**: ``This value should be identical to {{ compared_value_type }} {{ compared_value }}`` + +This is the message that will be shown if the value is not equal. diff --git a/reference/constraints/map.rst.inc b/reference/constraints/map.rst.inc index 7cb9f0f3b1b..5e8f9acfe5a 100644 --- a/reference/constraints/map.rst.inc +++ b/reference/constraints/map.rst.inc @@ -31,6 +31,7 @@ Comparison Constraints * :doc:`EqualTo ` * :doc:`NotEqualTo ` +* :doc:`IdenticalTo ` Date Constraints ~~~~~~~~~~~~~~~~ From f9019350a6603cac669d67aa2f8c855f50c7e82c Mon Sep 17 00:00:00 2001 From: WouterJ Date: Fri, 3 May 2013 16:49:47 +0200 Subject: [PATCH 4/8] Added docs for NotIdenticalTo validator --- reference/constraints.rst | 1 + reference/constraints/NotIdenticalTo.rst | 101 +++++++++++++++++++++++ reference/constraints/map.rst.inc | 1 + 3 files changed, 103 insertions(+) create mode 100644 reference/constraints/NotIdenticalTo.rst diff --git a/reference/constraints.rst b/reference/constraints.rst index 55bf6683159..3e3758eceab 100644 --- a/reference/constraints.rst +++ b/reference/constraints.rst @@ -24,6 +24,7 @@ Validation Constraints Reference constraints/EqualTo constraints/NotEqualTo constraints/IdenticalTo + constraints/NotIdenticalTo constraints/Date constraints/DateTime diff --git a/reference/constraints/NotIdenticalTo.rst b/reference/constraints/NotIdenticalTo.rst new file mode 100644 index 00000000000..2f659cbdbc5 --- /dev/null +++ b/reference/constraints/NotIdenticalTo.rst @@ -0,0 +1,101 @@ +NotIdenticalTo +=========== + +.. versionadded:: 2.3 + This constraint is new in version 2.3. + +Validates that a value is **not** identical to another value, defined in the +options. To force that a value is identical, see +:doc:`/reference/constraints/IdenticalTo`. + +.. caution:: + + This constraint compares using ``!==``, so ``3`` and ``"3"`` are + considered not equal. Use :doc:`/reference/constraints/NotEqualTo` to compare + with ``!=``. + ++----------------+-----------------------------------------------------------------------------+ +| Applies to | :ref:`property or method` | ++----------------+-----------------------------------------------------------------------------+ +| Options | - `value`_ | +| | - `message`_ | ++----------------+-----------------------------------------------------------------------------+ +| Class | :class:`Symfony\\Component\\Validator\\Constraints\\NotIdenticalTo` | ++----------------+-----------------------------------------------------------------------------+ +| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\NotIdenticalToValidator`| ++----------------+-----------------------------------------------------------------------------+ + +Basic Usage +----------- + +If you want to ensure that the ``age`` of a ``Person`` class is *not* equal to +``15`` and *not* an integer, you could do the following: + +.. configuration-block:: + + .. code-block:: yaml + + # src/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - NotIdenticalTo: + value: 15 + + .. code-block:: php-annotations + + // src/Acme/SocialBundle/Entity/Person.php + namespace Acme\SocialBundle\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Person + { + /** + * @Assert\NotIdenticalTo( + * value = 15 + * ) + */ + protected $age; + } + + .. code-block:: xml + + + + + + + + + + + .. code-block:: php + + // src/Acme/SocialBundle/Entity/Person.php + namespace Acme\SocialBundle\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Person + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('age', new Assert\NotIdenticalTo(array( + 'value' => 15, + ))); + } + } + +Options +------- + +.. include:: /reference/constraints/_comparison-value-option.rst.inc + +message +~~~~~~~ + +**type**: ``string`` **default**: ``This value should not be identical to {{ compared_value_type }} {{ compared_value }}`` + +This is the message that will be shown if the value is not equal. diff --git a/reference/constraints/map.rst.inc b/reference/constraints/map.rst.inc index 5e8f9acfe5a..364842a986c 100644 --- a/reference/constraints/map.rst.inc +++ b/reference/constraints/map.rst.inc @@ -32,6 +32,7 @@ Comparison Constraints * :doc:`EqualTo ` * :doc:`NotEqualTo ` * :doc:`IdenticalTo ` +* :doc:`NotIdenticalTo ` Date Constraints ~~~~~~~~~~~~~~~~ From fef0195425069f6875b014ca59237d1764fbd41e Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 4 May 2013 12:00:49 +0200 Subject: [PATCH 5/8] Added docs for LessThan validator --- reference/constraints.rst | 1 + reference/constraints/LessThan.rst | 96 ++++++++++++++++++++++++++++++ reference/constraints/map.rst.inc | 1 + 3 files changed, 98 insertions(+) create mode 100644 reference/constraints/LessThan.rst diff --git a/reference/constraints.rst b/reference/constraints.rst index 3e3758eceab..9038f2da7c1 100644 --- a/reference/constraints.rst +++ b/reference/constraints.rst @@ -25,6 +25,7 @@ Validation Constraints Reference constraints/NotEqualTo constraints/IdenticalTo constraints/NotIdenticalTo + constraints/LessThan constraints/Date constraints/DateTime diff --git a/reference/constraints/LessThan.rst b/reference/constraints/LessThan.rst new file mode 100644 index 00000000000..e872764deeb --- /dev/null +++ b/reference/constraints/LessThan.rst @@ -0,0 +1,96 @@ +LessThan +======== + +.. versionadded:: 2.3 + This constraint is new in version 2.3. + +Validates that a value is less than another value, defined in the options. To +force that a value is less than or equal to another value, see +:doc:`/reference/constraints/LessThanOrLessThan`. To force a value is greater +than another value, see :doc:`/reference/constraints/GreaterThan`. + ++----------------+-----------------------------------------------------------------------+ +| Applies to | :ref:`property or method` | ++----------------+-----------------------------------------------------------------------+ +| Options | - `value`_ | +| | - `message`_ | ++----------------+-----------------------------------------------------------------------+ +| Class | :class:`Symfony\\Component\\Validator\\Constraints\\LessThan` | ++----------------+-----------------------------------------------------------------------+ +| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\LessThanValidator` | ++----------------+-----------------------------------------------------------------------+ + +Basic Usage +----------- + +If you want to ensure that the ``age`` of a ``Person`` class is less than +``80``, you could do the following: + +.. configuration-block:: + + .. code-block:: yaml + + # src/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - LessThan: + value: 80 + + .. code-block:: php-annotations + + // src/Acme/SocialBundle/Entity/Person.php + namespace Acme\SocialBundle\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Person + { + /** + * @Assert\LessThan( + * value = 80 + * ) + */ + protected $age; + } + + .. code-block:: xml + + + + + + + + + + + .. code-block:: php + + // src/Acme/SocialBundle/Entity/Person.php + namespace Acme\SocialBundle\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Person + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('age', new Assert\LessThan(array( + 'value' => 80, + ))); + } + } + +Options +------- + +.. include:: /reference/constraints/_comparison-value-option.rst.inc + +message +~~~~~~~ + +**type**: ``string`` **default**: ``This value should be less than {{ compared_value }}`` + +This is the message that will be shown if the value is not equal. diff --git a/reference/constraints/map.rst.inc b/reference/constraints/map.rst.inc index 364842a986c..c142e34532b 100644 --- a/reference/constraints/map.rst.inc +++ b/reference/constraints/map.rst.inc @@ -33,6 +33,7 @@ Comparison Constraints * :doc:`NotEqualTo ` * :doc:`IdenticalTo ` * :doc:`NotIdenticalTo ` +* :doc:`LessThan ` Date Constraints ~~~~~~~~~~~~~~~~ From 030d05cb388be24ae289cd8866df91142dbbd29a Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 4 May 2013 12:04:10 +0200 Subject: [PATCH 6/8] Added docs for LessThanOrEqual validator --- reference/constraints.rst | 1 + reference/constraints/LessThan.rst | 18 ++--- reference/constraints/LessThanOrEqual.rst | 95 +++++++++++++++++++++++ reference/constraints/map.rst.inc | 1 + 4 files changed, 106 insertions(+), 9 deletions(-) create mode 100644 reference/constraints/LessThanOrEqual.rst diff --git a/reference/constraints.rst b/reference/constraints.rst index 9038f2da7c1..862e1babef0 100644 --- a/reference/constraints.rst +++ b/reference/constraints.rst @@ -26,6 +26,7 @@ Validation Constraints Reference constraints/IdenticalTo constraints/NotIdenticalTo constraints/LessThan + constraints/LessThanOrEqual constraints/Date constraints/DateTime diff --git a/reference/constraints/LessThan.rst b/reference/constraints/LessThan.rst index e872764deeb..eef2393d2eb 100644 --- a/reference/constraints/LessThan.rst +++ b/reference/constraints/LessThan.rst @@ -6,19 +6,19 @@ LessThan Validates that a value is less than another value, defined in the options. To force that a value is less than or equal to another value, see -:doc:`/reference/constraints/LessThanOrLessThan`. To force a value is greater +:doc:`/reference/constraints/LessThanOrEqual`. To force a value is greater than another value, see :doc:`/reference/constraints/GreaterThan`. -+----------------+-----------------------------------------------------------------------+ -| Applies to | :ref:`property or method` | -+----------------+-----------------------------------------------------------------------+ -| Options | - `value`_ | -| | - `message`_ | -+----------------+-----------------------------------------------------------------------+ ++----------------+------------------------------------------------------------------------+ +| Applies to | :ref:`property or method` | ++----------------+------------------------------------------------------------------------+ +| Options | - `value`_ | +| | - `message`_ | ++----------------+------------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Validator\\Constraints\\LessThan` | -+----------------+-----------------------------------------------------------------------+ ++----------------+------------------------------------------------------------------------+ | Validator | :class:`Symfony\\Component\\Validator\\Constraints\\LessThanValidator` | -+----------------+-----------------------------------------------------------------------+ ++----------------+------------------------------------------------------------------------+ Basic Usage ----------- diff --git a/reference/constraints/LessThanOrEqual.rst b/reference/constraints/LessThanOrEqual.rst new file mode 100644 index 00000000000..0f4ea99c37c --- /dev/null +++ b/reference/constraints/LessThanOrEqual.rst @@ -0,0 +1,95 @@ +LessThanOrEqual +=============== + +.. versionadded:: 2.3 + This constraint is new in version 2.3. + +Validates that a value is less than or equal to another value, defined in the +options. To force that a value is less than another value, see +:doc:`/reference/constraints/LessThan`. + ++----------------+-------------------------------------------------------------------------------+ +| Applies to | :ref:`property or method` | ++----------------+-------------------------------------------------------------------------------+ +| Options | - `value`_ | +| | - `message`_ | ++----------------+-------------------------------------------------------------------------------+ +| Class | :class:`Symfony\\Component\\Validator\\Constraints\\LessThanOrEqual` | ++----------------+-------------------------------------------------------------------------------+ +| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\LessThanOrEqualValidator` | ++----------------+-------------------------------------------------------------------------------+ + +Basic Usage +----------- + +If you want to ensure that the ``age`` of a ``Person`` class is less than or +equal to ``80``, you could do the following: + +.. configuration-block:: + + .. code-block:: yaml + + # src/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - LessThanOrEqual: + value: 80 + + .. code-block:: php-annotations + + // src/Acme/SocialBundle/Entity/Person.php + namespace Acme\SocialBundle\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Person + { + /** + * @Assert\LessThanOrEqual( + * value = 80 + * ) + */ + protected $age; + } + + .. code-block:: xml + + + + + + + + + + + .. code-block:: php + + // src/Acme/SocialBundle/Entity/Person.php + namespace Acme\SocialBundle\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Person + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('age', new Assert\LessThanOrEqual(array( + 'value' => 80, + ))); + } + } + +Options +------- + +.. include:: /reference/constraints/_comparison-value-option.rst.inc + +message +~~~~~~~ + +**type**: ``string`` **default**: ``This value should be less than or equal to {{ compared_value }}`` + +This is the message that will be shown if the value is not equal. diff --git a/reference/constraints/map.rst.inc b/reference/constraints/map.rst.inc index c142e34532b..a184f67a181 100644 --- a/reference/constraints/map.rst.inc +++ b/reference/constraints/map.rst.inc @@ -34,6 +34,7 @@ Comparison Constraints * :doc:`IdenticalTo ` * :doc:`NotIdenticalTo ` * :doc:`LessThan ` +* :doc:`LessThanOrEqual ` Date Constraints ~~~~~~~~~~~~~~~~ From 956f5fc1b506123e27925aa606c661210410ba8f Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 4 May 2013 12:06:17 +0200 Subject: [PATCH 7/8] Added docs for GreaterThan validator --- reference/constraints.rst | 1 + reference/constraints/GreaterThan.rst | 96 +++++++++++++++++++++++++++ reference/constraints/map.rst.inc | 1 + 3 files changed, 98 insertions(+) create mode 100644 reference/constraints/GreaterThan.rst diff --git a/reference/constraints.rst b/reference/constraints.rst index 862e1babef0..bc4770a8c3c 100644 --- a/reference/constraints.rst +++ b/reference/constraints.rst @@ -27,6 +27,7 @@ Validation Constraints Reference constraints/NotIdenticalTo constraints/LessThan constraints/LessThanOrEqual + constraints/GreaterThan constraints/Date constraints/DateTime diff --git a/reference/constraints/GreaterThan.rst b/reference/constraints/GreaterThan.rst new file mode 100644 index 00000000000..3d77bb1319a --- /dev/null +++ b/reference/constraints/GreaterThan.rst @@ -0,0 +1,96 @@ +GreaterThan +=========== + +.. versionadded:: 2.3 + This constraint is new in version 2.3. + +Validates that a value is greater than another value, defined in the options. To +force that a value is greater than or equal to another value, see +:doc:`/reference/constraints/GreaterThanOrEqual`. To force a value is less +than another value, see :doc:`/reference/constraints/LessThan`. + ++----------------+---------------------------------------------------------------------------+ +| Applies to | :ref:`property or method` | ++----------------+---------------------------------------------------------------------------+ +| Options | - `value`_ | +| | - `message`_ | ++----------------+---------------------------------------------------------------------------+ +| Class | :class:`Symfony\\Component\\Validator\\Constraints\\GreaterThan` | ++----------------+---------------------------------------------------------------------------+ +| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\GreaterThanValidator` | ++----------------+---------------------------------------------------------------------------+ + +Basic Usage +----------- + +If you want to ensure that the ``age`` of a ``Person`` class is greater than +``18``, you could do the following: + +.. configuration-block:: + + .. code-block:: yaml + + # src/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - GreaterThan: + value: 18 + + .. code-block:: php-annotations + + // src/Acme/SocialBundle/Entity/Person.php + namespace Acme\SocialBundle\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Person + { + /** + * @Assert\GreaterThan( + * value = 18 + * ) + */ + protected $age; + } + + .. code-block:: xml + + + + + + + + + + + .. code-block:: php + + // src/Acme/SocialBundle/Entity/Person.php + namespace Acme\SocialBundle\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Person + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('age', new Assert\GreaterThan(array( + 'value' => 18, + ))); + } + } + +Options +------- + +.. include:: /reference/constraints/_comparison-value-option.rst.inc + +message +~~~~~~~ + +**type**: ``string`` **default**: ``This value should be greater than {{ compared_value }}`` + +This is the message that will be shown if the value is not equal. diff --git a/reference/constraints/map.rst.inc b/reference/constraints/map.rst.inc index a184f67a181..a82d87c4ddc 100644 --- a/reference/constraints/map.rst.inc +++ b/reference/constraints/map.rst.inc @@ -35,6 +35,7 @@ Comparison Constraints * :doc:`NotIdenticalTo ` * :doc:`LessThan ` * :doc:`LessThanOrEqual ` +* :doc:`GreaterThan ` Date Constraints ~~~~~~~~~~~~~~~~ From 6f261f4e62d0c10234dac176d03f764ae6ff6a45 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 4 May 2013 12:09:17 +0200 Subject: [PATCH 8/8] Added docs for GreaterThanOrEqual validator --- reference/constraints.rst | 1 + reference/constraints/GreaterThanOrEqual.rst | 95 ++++++++++++++++++++ reference/constraints/map.rst.inc | 1 + 3 files changed, 97 insertions(+) create mode 100644 reference/constraints/GreaterThanOrEqual.rst diff --git a/reference/constraints.rst b/reference/constraints.rst index bc4770a8c3c..7c6879f664e 100644 --- a/reference/constraints.rst +++ b/reference/constraints.rst @@ -28,6 +28,7 @@ Validation Constraints Reference constraints/LessThan constraints/LessThanOrEqual constraints/GreaterThan + constraints/GreaterThanOrEqual constraints/Date constraints/DateTime diff --git a/reference/constraints/GreaterThanOrEqual.rst b/reference/constraints/GreaterThanOrEqual.rst new file mode 100644 index 00000000000..536feb54de2 --- /dev/null +++ b/reference/constraints/GreaterThanOrEqual.rst @@ -0,0 +1,95 @@ +GreaterThanOrEqual +=========== + +.. versionadded:: 2.3 + This constraint is new in version 2.3. + +Validates that a value is greater than or equal to another value, defined in +the options. To force that a value is greater than another value, see +:doc:`/reference/constraints/GreaterThan`. + ++----------------+----------------------------------------------------------------------------------+ +| Applies to | :ref:`property or method` | ++----------------+----------------------------------------------------------------------------------+ +| Options | - `value`_ | +| | - `message`_ | ++----------------+----------------------------------------------------------------------------------+ +| Class | :class:`Symfony\\Component\\Validator\\Constraints\\GreaterThanOrEqual` | ++----------------+----------------------------------------------------------------------------------+ +| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\GreaterThanOrEqualValidator` | ++----------------+----------------------------------------------------------------------------------+ + +Basic Usage +----------- + +If you want to ensure that the ``age`` of a ``Person`` class is greater than +or equal to ``18``, you could do the following: + +.. configuration-block:: + + .. code-block:: yaml + + # src/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - GreaterThanOrEqual: + value: 18 + + .. code-block:: php-annotations + + // src/Acme/SocialBundle/Entity/Person.php + namespace Acme\SocialBundle\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Person + { + /** + * @Assert\GreaterThanOrEqual( + * value = 18 + * ) + */ + protected $age; + } + + .. code-block:: xml + + + + + + + + + + + .. code-block:: php + + // src/Acme/SocialBundle/Entity/Person.php + namespace Acme\SocialBundle\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Person + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('age', new Assert\GreaterThanOrEqual(array( + 'value' => 18, + ))); + } + } + +Options +------- + +.. include:: /reference/constraints/_comparison-value-option.rst.inc + +message +~~~~~~~ + +**type**: ``string`` **default**: ``This value should be greater than or equal to {{ compared_value }}`` + +This is the message that will be shown if the value is not equal. diff --git a/reference/constraints/map.rst.inc b/reference/constraints/map.rst.inc index a82d87c4ddc..1933cf5d950 100644 --- a/reference/constraints/map.rst.inc +++ b/reference/constraints/map.rst.inc @@ -36,6 +36,7 @@ Comparison Constraints * :doc:`LessThan ` * :doc:`LessThanOrEqual ` * :doc:`GreaterThan ` +* :doc:`GreaterThanOrEqual ` Date Constraints ~~~~~~~~~~~~~~~~