@@ -23,8 +23,9 @@ the options. To force that a value is greater than another value, see
2323Basic Usage
2424-----------
2525
26- If you want to ensure that the ``age `` of a ``Person `` class is greater than
27- or equal to ``18 ``, you could do the following:
26+ The following constraints ensure that:
27+ - the number of ``siblings `` of a ``Person `` is greater than or equal to ``5 ``
28+ - the ``age `` of a ``Person `` class is greater than or equal to ``18 ``
2829
2930.. configuration-block ::
3031
@@ -37,6 +38,11 @@ or equal to ``18``, you could do the following:
3738
3839 class Person
3940 {
41+ /**
42+ * @Assert\GreaterThanOrEqual(5)
43+ */
44+ protected $siblings;
45+
4046 /**
4147 * @Assert\GreaterThanOrEqual(
4248 * value = 18
@@ -50,6 +56,8 @@ or equal to ``18``, you could do the following:
5056 # src/AppBundle/Resources/config/validation.yml
5157 AppBundle\Entity\Person :
5258 properties :
59+ siblings :
60+ - GreaterThanOrEqual : 5
5361 age :
5462 - GreaterThanOrEqual :
5563 value : 18
@@ -63,6 +71,11 @@ or equal to ``18``, you could do the following:
6371 xsi : schemaLocation =" http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd" >
6472
6573 <class name =" AppBundle\Entity\Person" >
74+ <property name =" siblings" >
75+ <constraint name =" GreaterThanOrEqual" >
76+ <value >5</value >
77+ </constraint >
78+ </property >
6679 <property name =" age" >
6780 <constraint name =" GreaterThanOrEqual" >
6881 <option name =" value" >18</option >
@@ -83,6 +96,8 @@ or equal to ``18``, you could do the following:
8396 {
8497 public static function loadValidatorMetadata(ClassMetadata $metadata)
8598 {
99+ $metadata->addPropertyConstraint('siblings', new Assert\GreaterThanOrEqual(5));
100+
86101 $metadata->addPropertyConstraint('age', new Assert\GreaterThanOrEqual(array(
87102 'value' => 18,
88103 )));
0 commit comments