Skip to content

Commit 6f261f4

Browse files
committed
Added docs for GreaterThanOrEqual validator
1 parent 956f5fc commit 6f261f4

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

reference/constraints.rst

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Validation Constraints Reference
2828
constraints/LessThan
2929
constraints/LessThanOrEqual
3030
constraints/GreaterThan
31+
constraints/GreaterThanOrEqual
3132

3233
constraints/Date
3334
constraints/DateTime
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
GreaterThanOrEqual
2+
===========
3+
4+
.. versionadded:: 2.3
5+
This constraint is new in version 2.3.
6+
7+
Validates that a value is greater than or equal to another value, defined in
8+
the options. To force that a value is greater than another value, see
9+
:doc:`/reference/constraints/GreaterThan`.
10+
11+
+----------------+----------------------------------------------------------------------------------+
12+
| Applies to | :ref:`property or method<validation-property-target>` |
13+
+----------------+----------------------------------------------------------------------------------+
14+
| Options | - `value`_ |
15+
| | - `message`_ |
16+
+----------------+----------------------------------------------------------------------------------+
17+
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\GreaterThanOrEqual` |
18+
+----------------+----------------------------------------------------------------------------------+
19+
| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\GreaterThanOrEqualValidator` |
20+
+----------------+----------------------------------------------------------------------------------+
21+
22+
Basic Usage
23+
-----------
24+
25+
If you want to ensure that the ``age`` of a ``Person`` class is greater than
26+
or equal to ``18``, you could do the following:
27+
28+
.. configuration-block::
29+
30+
.. code-block:: yaml
31+
32+
# src/SocialBundle/Resources/config/validation.yml
33+
Acme\SocialBundle\Entity\Person:
34+
properties:
35+
age:
36+
- GreaterThanOrEqual:
37+
value: 18
38+
39+
.. code-block:: php-annotations
40+
41+
// src/Acme/SocialBundle/Entity/Person.php
42+
namespace Acme\SocialBundle\Entity;
43+
44+
use Symfony\Component\Validator\Constraints as Assert;
45+
46+
class Person
47+
{
48+
/**
49+
* @Assert\GreaterThanOrEqual(
50+
* value = 18
51+
* )
52+
*/
53+
protected $age;
54+
}
55+
56+
.. code-block:: xml
57+
58+
<!-- src/Acme/SocialBundle/Resources/config/validation.xml -->
59+
<class name="Acme\SocialBundle\Entity\Person">
60+
<property name="age">
61+
<constraint name="GreaterThanOrEqual">
62+
<option name="value">18</option>
63+
</constraint>
64+
</property>
65+
</class>
66+
67+
.. code-block:: php
68+
69+
// src/Acme/SocialBundle/Entity/Person.php
70+
namespace Acme\SocialBundle\Entity;
71+
72+
use Symfony\Component\Validator\Mapping\ClassMetadata;
73+
use Symfony\Component\Validator\Constraints as Assert;
74+
75+
class Person
76+
{
77+
public static function loadValidatorMetadata(ClassMetadata $metadata)
78+
{
79+
$metadata->addPropertyConstraint('age', new Assert\GreaterThanOrEqual(array(
80+
'value' => 18,
81+
)));
82+
}
83+
}
84+
85+
Options
86+
-------
87+
88+
.. include:: /reference/constraints/_comparison-value-option.rst.inc
89+
90+
message
91+
~~~~~~~
92+
93+
**type**: ``string`` **default**: ``This value should be greater than or equal to {{ compared_value }}``
94+
95+
This is the message that will be shown if the value is not equal.

reference/constraints/map.rst.inc

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Comparison Constraints
3636
* :doc:`LessThan </reference/constraints/LessThan>`
3737
* :doc:`LessThanOrEqual </reference/constraints/LessThanOrEqual>`
3838
* :doc:`GreaterThan </reference/constraints/GreaterThan>`
39+
* :doc:`GreaterThanOrEqual </reference/constraints/GreaterThanOrEqual>`
3940

4041
Date Constraints
4142
~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)