From 7aba65fbc315b3e011e97efde0ed3df4f2f9d705 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Mon, 18 Aug 2014 13:40:46 +0200 Subject: [PATCH 1/6] Added information about the new date handling in the comparison constraints and Range Conflicts: reference/constraints/GreaterThan.rst reference/constraints/GreaterThanOrEqual.rst reference/constraints/LessThan.rst reference/constraints/LessThanOrEqual.rst --- reference/constraints/GreaterThan.rst | 217 ++++++++++++++++--- reference/constraints/GreaterThanOrEqual.rst | 217 ++++++++++++++++--- reference/constraints/LessThan.rst | 202 +++++++++++++++-- reference/constraints/LessThanOrEqual.rst | 210 +++++++++++++++--- reference/constraints/Range.rst | 198 +++++++++++++++++ 5 files changed, 934 insertions(+), 110 deletions(-) diff --git a/reference/constraints/GreaterThan.rst b/reference/constraints/GreaterThan.rst index b1066c6b1f4..a8638acf025 100644 --- a/reference/constraints/GreaterThan.rst +++ b/reference/constraints/GreaterThan.rst @@ -4,8 +4,8 @@ GreaterThan .. versionadded:: 2.3 The ``GreaterThan`` constraint was introduced in Symfony 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 +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`. @@ -14,7 +14,6 @@ than another value, see :doc:`/reference/constraints/LessThan`. +----------------+---------------------------------------------------------------------------+ | Options | - `value`_ | | | - `message`_ | -| | - `payload`_ | +----------------+---------------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Validator\\Constraints\\GreaterThan` | +----------------+---------------------------------------------------------------------------+ @@ -24,11 +23,20 @@ than another value, see :doc:`/reference/constraints/LessThan`. Basic Usage ----------- -If you want to ensure that the ``age`` of a ``Person`` class is greater -than ``18``, you could do the following: +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 @@ -46,31 +54,16 @@ than ``18``, you could do the following: protected $age; } - .. code-block:: yaml - - # src/Acme/SocialBundle/Resources/config/validation.yml - Acme\SocialBundle\Entity\Person: - properties: - age: - - GreaterThan: - value: 18 - .. code-block:: xml - - - - - - - - - - - + + + + + + + .. code-block:: php @@ -90,6 +83,170 @@ than ``18``, you could do the following: } } +Comparing Dates +--------------- + +This constraint can be used to compare ``DateTime`` objects against any date +string `accepted by the DateTime constructor`_. For example, you could check +that a date must at least be the next day: + +.. configuration-block:: + + .. code-block:: yaml + + # src/OrderBundle/Resources/config/validation.yml + Acme\OrderBundle\Entity\Order: + properties: + deliveryDate: + - GreaterThan: today + + .. code-block:: php-annotations + + // src/Acme/SocialBundle/Entity/Order.php + namespace Acme\OrderBundle\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Order + { + /** + * @Assert\GreaterThan("today") + */ + protected $deliveryDate; + } + + .. code-block:: xml + + + + + today + + + + .. code-block:: php + + // src/Acme/OrderBundle/Entity/Order.php + namespace Acme\OrderBundle\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Order + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('deliveryDate', new Assert\GreaterThan('today')); + } + } + +Be aware that PHP will use the server's configured timezone to interpret these +dates. If you want to fix the timezone, append it to the date string: + +.. configuration-block:: + + .. code-block:: yaml + + # src/OrderBundle/Resources/config/validation.yml + Acme\OrderBundle\Entity\Order: + properties: + deliveryDate: + - GreaterThan: today UTC + + .. code-block:: php-annotations + + // src/Acme/SocialBundle/Entity/Order.php + namespace Acme\OrderBundle\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Order + { + /** + * @Assert\GreaterThan("today UTC") + */ + protected $deliveryDate; + } + + .. code-block:: xml + + + + + today UTC + + + + .. code-block:: php + + // src/Acme/OrderBundle/Entity/Order.php + namespace Acme\OrderBundle\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Order + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('deliveryDate', new Assert\GreaterThan('today UTC')); + } + } + +The ``DateTime`` class also accepts relative dates or times. For example, you +can check that the above delivery date starts at least five hours after the +current time: + +.. configuration-block:: + + .. code-block:: yaml + + # src/OrderBundle/Resources/config/validation.yml + Acme\OrderBundle\Entity\Order: + properties: + deliveryDate: + - GreaterThan: +5 hours + + .. code-block:: php-annotations + + // src/Acme/SocialBundle/Entity/Order.php + namespace Acme\OrderBundle\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Order + { + /** + * @Assert\GreaterThan("+5 hours") + */ + protected $deliveryDate; + } + + .. code-block:: xml + + + + + +5 hours + + + + .. code-block:: php + + // src/Acme/OrderBundle/Entity/Order.php + namespace Acme\OrderBundle\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Order + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('deliveryDate', new Assert\GreaterThan('+5 hours')); + } + } + Options ------- @@ -100,7 +257,7 @@ 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 greater than -the comparison value. +This is the message that will be shown if the value is not greater than the +comparison value. -.. include:: /reference/constraints/_payload-option.rst.inc +.. _`accepted by the DateTime constructor`: http://www.php.net/manual/en/datetime.formats.php diff --git a/reference/constraints/GreaterThanOrEqual.rst b/reference/constraints/GreaterThanOrEqual.rst index cc868390490..bdc6f9e36cf 100644 --- a/reference/constraints/GreaterThanOrEqual.rst +++ b/reference/constraints/GreaterThanOrEqual.rst @@ -4,8 +4,8 @@ GreaterThanOrEqual .. versionadded:: 2.3 The ``GreaterThanOrEqual`` constraint was introduced in Symfony 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 +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`. +----------------+----------------------------------------------------------------------------------+ @@ -13,7 +13,6 @@ in the options. To force that a value is greater than another value, see +----------------+----------------------------------------------------------------------------------+ | Options | - `value`_ | | | - `message`_ | -| | - `payload`_ | +----------------+----------------------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Validator\\Constraints\\GreaterThanOrEqual` | +----------------+----------------------------------------------------------------------------------+ @@ -23,11 +22,20 @@ in the options. To force that a value is greater than another value, see 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: +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 @@ -45,31 +53,16 @@ than or equal to ``18``, you could do the following: protected $age; } - .. code-block:: yaml - - # src/Acme/SocialBundle/Resources/config/validation.yml - Acme\SocialBundle\Entity\Person: - properties: - age: - - GreaterThanOrEqual: - value: 18 - .. code-block:: xml - - - - - - - - - - - + + + + + + + .. code-block:: php @@ -89,6 +82,170 @@ than or equal to ``18``, you could do the following: } } +Comparing Dates +--------------- + +This constraint can be used to compare ``DateTime`` objects against any date +string `accepted by the DateTime constructor`_. For example, you could check +that a date must at least be the current day: + +.. configuration-block:: + + .. code-block:: yaml + + # src/OrderBundle/Resources/config/validation.yml + Acme\OrderBundle\Entity\Order: + properties: + deliveryDate: + - GreaterThanOrEqual: today + + .. code-block:: php-annotations + + // src/Acme/SocialBundle/Entity/Order.php + namespace Acme\OrderBundle\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Order + { + /** + * @Assert\GreaterThanOrEqual("today") + */ + protected $deliveryDate; + } + + .. code-block:: xml + + + + + today + + + + .. code-block:: php + + // src/Acme/OrderBundle/Entity/Order.php + namespace Acme\OrderBundle\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Order + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('deliveryDate', new Assert\GreaterThanOrEqual('today')); + } + } + +Be aware that PHP will use the server's configured timezone to interpret these +dates. If you want to fix the timezone, append it to the date string: + +.. configuration-block:: + + .. code-block:: yaml + + # src/OrderBundle/Resources/config/validation.yml + Acme\OrderBundle\Entity\Order: + properties: + deliveryDate: + - GreaterThanOrEqual: today UTC + + .. code-block:: php-annotations + + // src/Acme/SocialBundle/Entity/Order.php + namespace Acme\OrderBundle\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Order + { + /** + * @Assert\GreaterThanOrEqual("today UTC") + */ + protected $deliveryDate; + } + + .. code-block:: xml + + + + + today UTC + + + + .. code-block:: php + + // src/Acme/OrderBundle/Entity/Order.php + namespace Acme\OrderBundle\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Order + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('deliveryDate', new Assert\GreaterThanOrEqual('today UTC')); + } + } + +The ``DateTime`` class also accepts relative dates or times. For example, you +can check that the above delivery date starts at least five hours after the +current time: + +.. configuration-block:: + + .. code-block:: yaml + + # src/OrderBundle/Resources/config/validation.yml + Acme\OrderBundle\Entity\Order: + properties: + deliveryDate: + - GreaterThanOrEqual: +5 hours + + .. code-block:: php-annotations + + // src/Acme/SocialBundle/Entity/Order.php + namespace Acme\OrderBundle\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Order + { + /** + * @Assert\GreaterThanOrEqual("+5 hours") + */ + protected $deliveryDate; + } + + .. code-block:: xml + + + + + +5 hours + + + + .. code-block:: php + + // src/Acme/OrderBundle/Entity/Order.php + namespace Acme\OrderBundle\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Order + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('deliveryDate', new Assert\GreaterThanOrEqual('+5 hours')); + } + } + Options ------- @@ -99,7 +256,7 @@ 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 greater than -or equal to the comparison value. +This is the message that will be shown if the value is not greater than or equal +to the comparison value. -.. include:: /reference/constraints/_payload-option.rst.inc +.. _`accepted by the DateTime constructor`: http://www.php.net/manual/en/datetime.formats.php diff --git a/reference/constraints/LessThan.rst b/reference/constraints/LessThan.rst index d14e289fd0c..09c5f93ef40 100644 --- a/reference/constraints/LessThan.rst +++ b/reference/constraints/LessThan.rst @@ -4,8 +4,8 @@ LessThan .. versionadded:: 2.3 The ``LessThan`` constraint was introduced in Symfony 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 +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/LessThanOrEqual`. To force a value is greater than another value, see :doc:`/reference/constraints/GreaterThan`. @@ -14,7 +14,6 @@ than another value, see :doc:`/reference/constraints/GreaterThan`. +----------------+------------------------------------------------------------------------+ | Options | - `value`_ | | | - `message`_ | -| | - `payload`_ | +----------------+------------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Validator\\Constraints\\LessThan` | +----------------+------------------------------------------------------------------------+ @@ -29,6 +28,15 @@ If you want to ensure that the ``age`` of a ``Person`` class is less than .. 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 @@ -46,31 +54,75 @@ If you want to ensure that the ``age`` of a ``Person`` class is less than 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, + ))); + } + } + +Comparing Dates +--------------- + +This constraint can be used to compare ``DateTime`` objects against any date +string `accepted by the DateTime constructor`_. For example, you could check +that a date must be in the past like this: + +.. configuration-block:: + .. code-block:: yaml - # src/Acme/SocialBundle/Resources/config/validation.yml + # src/SocialBundle/Resources/config/validation.yml Acme\SocialBundle\Entity\Person: properties: age: - - LessThan: - value: 80 + - LessThan: today + + .. 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("today") + */ + protected $age; + } .. code-block:: xml - - - - - - - - - - - + + + today + + .. code-block:: php @@ -84,9 +136,113 @@ If you want to ensure that the ``age`` of a ``Person`` class is less than { public static function loadValidatorMetadata(ClassMetadata $metadata) { - $metadata->addPropertyConstraint('age', new Assert\LessThan(array( - 'value' => 80, - ))); + $metadata->addPropertyConstraint('age', new Assert\LessThan('today')); + } + } + +Be aware that PHP will use the server's configured timezone to interpret these +dates. If you want to fix the timezone, append it to the date string: + +.. configuration-block:: + + .. code-block:: yaml + + # src/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - LessThan: today UTC + + .. 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("today UTC") + */ + protected $age; + } + + .. code-block:: xml + + + + + today UTC + + + + .. 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('today UTC')); + } + } + +The ``DateTime`` class also accepts relative dates or times. For example, you +can check that a person must be at least 18 years old like this: + +.. configuration-block:: + + .. code-block:: yaml + + # src/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - LessThan: -18 years + + .. 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("-18 years") + */ + protected $age; + } + + .. code-block:: xml + + + + + -18 years + + + + .. 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('-18 years')); } } @@ -103,4 +259,4 @@ message This is the message that will be shown if the value is not less than the comparison value. -.. include:: /reference/constraints/_payload-option.rst.inc +.. _`accepted by the DateTime constructor`: http://www.php.net/manual/en/datetime.formats.php diff --git a/reference/constraints/LessThanOrEqual.rst b/reference/constraints/LessThanOrEqual.rst index c75266bbc52..61261fbe571 100644 --- a/reference/constraints/LessThanOrEqual.rst +++ b/reference/constraints/LessThanOrEqual.rst @@ -4,8 +4,8 @@ LessThanOrEqual .. versionadded:: 2.3 The ``LessThanOrEqual`` constraint was introduced in Symfony 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 +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`. +----------------+-------------------------------------------------------------------------------+ @@ -13,7 +13,6 @@ the options. To force that a value is less than another value, see +----------------+-------------------------------------------------------------------------------+ | Options | - `value`_ | | | - `message`_ | -| | - `payload`_ | +----------------+-------------------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Validator\\Constraints\\LessThanOrEqual` | +----------------+-------------------------------------------------------------------------------+ @@ -23,11 +22,20 @@ the options. To force that a value is less than another value, see 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: +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 @@ -45,31 +53,75 @@ or equal to ``80``, you could do the following: 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, + ))); + } + } + +Comparing Dates +--------------- + +This constraint can be used to compare ``DateTime`` objects against any date +string `accepted by the DateTime constructor`_. For example, you could check +that a date must be today or in the past like this: + +.. configuration-block:: + .. code-block:: yaml - # src/Acme/SocialBundle/Resources/config/validation.yml + # src/SocialBundle/Resources/config/validation.yml Acme\SocialBundle\Entity\Person: properties: age: - - LessThanOrEqual: - value: 80 + - LessThanOrEqual: today + + .. 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("today") + */ + protected $age; + } .. code-block:: xml - - - - - - - - - - - + + + today + + .. code-block:: php @@ -83,9 +135,113 @@ or equal to ``80``, you could do the following: { public static function loadValidatorMetadata(ClassMetadata $metadata) { - $metadata->addPropertyConstraint('age', new Assert\LessThanOrEqual(array( - 'value' => 80, - ))); + $metadata->addPropertyConstraint('age', new Assert\LessThanOrEqual('today')); + } + } + +Be aware that PHP will use the server's configured timezone to interpret these +dates. If you want to fix the timezone, append it to the date string: + +.. configuration-block:: + + .. code-block:: yaml + + # src/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - LessThanOrEqual: today UTC + + .. 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("today UTC") + */ + protected $age; + } + + .. code-block:: xml + + + + + today UTC + + + + .. 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('today UTC')); + } + } + +The ``DateTime`` class also accepts relative dates or times. For example, you +can check that a person must be at least 18 years old like this: + +.. configuration-block:: + + .. code-block:: yaml + + # src/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - LessThanOrEqual: -18 years + + .. 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("-18 years") + */ + protected $age; + } + + .. code-block:: xml + + + + + -18 years + + + + .. 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('-18 years')); } } @@ -99,7 +255,7 @@ 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 less than or -equal to the comparison value. +This is the message that will be shown if the value is not less than or equal +to the comparison value. -.. include:: /reference/constraints/_payload-option.rst.inc +.. _`accepted by the DateTime constructor`: http://www.php.net/manual/en/datetime.formats.php diff --git a/reference/constraints/Range.rst b/reference/constraints/Range.rst index b588cc31cca..6009adf7a55 100644 --- a/reference/constraints/Range.rst +++ b/reference/constraints/Range.rst @@ -99,6 +99,203 @@ you might add the following: } } +Date Ranges +----------- + +This constraint can be used to compare ``DateTime`` objects against date ranges. +The minimum and maximum date of the range should be given as any date string +`accepted by the DateTime constructor`_. For example, you could check that a +date must lie within the current year like this: + +.. configuration-block:: + + .. code-block:: yaml + + # src/EventBundle/Resources/config/validation.yml + Acme\EventBundle\Entity\Event: + properties: + startDate: + - Range: + min: first day of January + max: first day of January next year + + .. code-block:: php-annotations + + // src/Acme/SocialBundle/Entity/Event.php + namespace Acme\EventBundle\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Event + { + /** + * @Assert\Range( + * min = "first day of January", + * max = "first day of January next year" + * ) + */ + protected $startDate; + } + + .. code-block:: xml + + + + + + + + + + + + .. code-block:: php + + // src/Acme/EventBundle/Entity/Person.php + namespace Acme\EventBundle\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Event + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('startDate', new Assert\Range(array( + 'min' => 'first day of January', + 'max' => 'first day of January next year', + ))); + } + } + +Be aware that PHP will use the server's configured timezone to interpret these +dates. If you want to fix the timezone, append it to the date string: + +.. configuration-block:: + + .. code-block:: yaml + + # src/EventBundle/Resources/config/validation.yml + Acme\EventBundle\Entity\Event: + properties: + startDate: + - Range: + min: first day of January UTC + max: first day of January next year UTC + + .. code-block:: php-annotations + + // src/Acme/SocialBundle/Entity/Event.php + namespace Acme\EventBundle\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Event + { + /** + * @Assert\Range( + * min = "first day of January UTC", + * max = "first day of January next year UTC" + * ) + */ + protected $startDate; + } + + .. code-block:: xml + + + + + + + + + + + + .. code-block:: php + + // src/Acme/EventBundle/Entity/Person.php + namespace Acme\EventBundle\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Event + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('startDate', new Assert\Range(array( + 'min' => 'first day of January UTC', + 'max' => 'first day of January next year UTC', + ))); + } + } + +The ``DateTime`` class also accepts relative dates or times. For example, you +can check that a delivery date starts within the next five hours like this: + +.. configuration-block:: + + .. code-block:: yaml + + # src/OrderBundle/Resources/config/validation.yml + Acme\OrderBundle\Entity\Order: + properties: + deliveryDate: + - Range: + min: now + max: +5 hours + + .. code-block:: php-annotations + + // src/Acme/SocialBundle/Entity/Order.php + namespace Acme\OrderBundle\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Order + { + /** + * @Assert\Range( + * min = "now", + * max = "+5 hours" + * ) + */ + protected $deliveryDate; + } + + .. code-block:: xml + + + + + + + + + + + + .. code-block:: php + + // src/Acme/OrderBundle/Entity/Order.php + namespace Acme\OrderBundle\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Order + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('deliveryDate', new Assert\Range(array( + 'min' => 'now', + 'max' => '+5 hours', + ))); + } + } + Options ------- @@ -145,3 +342,4 @@ the `is_numeric`_ PHP function). .. include:: /reference/constraints/_payload-option.rst.inc .. _`is_numeric`: http://www.php.net/manual/en/function.is-numeric.php +.. _`accepted by the DateTime constructor`: http://www.php.net/manual/en/datetime.formats.php From 5a6533b57b667468567be06c31d91d333a5f5a66 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 11 Jun 2015 14:56:52 +0200 Subject: [PATCH 2/6] Finished the documentation of the new data comparison validators --- reference/constraints/GreaterThan.rst | 83 ++++++++++++------- reference/constraints/GreaterThanOrEqual.rst | 71 +++++++++++----- reference/constraints/LessThan.rst | 87 +++++++++++++------- reference/constraints/LessThanOrEqual.rst | 71 +++++++++++----- reference/constraints/Range.rst | 68 +++++++++------ 5 files changed, 253 insertions(+), 127 deletions(-) diff --git a/reference/constraints/GreaterThan.rst b/reference/constraints/GreaterThan.rst index a8638acf025..8f7783b1937 100644 --- a/reference/constraints/GreaterThan.rst +++ b/reference/constraints/GreaterThan.rst @@ -57,13 +57,19 @@ If you want to ensure that the ``age`` of a ``Person`` class is greater than .. code-block:: xml - - - - - - - + + + + + + + + + + + .. code-block:: php @@ -86,6 +92,9 @@ If you want to ensure that the ``age`` of a ``Person`` class is greater than Comparing Dates --------------- +.. versionadded:: 2.6 + The feature to compare dates was added in Symfony 2.6. + This constraint can be used to compare ``DateTime`` objects against any date string `accepted by the DateTime constructor`_. For example, you could check that a date must at least be the next day: @@ -94,7 +103,7 @@ that a date must at least be the next day: .. code-block:: yaml - # src/OrderBundle/Resources/config/validation.yml + # src/Acme/OrderBundle/Resources/config/validation.yml Acme\OrderBundle\Entity\Order: properties: deliveryDate: @@ -102,7 +111,7 @@ that a date must at least be the next day: .. code-block:: php-annotations - // src/Acme/SocialBundle/Entity/Order.php + // src/Acme/OrderBundle/Entity/Order.php namespace Acme\OrderBundle\Entity; use Symfony\Component\Validator\Constraints as Assert; @@ -118,11 +127,17 @@ that a date must at least be the next day: .. code-block:: xml - - - today - - + + + + + + today + + + .. code-block:: php @@ -147,7 +162,7 @@ dates. If you want to fix the timezone, append it to the date string: .. code-block:: yaml - # src/OrderBundle/Resources/config/validation.yml + # src/Acme/OrderBundle/Resources/config/validation.yml Acme\OrderBundle\Entity\Order: properties: deliveryDate: @@ -155,7 +170,7 @@ dates. If you want to fix the timezone, append it to the date string: .. code-block:: php-annotations - // src/Acme/SocialBundle/Entity/Order.php + // src/Acme/OrderBundle/Entity/Order.php namespace Acme\OrderBundle\Entity; use Symfony\Component\Validator\Constraints as Assert; @@ -171,11 +186,17 @@ dates. If you want to fix the timezone, append it to the date string: .. code-block:: xml - - - today UTC - - + + + + + + today UTC + + + .. code-block:: php @@ -201,7 +222,7 @@ current time: .. code-block:: yaml - # src/OrderBundle/Resources/config/validation.yml + # src/Acme/OrderBundle/Resources/config/validation.yml Acme\OrderBundle\Entity\Order: properties: deliveryDate: @@ -209,7 +230,7 @@ current time: .. code-block:: php-annotations - // src/Acme/SocialBundle/Entity/Order.php + // src/Acme/OrderBundle/Entity/Order.php namespace Acme\OrderBundle\Entity; use Symfony\Component\Validator\Constraints as Assert; @@ -225,11 +246,17 @@ current time: .. code-block:: xml - - - +5 hours - - + + + + + + +5 hours + + + .. code-block:: php diff --git a/reference/constraints/GreaterThanOrEqual.rst b/reference/constraints/GreaterThanOrEqual.rst index bdc6f9e36cf..e5abbfb239f 100644 --- a/reference/constraints/GreaterThanOrEqual.rst +++ b/reference/constraints/GreaterThanOrEqual.rst @@ -56,13 +56,19 @@ or equal to ``18``, you could do the following: .. code-block:: xml - - - - - - - + + + + + + + + + + + .. code-block:: php @@ -85,6 +91,9 @@ or equal to ``18``, you could do the following: Comparing Dates --------------- +.. versionadded:: 2.6 + The feature to compare dates was added in Symfony 2.6. + This constraint can be used to compare ``DateTime`` objects against any date string `accepted by the DateTime constructor`_. For example, you could check that a date must at least be the current day: @@ -117,11 +126,17 @@ that a date must at least be the current day: .. code-block:: xml - - - today - - + + + + + + today + + + .. code-block:: php @@ -170,11 +185,17 @@ dates. If you want to fix the timezone, append it to the date string: .. code-block:: xml - - - today UTC - - + + + + + + today UTC + + + .. code-block:: php @@ -224,11 +245,17 @@ current time: .. code-block:: xml - - - +5 hours - - + + + + + + +5 hours + + + .. code-block:: php diff --git a/reference/constraints/LessThan.rst b/reference/constraints/LessThan.rst index 09c5f93ef40..f4a2f32af40 100644 --- a/reference/constraints/LessThan.rst +++ b/reference/constraints/LessThan.rst @@ -57,13 +57,19 @@ If you want to ensure that the ``age`` of a ``Person`` class is less than .. code-block:: xml - - - - - - - + + + + + + + + + + + .. code-block:: php @@ -86,6 +92,9 @@ If you want to ensure that the ``age`` of a ``Person`` class is less than Comparing Dates --------------- +.. versionadded:: 2.6 + The feature to compare dates was added in Symfony 2.6. + This constraint can be used to compare ``DateTime`` objects against any date string `accepted by the DateTime constructor`_. For example, you could check that a date must be in the past like this: @@ -97,7 +106,7 @@ that a date must be in the past like this: # src/SocialBundle/Resources/config/validation.yml Acme\SocialBundle\Entity\Person: properties: - age: + dateOfBirth: - LessThan: today .. code-block:: php-annotations @@ -112,17 +121,23 @@ that a date must be in the past like this: /** * @Assert\LessThan("today") */ - protected $age; + protected $dateOfBirth; } .. code-block:: xml - - - today - - + + + + + + today + + + .. code-block:: php @@ -136,7 +151,7 @@ that a date must be in the past like this: { public static function loadValidatorMetadata(ClassMetadata $metadata) { - $metadata->addPropertyConstraint('age', new Assert\LessThan('today')); + $metadata->addPropertyConstraint('dateOfBirth', new Assert\LessThan('today')); } } @@ -150,7 +165,7 @@ dates. If you want to fix the timezone, append it to the date string: # src/SocialBundle/Resources/config/validation.yml Acme\SocialBundle\Entity\Person: properties: - age: + dateOfBirth: - LessThan: today UTC .. code-block:: php-annotations @@ -165,17 +180,23 @@ dates. If you want to fix the timezone, append it to the date string: /** * @Assert\LessThan("today UTC") */ - protected $age; + protected $dateOfBirth; } .. code-block:: xml - - - today UTC - - + + + + + + today UTC + + + .. code-block:: php @@ -203,7 +224,7 @@ can check that a person must be at least 18 years old like this: # src/SocialBundle/Resources/config/validation.yml Acme\SocialBundle\Entity\Person: properties: - age: + dateOfBirth: - LessThan: -18 years .. code-block:: php-annotations @@ -218,17 +239,23 @@ can check that a person must be at least 18 years old like this: /** * @Assert\LessThan("-18 years") */ - protected $age; + protected $dateOfBirth; } .. code-block:: xml - - - -18 years - - + + + + + + -18 years + + + .. code-block:: php @@ -242,7 +269,7 @@ can check that a person must be at least 18 years old like this: { public static function loadValidatorMetadata(ClassMetadata $metadata) { - $metadata->addPropertyConstraint('age', new Assert\LessThan('-18 years')); + $metadata->addPropertyConstraint('dateOfBirth', new Assert\LessThan('-18 years')); } } diff --git a/reference/constraints/LessThanOrEqual.rst b/reference/constraints/LessThanOrEqual.rst index 61261fbe571..89d67ff41b4 100644 --- a/reference/constraints/LessThanOrEqual.rst +++ b/reference/constraints/LessThanOrEqual.rst @@ -56,13 +56,19 @@ equal to ``80``, you could do the following: .. code-block:: xml - - - - - - - + + + + + + + + + + + .. code-block:: php @@ -85,6 +91,9 @@ equal to ``80``, you could do the following: Comparing Dates --------------- +.. versionadded:: 2.6 + The feature to compare dates was added in Symfony 2.6. + This constraint can be used to compare ``DateTime`` objects against any date string `accepted by the DateTime constructor`_. For example, you could check that a date must be today or in the past like this: @@ -117,11 +126,17 @@ that a date must be today or in the past like this: .. code-block:: xml - - - today - - + + + + + + today + + + .. code-block:: php @@ -170,11 +185,17 @@ dates. If you want to fix the timezone, append it to the date string: .. code-block:: xml - - - today UTC - - + + + + + + today UTC + + + .. code-block:: php @@ -223,11 +244,17 @@ can check that a person must be at least 18 years old like this: .. code-block:: xml - - - -18 years - - + + + + + + -18 years + + + .. code-block:: php diff --git a/reference/constraints/Range.rst b/reference/constraints/Range.rst index 6009adf7a55..1dce92d6a59 100644 --- a/reference/constraints/Range.rst +++ b/reference/constraints/Range.rst @@ -140,18 +140,24 @@ date must lie within the current year like this: .. code-block:: xml - - - - - - - - + + + + + + + + + + + + .. code-block:: php - // src/Acme/EventBundle/Entity/Person.php + // src/Acme/EventBundle/Entity/Event.php namespace Acme\EventBundle\Entity; use Symfony\Component\Validator\Mapping\ClassMetadata; @@ -204,14 +210,20 @@ dates. If you want to fix the timezone, append it to the date string: .. code-block:: xml - - - - - - - - + + + + + + + + + + + + .. code-block:: php @@ -268,14 +280,20 @@ can check that a delivery date starts within the next five hours like this: .. code-block:: xml - - - - - - - - + + + + + + + + + + + + .. code-block:: php From e4b776ebce4eea24c29dc070aadbc9547f76c4c1 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 16 Jun 2015 16:22:01 +0200 Subject: [PATCH 3/6] Fixed the issues reported by @xabbuh --- reference/constraints/GreaterThan.rst | 7 +++++-- reference/constraints/GreaterThanOrEqual.rst | 4 ++-- reference/constraints/LessThan.rst | 4 ++-- reference/constraints/LessThanOrEqual.rst | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/reference/constraints/GreaterThan.rst b/reference/constraints/GreaterThan.rst index 8f7783b1937..ccc89c9e92f 100644 --- a/reference/constraints/GreaterThan.rst +++ b/reference/constraints/GreaterThan.rst @@ -14,6 +14,7 @@ than another value, see :doc:`/reference/constraints/LessThan`. +----------------+---------------------------------------------------------------------------+ | Options | - `value`_ | | | - `message`_ | +| | - `payload`_ | +----------------+---------------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Validator\\Constraints\\GreaterThan` | +----------------+---------------------------------------------------------------------------+ @@ -30,7 +31,7 @@ If you want to ensure that the ``age`` of a ``Person`` class is greater than .. code-block:: yaml - # src/SocialBundle/Resources/config/validation.yml + # src/Acme/SocialBundle/Resources/config/validation.yml Acme\SocialBundle\Entity\Person: properties: age: @@ -93,7 +94,7 @@ Comparing Dates --------------- .. versionadded:: 2.6 - The feature to compare dates was added in Symfony 2.6. + The feature to compare dates was introduced in Symfony 2.6. This constraint can be used to compare ``DateTime`` objects against any date string `accepted by the DateTime constructor`_. For example, you could check @@ -287,4 +288,6 @@ message This is the message that will be shown if the value is not greater than the comparison value. +.. include:: /reference/constraints/_payload-option.rst.inc + .. _`accepted by the DateTime constructor`: http://www.php.net/manual/en/datetime.formats.php diff --git a/reference/constraints/GreaterThanOrEqual.rst b/reference/constraints/GreaterThanOrEqual.rst index e5abbfb239f..b591f38d0b4 100644 --- a/reference/constraints/GreaterThanOrEqual.rst +++ b/reference/constraints/GreaterThanOrEqual.rst @@ -29,7 +29,7 @@ or equal to ``18``, you could do the following: .. code-block:: yaml - # src/SocialBundle/Resources/config/validation.yml + # src/Acme/SocialBundle/Resources/config/validation.yml Acme\SocialBundle\Entity\Person: properties: age: @@ -92,7 +92,7 @@ Comparing Dates --------------- .. versionadded:: 2.6 - The feature to compare dates was added in Symfony 2.6. + The feature to compare dates was introduced in Symfony 2.6. This constraint can be used to compare ``DateTime`` objects against any date string `accepted by the DateTime constructor`_. For example, you could check diff --git a/reference/constraints/LessThan.rst b/reference/constraints/LessThan.rst index f4a2f32af40..d07c163abfb 100644 --- a/reference/constraints/LessThan.rst +++ b/reference/constraints/LessThan.rst @@ -30,7 +30,7 @@ If you want to ensure that the ``age`` of a ``Person`` class is less than .. code-block:: yaml - # src/SocialBundle/Resources/config/validation.yml + # src/Acme/SocialBundle/Resources/config/validation.yml Acme\SocialBundle\Entity\Person: properties: age: @@ -93,7 +93,7 @@ Comparing Dates --------------- .. versionadded:: 2.6 - The feature to compare dates was added in Symfony 2.6. + The feature to compare dates was introduced in Symfony 2.6. This constraint can be used to compare ``DateTime`` objects against any date string `accepted by the DateTime constructor`_. For example, you could check diff --git a/reference/constraints/LessThanOrEqual.rst b/reference/constraints/LessThanOrEqual.rst index 89d67ff41b4..78c40bb9c95 100644 --- a/reference/constraints/LessThanOrEqual.rst +++ b/reference/constraints/LessThanOrEqual.rst @@ -29,7 +29,7 @@ equal to ``80``, you could do the following: .. code-block:: yaml - # src/SocialBundle/Resources/config/validation.yml + # src/Acme/SocialBundle/Resources/config/validation.yml Acme\SocialBundle\Entity\Person: properties: age: @@ -92,7 +92,7 @@ Comparing Dates --------------- .. versionadded:: 2.6 - The feature to compare dates was added in Symfony 2.6. + The feature to compare dates was introduced in Symfony 2.6. This constraint can be used to compare ``DateTime`` objects against any date string `accepted by the DateTime constructor`_. For example, you could check From a9ba5281f1801e895c7d47428268b3193bd1de8b Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 16 Jun 2015 16:26:57 +0200 Subject: [PATCH 4/6] Reordered the code blocks to show Annotations, YAML, XML and PHP --- reference/constraints/GreaterThan.rst | 66 ++++++++++---------- reference/constraints/GreaterThanOrEqual.rst | 66 ++++++++++---------- reference/constraints/LessThan.rst | 66 ++++++++++---------- reference/constraints/LessThanOrEqual.rst | 66 ++++++++++---------- 4 files changed, 132 insertions(+), 132 deletions(-) diff --git a/reference/constraints/GreaterThan.rst b/reference/constraints/GreaterThan.rst index ccc89c9e92f..bf47027494d 100644 --- a/reference/constraints/GreaterThan.rst +++ b/reference/constraints/GreaterThan.rst @@ -29,15 +29,6 @@ If you want to ensure that the ``age`` of a ``Person`` class is greater than .. configuration-block:: - .. code-block:: yaml - - # src/Acme/SocialBundle/Resources/config/validation.yml - Acme\SocialBundle\Entity\Person: - properties: - age: - - GreaterThan: - value: 18 - .. code-block:: php-annotations // src/Acme/SocialBundle/Entity/Person.php @@ -55,6 +46,15 @@ If you want to ensure that the ``age`` of a ``Person`` class is greater than protected $age; } + .. code-block:: yaml + + # src/Acme/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - GreaterThan: + value: 18 + .. code-block:: xml @@ -102,14 +102,6 @@ that a date must at least be the next day: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/OrderBundle/Resources/config/validation.yml - Acme\OrderBundle\Entity\Order: - properties: - deliveryDate: - - GreaterThan: today - .. code-block:: php-annotations // src/Acme/OrderBundle/Entity/Order.php @@ -125,6 +117,14 @@ that a date must at least be the next day: protected $deliveryDate; } + .. code-block:: yaml + + # src/Acme/OrderBundle/Resources/config/validation.yml + Acme\OrderBundle\Entity\Order: + properties: + deliveryDate: + - GreaterThan: today + .. code-block:: xml @@ -161,14 +161,6 @@ dates. If you want to fix the timezone, append it to the date string: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/OrderBundle/Resources/config/validation.yml - Acme\OrderBundle\Entity\Order: - properties: - deliveryDate: - - GreaterThan: today UTC - .. code-block:: php-annotations // src/Acme/OrderBundle/Entity/Order.php @@ -184,6 +176,14 @@ dates. If you want to fix the timezone, append it to the date string: protected $deliveryDate; } + .. code-block:: yaml + + # src/Acme/OrderBundle/Resources/config/validation.yml + Acme\OrderBundle\Entity\Order: + properties: + deliveryDate: + - GreaterThan: today UTC + .. code-block:: xml @@ -221,14 +221,6 @@ current time: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/OrderBundle/Resources/config/validation.yml - Acme\OrderBundle\Entity\Order: - properties: - deliveryDate: - - GreaterThan: +5 hours - .. code-block:: php-annotations // src/Acme/OrderBundle/Entity/Order.php @@ -244,6 +236,14 @@ current time: protected $deliveryDate; } + .. code-block:: yaml + + # src/Acme/OrderBundle/Resources/config/validation.yml + Acme\OrderBundle\Entity\Order: + properties: + deliveryDate: + - GreaterThan: +5 hours + .. code-block:: xml diff --git a/reference/constraints/GreaterThanOrEqual.rst b/reference/constraints/GreaterThanOrEqual.rst index b591f38d0b4..eb5754c2eaa 100644 --- a/reference/constraints/GreaterThanOrEqual.rst +++ b/reference/constraints/GreaterThanOrEqual.rst @@ -27,15 +27,6 @@ or equal to ``18``, you could do the following: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/SocialBundle/Resources/config/validation.yml - Acme\SocialBundle\Entity\Person: - properties: - age: - - GreaterThanOrEqual: - value: 18 - .. code-block:: php-annotations // src/Acme/SocialBundle/Entity/Person.php @@ -53,6 +44,15 @@ or equal to ``18``, you could do the following: protected $age; } + .. code-block:: yaml + + # src/Acme/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - GreaterThanOrEqual: + value: 18 + .. code-block:: xml @@ -100,14 +100,6 @@ that a date must at least be the current day: .. configuration-block:: - .. code-block:: yaml - - # src/OrderBundle/Resources/config/validation.yml - Acme\OrderBundle\Entity\Order: - properties: - deliveryDate: - - GreaterThanOrEqual: today - .. code-block:: php-annotations // src/Acme/SocialBundle/Entity/Order.php @@ -123,6 +115,14 @@ that a date must at least be the current day: protected $deliveryDate; } + .. code-block:: yaml + + # src/OrderBundle/Resources/config/validation.yml + Acme\OrderBundle\Entity\Order: + properties: + deliveryDate: + - GreaterThanOrEqual: today + .. code-block:: xml @@ -159,14 +159,6 @@ dates. If you want to fix the timezone, append it to the date string: .. configuration-block:: - .. code-block:: yaml - - # src/OrderBundle/Resources/config/validation.yml - Acme\OrderBundle\Entity\Order: - properties: - deliveryDate: - - GreaterThanOrEqual: today UTC - .. code-block:: php-annotations // src/Acme/SocialBundle/Entity/Order.php @@ -182,6 +174,14 @@ dates. If you want to fix the timezone, append it to the date string: protected $deliveryDate; } + .. code-block:: yaml + + # src/OrderBundle/Resources/config/validation.yml + Acme\OrderBundle\Entity\Order: + properties: + deliveryDate: + - GreaterThanOrEqual: today UTC + .. code-block:: xml @@ -219,14 +219,6 @@ current time: .. configuration-block:: - .. code-block:: yaml - - # src/OrderBundle/Resources/config/validation.yml - Acme\OrderBundle\Entity\Order: - properties: - deliveryDate: - - GreaterThanOrEqual: +5 hours - .. code-block:: php-annotations // src/Acme/SocialBundle/Entity/Order.php @@ -242,6 +234,14 @@ current time: protected $deliveryDate; } + .. code-block:: yaml + + # src/OrderBundle/Resources/config/validation.yml + Acme\OrderBundle\Entity\Order: + properties: + deliveryDate: + - GreaterThanOrEqual: +5 hours + .. code-block:: xml diff --git a/reference/constraints/LessThan.rst b/reference/constraints/LessThan.rst index d07c163abfb..3afcd1be4f1 100644 --- a/reference/constraints/LessThan.rst +++ b/reference/constraints/LessThan.rst @@ -28,15 +28,6 @@ If you want to ensure that the ``age`` of a ``Person`` class is less than .. configuration-block:: - .. code-block:: yaml - - # src/Acme/SocialBundle/Resources/config/validation.yml - Acme\SocialBundle\Entity\Person: - properties: - age: - - LessThan: - value: 80 - .. code-block:: php-annotations // src/Acme/SocialBundle/Entity/Person.php @@ -54,6 +45,15 @@ If you want to ensure that the ``age`` of a ``Person`` class is less than protected $age; } + .. code-block:: yaml + + # src/Acme/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - LessThan: + value: 80 + .. code-block:: xml @@ -101,14 +101,6 @@ that a date must be in the past like this: .. configuration-block:: - .. code-block:: yaml - - # src/SocialBundle/Resources/config/validation.yml - Acme\SocialBundle\Entity\Person: - properties: - dateOfBirth: - - LessThan: today - .. code-block:: php-annotations // src/Acme/SocialBundle/Entity/Person.php @@ -124,6 +116,14 @@ that a date must be in the past like this: protected $dateOfBirth; } + .. code-block:: yaml + + # src/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + dateOfBirth: + - LessThan: today + .. code-block:: xml @@ -160,14 +160,6 @@ dates. If you want to fix the timezone, append it to the date string: .. configuration-block:: - .. code-block:: yaml - - # src/SocialBundle/Resources/config/validation.yml - Acme\SocialBundle\Entity\Person: - properties: - dateOfBirth: - - LessThan: today UTC - .. code-block:: php-annotations // src/Acme/SocialBundle/Entity/Person.php @@ -183,6 +175,14 @@ dates. If you want to fix the timezone, append it to the date string: protected $dateOfBirth; } + .. code-block:: yaml + + # src/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + dateOfBirth: + - LessThan: today UTC + .. code-block:: xml @@ -219,14 +219,6 @@ can check that a person must be at least 18 years old like this: .. configuration-block:: - .. code-block:: yaml - - # src/SocialBundle/Resources/config/validation.yml - Acme\SocialBundle\Entity\Person: - properties: - dateOfBirth: - - LessThan: -18 years - .. code-block:: php-annotations // src/Acme/SocialBundle/Entity/Person.php @@ -242,6 +234,14 @@ can check that a person must be at least 18 years old like this: protected $dateOfBirth; } + .. code-block:: yaml + + # src/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + dateOfBirth: + - LessThan: -18 years + .. code-block:: xml diff --git a/reference/constraints/LessThanOrEqual.rst b/reference/constraints/LessThanOrEqual.rst index 78c40bb9c95..889ffe9d46a 100644 --- a/reference/constraints/LessThanOrEqual.rst +++ b/reference/constraints/LessThanOrEqual.rst @@ -27,15 +27,6 @@ equal to ``80``, you could do the following: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/SocialBundle/Resources/config/validation.yml - Acme\SocialBundle\Entity\Person: - properties: - age: - - LessThanOrEqual: - value: 80 - .. code-block:: php-annotations // src/Acme/SocialBundle/Entity/Person.php @@ -53,6 +44,15 @@ equal to ``80``, you could do the following: protected $age; } + .. code-block:: yaml + + # src/Acme/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - LessThanOrEqual: + value: 80 + .. code-block:: xml @@ -100,14 +100,6 @@ that a date must be today or in the past like this: .. configuration-block:: - .. code-block:: yaml - - # src/SocialBundle/Resources/config/validation.yml - Acme\SocialBundle\Entity\Person: - properties: - age: - - LessThanOrEqual: today - .. code-block:: php-annotations // src/Acme/SocialBundle/Entity/Person.php @@ -123,6 +115,14 @@ that a date must be today or in the past like this: protected $age; } + .. code-block:: yaml + + # src/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - LessThanOrEqual: today + .. code-block:: xml @@ -159,14 +159,6 @@ dates. If you want to fix the timezone, append it to the date string: .. configuration-block:: - .. code-block:: yaml - - # src/SocialBundle/Resources/config/validation.yml - Acme\SocialBundle\Entity\Person: - properties: - age: - - LessThanOrEqual: today UTC - .. code-block:: php-annotations // src/Acme/SocialBundle/Entity/Person.php @@ -182,6 +174,14 @@ dates. If you want to fix the timezone, append it to the date string: protected $age; } + .. code-block:: yaml + + # src/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - LessThanOrEqual: today UTC + .. code-block:: xml @@ -218,14 +218,6 @@ can check that a person must be at least 18 years old like this: .. configuration-block:: - .. code-block:: yaml - - # src/SocialBundle/Resources/config/validation.yml - Acme\SocialBundle\Entity\Person: - properties: - age: - - LessThanOrEqual: -18 years - .. code-block:: php-annotations // src/Acme/SocialBundle/Entity/Person.php @@ -241,6 +233,14 @@ can check that a person must be at least 18 years old like this: protected $age; } + .. code-block:: yaml + + # src/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - LessThanOrEqual: -18 years + .. code-block:: xml From 918df0a72ceb37d5b80481039f785da72bfce794 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 16 Jun 2015 22:26:30 +0200 Subject: [PATCH 5/6] Show annotations first --- reference/constraints/Range.rst | 60 ++++++++++++++++----------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/reference/constraints/Range.rst b/reference/constraints/Range.rst index 1dce92d6a59..6f4dea3339d 100644 --- a/reference/constraints/Range.rst +++ b/reference/constraints/Range.rst @@ -109,16 +109,6 @@ date must lie within the current year like this: .. configuration-block:: - .. code-block:: yaml - - # src/EventBundle/Resources/config/validation.yml - Acme\EventBundle\Entity\Event: - properties: - startDate: - - Range: - min: first day of January - max: first day of January next year - .. code-block:: php-annotations // src/Acme/SocialBundle/Entity/Event.php @@ -137,6 +127,16 @@ date must lie within the current year like this: protected $startDate; } + .. code-block:: yaml + + # src/EventBundle/Resources/config/validation.yml + Acme\EventBundle\Entity\Event: + properties: + startDate: + - Range: + min: first day of January + max: first day of January next year + .. code-block:: xml @@ -179,16 +179,6 @@ dates. If you want to fix the timezone, append it to the date string: .. configuration-block:: - .. code-block:: yaml - - # src/EventBundle/Resources/config/validation.yml - Acme\EventBundle\Entity\Event: - properties: - startDate: - - Range: - min: first day of January UTC - max: first day of January next year UTC - .. code-block:: php-annotations // src/Acme/SocialBundle/Entity/Event.php @@ -207,6 +197,16 @@ dates. If you want to fix the timezone, append it to the date string: protected $startDate; } + .. code-block:: yaml + + # src/EventBundle/Resources/config/validation.yml + Acme\EventBundle\Entity\Event: + properties: + startDate: + - Range: + min: first day of January UTC + max: first day of January next year UTC + .. code-block:: xml @@ -249,16 +249,6 @@ can check that a delivery date starts within the next five hours like this: .. configuration-block:: - .. code-block:: yaml - - # src/OrderBundle/Resources/config/validation.yml - Acme\OrderBundle\Entity\Order: - properties: - deliveryDate: - - Range: - min: now - max: +5 hours - .. code-block:: php-annotations // src/Acme/SocialBundle/Entity/Order.php @@ -277,6 +267,16 @@ can check that a delivery date starts within the next five hours like this: protected $deliveryDate; } + .. code-block:: yaml + + # src/OrderBundle/Resources/config/validation.yml + Acme\OrderBundle\Entity\Order: + properties: + deliveryDate: + - Range: + min: now + max: +5 hours + .. code-block:: xml From c5d0c8f46ec8250920cf9483071e9d29a20b2303 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 16 Jun 2015 22:27:45 +0200 Subject: [PATCH 6/6] Added the "payload" option back --- reference/constraints/GreaterThanOrEqual.rst | 3 +++ reference/constraints/LessThan.rst | 3 +++ reference/constraints/LessThanOrEqual.rst | 3 +++ 3 files changed, 9 insertions(+) diff --git a/reference/constraints/GreaterThanOrEqual.rst b/reference/constraints/GreaterThanOrEqual.rst index eb5754c2eaa..4d61dd5b077 100644 --- a/reference/constraints/GreaterThanOrEqual.rst +++ b/reference/constraints/GreaterThanOrEqual.rst @@ -13,6 +13,7 @@ the options. To force that a value is greater than another value, see +----------------+----------------------------------------------------------------------------------+ | Options | - `value`_ | | | - `message`_ | +| | - `payload`_ | +----------------+----------------------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Validator\\Constraints\\GreaterThanOrEqual` | +----------------+----------------------------------------------------------------------------------+ @@ -286,4 +287,6 @@ message This is the message that will be shown if the value is not greater than or equal to the comparison value. +.. include:: /reference/constraints/_payload-option.rst.inc + .. _`accepted by the DateTime constructor`: http://www.php.net/manual/en/datetime.formats.php diff --git a/reference/constraints/LessThan.rst b/reference/constraints/LessThan.rst index 3afcd1be4f1..772f6e629ee 100644 --- a/reference/constraints/LessThan.rst +++ b/reference/constraints/LessThan.rst @@ -14,6 +14,7 @@ than another value, see :doc:`/reference/constraints/GreaterThan`. +----------------+------------------------------------------------------------------------+ | Options | - `value`_ | | | - `message`_ | +| | - `payload`_ | +----------------+------------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Validator\\Constraints\\LessThan` | +----------------+------------------------------------------------------------------------+ @@ -286,4 +287,6 @@ message This is the message that will be shown if the value is not less than the comparison value. +.. include:: /reference/constraints/_payload-option.rst.inc + .. _`accepted by the DateTime constructor`: http://www.php.net/manual/en/datetime.formats.php diff --git a/reference/constraints/LessThanOrEqual.rst b/reference/constraints/LessThanOrEqual.rst index 889ffe9d46a..22d0201a429 100644 --- a/reference/constraints/LessThanOrEqual.rst +++ b/reference/constraints/LessThanOrEqual.rst @@ -13,6 +13,7 @@ options. To force that a value is less than another value, see +----------------+-------------------------------------------------------------------------------+ | Options | - `value`_ | | | - `message`_ | +| | - `payload`_ | +----------------+-------------------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Validator\\Constraints\\LessThanOrEqual` | +----------------+-------------------------------------------------------------------------------+ @@ -285,4 +286,6 @@ message This is the message that will be shown if the value is not less than or equal to the comparison value. +.. include:: /reference/constraints/_payload-option.rst.inc + .. _`accepted by the DateTime constructor`: http://www.php.net/manual/en/datetime.formats.php pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy