Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit030d05c

Browse files
committed
Added docs for LessThanOrEqual validator
1 parentfef0195 commit030d05c

File tree

4 files changed

+106
-9
lines changed

4 files changed

+106
-9
lines changed

‎reference/constraints.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Validation Constraints Reference
2626
constraints/IdenticalTo
2727
constraints/NotIdenticalTo
2828
constraints/LessThan
29+
constraints/LessThanOrEqual
2930

3031
constraints/Date
3132
constraints/DateTime

‎reference/constraints/LessThan.rst‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ LessThan
66

77
Validates that a value is less than another value, defined in the options. To
88
force that a value is less than or equal to another value, see
9-
:doc:`/reference/constraints/LessThanOrLessThan`. To force a value is greater
9+
:doc:`/reference/constraints/LessThanOrEqual`. To force a value is greater
1010
than another value, see:doc:`/reference/constraints/GreaterThan`.
1111

12-
+----------------+-----------------------------------------------------------------------+
13-
| Applies to|:ref:`property or method<validation-property-target>`|
14-
+----------------+-----------------------------------------------------------------------+
15-
| Options| - `value`_|
16-
|| - `message`_|
17-
+----------------+-----------------------------------------------------------------------+
12+
+----------------+------------------------------------------------------------------------+
13+
| Applies to|:ref:`property or method<validation-property-target>`|
14+
+----------------+------------------------------------------------------------------------+
15+
| Options| - `value`_|
16+
|| - `message`_|
17+
+----------------+------------------------------------------------------------------------+
1818
| Class|:class:`Symfony\\Component\\Validator\\Constraints\\LessThan`|
19-
+----------------+-----------------------------------------------------------------------+
19+
+----------------+------------------------------------------------------------------------+
2020
| Validator|:class:`Symfony\\Component\\Validator\\Constraints\\LessThanValidator`|
21-
+----------------+-----------------------------------------------------------------------+
21+
+----------------+------------------------------------------------------------------------+
2222

2323
Basic Usage
2424
-----------
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
LessThanOrEqual
2+
===============
3+
4+
..versionadded::2.3
5+
This constraint is new in version 2.3.
6+
7+
Validates that a value is less than or equal to another value, defined in the
8+
options. To force that a value is less than another value, see
9+
:doc:`/reference/constraints/LessThan`.
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\\LessThanOrEqual`|
18+
+----------------+-------------------------------------------------------------------------------+
19+
| Validator|:class:`Symfony\\Component\\Validator\\Constraints\\LessThanOrEqualValidator`|
20+
+----------------+-------------------------------------------------------------------------------+
21+
22+
Basic Usage
23+
-----------
24+
25+
If you want to ensure that the ``age`` of a ``Person`` class is less than or
26+
equal to ``80``, 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+
-LessThanOrEqual:
37+
value:80
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\LessThanOrEqual(
50+
* value = 80
51+
* )
52+
*/
53+
protected $age;
54+
}
55+
56+
..code-block::xml
57+
58+
<!-- src/Acme/SocialBundle/Resources/config/validation.xml-->
59+
<classname="Acme\SocialBundle\Entity\Person">
60+
<propertyname="age">
61+
<constraintname="LessThanOrEqual">
62+
<optionname="value">80</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\LessThanOrEqual(array(
80+
'value' => 80,
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 less 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‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Comparison Constraints
3434
* :doc:`IdenticalTo</reference/constraints/IdenticalTo>`
3535
* :doc:`NotIdenticalTo</reference/constraints/NotIdenticalTo>`
3636
* :doc:`LessThan</reference/constraints/LessThan>`
37+
* :doc:`LessThanOrEqual</reference/constraints/LessThanOrEqual>`
3738

3839
Date Constraints
3940
~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp