From 70034452d978b25deb1bf4b0422dff1216d33968 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 11 Jun 2015 14:56:52 +0200 Subject: [PATCH] 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