Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.3k
Documented the Comparison validators#2599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
8 commits Select commitHold shift + click to select a range
635c8c8 Added documentation for the EqualConstraint
wouterj48ca4f0 Added docs for NotEqualTo validator
wouterj372e800 Added docs for IdenticalTo validator
wouterjf901935 Added docs for NotIdenticalTo validator
wouterjfef0195 Added docs for LessThan validator
wouterj030d05c Added docs for LessThanOrEqual validator
wouterj956f5fc Added docs for GreaterThan validator
wouterj6f261f4 Added docs for GreaterThanOrEqual validator
wouterjFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
9 changes: 9 additions & 0 deletionsreference/constraints.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletionsreference/constraints/EqualTo.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| 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/NotEqualTo`. | ||
| .. 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<validation-property-target>` | | ||
| +----------------+-----------------------------------------------------------------------+ | ||
| | 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 | ||
| <!-- src/Acme/SocialBundle/Resources/config/validation.xml --> | ||
| <class name="Acme\SocialBundle\Entity\Person"> | ||
| <property name="age"> | ||
| <constraint name="EqualTo"> | ||
| <option name="value">20</option> | ||
| </constraint> | ||
| </property> | ||
| </class> | ||
| .. 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 | ||
| ------- | ||
| .. include:: /reference/constraints/_comparison-value-option.rst.inc | ||
| 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. |
96 changes: 96 additions & 0 deletionsreference/constraints/GreaterThan.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<validation-property-target>` | | ||
| +----------------+---------------------------------------------------------------------------+ | ||
| | 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 | ||
| <!-- src/Acme/SocialBundle/Resources/config/validation.xml --> | ||
| <class name="Acme\SocialBundle\Entity\Person"> | ||
| <property name="age"> | ||
| <constraint name="GreaterThan"> | ||
| <option name="value">18</option> | ||
| </constraint> | ||
| </property> | ||
| </class> | ||
| .. 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. |
95 changes: 95 additions & 0 deletionsreference/constraints/GreaterThanOrEqual.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<validation-property-target>` | | ||
| +----------------+----------------------------------------------------------------------------------+ | ||
| | 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 | ||
| <!-- src/Acme/SocialBundle/Resources/config/validation.xml --> | ||
| <class name="Acme\SocialBundle\Entity\Person"> | ||
| <property name="age"> | ||
| <constraint name="GreaterThanOrEqual"> | ||
| <option name="value">18</option> | ||
| </constraint> | ||
| </property> | ||
| </class> | ||
| .. 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. |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.