-
-
Couldn't load subscription status.
- Fork 5.3k
[Validator] Add shorter examples using the default option #6597
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,8 +23,10 @@ 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: | ||
| The following constraints ensure that: | ||
| - the number of ``siblings`` of a ``Person`` is greater than ``5`` | ||
| - the ``age`` of a ``Person`` class is greater than ``18`` | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we commonly use |
||
|
|
||
|
|
||
| .. configuration-block:: | ||
|
|
||
|
|
@@ -37,6 +39,12 @@ than ``18``, you could do the following: | |
|
|
||
| class Person | ||
| { | ||
|
|
||
| /** | ||
| * @Assert\GreaterThan(5) | ||
| */ | ||
| protected $siblings; | ||
|
|
||
| /** | ||
| * @Assert\GreaterThan( | ||
| * value = 18 | ||
|
|
@@ -50,6 +58,8 @@ than ``18``, you could do the following: | |
| # src/AppBundle/Resources/config/validation.yml | ||
| AppBundle\Entity\Person: | ||
| properties: | ||
| siblings: | ||
| - GreaterThan: 5 | ||
| age: | ||
| - GreaterThan: | ||
| value: 18 | ||
|
|
@@ -63,6 +73,11 @@ than ``18``, you could do the following: | |
| xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd"> | ||
|
|
||
| <class name="AppBundle\Entity\Person"> | ||
| <property name="siblings"> | ||
| <constraint name="GreaterThan"> | ||
| <value>5</value> | ||
| </constraint> | ||
| </property> | ||
| <property name="age"> | ||
| <constraint name="GreaterThan"> | ||
| <option name="value">18</option> | ||
|
|
@@ -83,6 +98,8 @@ than ``18``, you could do the following: | |
| { | ||
| public static function loadValidatorMetadata(ClassMetadata $metadata) | ||
| { | ||
| $metadata->addPropertyConstraint('siblings', new Assert\GreaterThan(5)); | ||
|
|
||
| $metadata->addPropertyConstraint('age', new Assert\GreaterThan(array( | ||
| 'value' => 18, | ||
| ))); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,8 +22,9 @@ 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: | ||
| The following constraints ensure that: | ||
| - the number of ``siblings`` of a ``Person`` is greater than or equal to ``5`` | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here a blank line too before the list items. |
||
| - the ``age`` of a ``Person`` class is greater than or equal to ``18`` | ||
|
|
||
| .. configuration-block:: | ||
|
|
||
|
|
@@ -36,6 +37,11 @@ than or equal to ``18``, you could do the following: | |
|
|
||
| class Person | ||
| { | ||
| /** | ||
| * @Assert\GreaterThanOrEqual(5) | ||
| */ | ||
| protected $siblings; | ||
|
|
||
| /** | ||
| * @Assert\GreaterThanOrEqual( | ||
| * value = 18 | ||
|
|
@@ -49,6 +55,8 @@ than or equal to ``18``, you could do the following: | |
| # src/AppBundle/Resources/config/validation.yml | ||
| AppBundle\Entity\Person: | ||
| properties: | ||
| siblings: | ||
| - GreaterThanOrEqual: 5 | ||
| age: | ||
| - GreaterThanOrEqual: | ||
| value: 18 | ||
|
|
@@ -62,6 +70,11 @@ than or equal to ``18``, you could do the following: | |
| xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd"> | ||
|
|
||
| <class name="AppBundle\Entity\Person"> | ||
| <property name="siblings"> | ||
| <constraint name="GreaterThanOrEqual"> | ||
| <value>5</value> | ||
| </constraint> | ||
| </property> | ||
| <property name="age"> | ||
| <constraint name="GreaterThanOrEqual"> | ||
| <option name="value">18</option> | ||
|
|
@@ -82,6 +95,8 @@ than or equal to ``18``, you could do the following: | |
| { | ||
| public static function loadValidatorMetadata(ClassMetadata $metadata) | ||
| { | ||
| $metadata->addPropertyConstraint('siblings', new Assert\GreaterThanOrEqual(5)); | ||
|
|
||
| $metadata->addPropertyConstraint('age', new Assert\GreaterThanOrEqual(array( | ||
| 'value' => 18, | ||
| ))); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please leave a blank line before the list items. Otherwise, it will be displayed like this: