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

Commitd2073e5

Browse files
committed
[Validator] add number constraints
-@positive- @PositiveOrZero-@Negative- @NegativeOrZero
1 parent8d277ce commitd2073e5

12 files changed

+636
-0
lines changed

‎src/Symfony/Component/Validator/CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ CHANGELOG
1515
* deprecated using the`Bic`,`Country`,`Currency`,`Language` and`Locale` constraints without`symfony/intl`
1616
* deprecated using the`Email` constraint without`egulias/email-validator`
1717
* deprecated using the`Expression` constraint without`symfony/expression-language`
18+
* deprecated using the`Bic` constraint without`symfony/intl`
19+
* added`Positive` constraint
20+
* added`PositiveOrZero` constraint
21+
* added`Negative` constraint
22+
* added`NegativeOrZero` constraint
1823

1924
4.1.0
2025
-----
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Validator\Constraints;
13+
14+
useSymfony\Component\Validator\Exception\ConstraintDefinitionException;
15+
16+
/**
17+
* @Annotation
18+
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
19+
*
20+
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
21+
*/
22+
class Negativeextends LessThan
23+
{
24+
public$message ='This value should be negative.';
25+
26+
publicfunction__construct($options =null)
27+
{
28+
if (null !==$options) {
29+
thrownewConstraintDefinitionException(sprintf('The "%s" constraint can not be configured via options.',\get_class($this)));
30+
}
31+
32+
$options =array('value' =>0);
33+
34+
parent::__construct($options);
35+
}
36+
37+
publicfunctionvalidatedBy()
38+
{
39+
return'LessThanValidator';
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Validator\Constraints;
13+
14+
useSymfony\Component\Validator\Exception\ConstraintDefinitionException;
15+
16+
/**
17+
* @Annotation
18+
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
19+
*
20+
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
21+
*/
22+
class NegativeOrZeroextends LessThanOrEqual
23+
{
24+
public$message ='This value should be either negative or zero.';
25+
26+
publicfunction__construct($options =null)
27+
{
28+
if (null !==$options) {
29+
thrownewConstraintDefinitionException(sprintf('The "%s" constraint can not be configured via options.',\get_class($this)));
30+
}
31+
32+
$options =array('value' =>0);
33+
34+
parent::__construct($options);
35+
}
36+
37+
publicfunctionvalidatedBy()
38+
{
39+
return'LessThanOrEqualValidator';
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Validator\Constraints;
13+
14+
useSymfony\Component\Validator\Exception\ConstraintDefinitionException;
15+
16+
/**
17+
* @Annotation
18+
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
19+
*
20+
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
21+
*/
22+
class Positiveextends GreaterThan
23+
{
24+
public$message ='This value should be positive.';
25+
26+
publicfunction__construct($options =null)
27+
{
28+
if (null !==$options) {
29+
thrownewConstraintDefinitionException(sprintf('The "%s" constraint can not be configured via options.',\get_class($this)));
30+
}
31+
32+
$options =array('value' =>0);
33+
34+
parent::__construct($options);
35+
}
36+
37+
publicfunctionvalidatedBy()
38+
{
39+
return'GreaterThanValidator';
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Validator\Constraints;
13+
14+
useSymfony\Component\Validator\Exception\ConstraintDefinitionException;
15+
16+
/**
17+
* @Annotation
18+
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
19+
*
20+
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
21+
*/
22+
class PositiveOrZeroextends GreaterThanOrEqual
23+
{
24+
public$message ='This value should be either positive or zero.';
25+
26+
publicfunction__construct($options =null)
27+
{
28+
if (null !==$options) {
29+
thrownewConstraintDefinitionException(sprintf('The "%s" constraint can not be configured via options.',\get_class($this)));
30+
}
31+
32+
$options =array('value' =>0);
33+
34+
parent::__construct($options);
35+
}
36+
37+
publicfunctionvalidatedBy()
38+
{
39+
return'GreaterThanOrEqualValidator';
40+
}
41+
}

‎src/Symfony/Component/Validator/Resources/translations/validators.de.xlf‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,22 @@
326326
<source>This value should be a multiple of {{ compared_value }}.</source>
327327
<target>Dieser Wert sollte ein Vielfaches von {{ compared_value }} sein.</target>
328328
</trans-unit>
329+
<trans-unitid="85">
330+
<source>This value should be positive.</source>
331+
<target>Dieser Wert sollte positiv sein.</target>
332+
</trans-unit>
333+
<trans-unitid="86">
334+
<source>This value should be either positive or zero.</source>
335+
<target>Dieser Wert sollte entweder positiv oder 0 sein.</target>
336+
</trans-unit>
337+
<trans-unitid="87">
338+
<source>This value should be negative.</source>
339+
<target>Dieser Wert sollte negativ sein.</target>
340+
</trans-unit>
341+
<trans-unitid="88">
342+
<source>This value should be either negative or zero.</source>
343+
<target>Dieser Wert sollte entweder negativ oder 0 sein.</target>
344+
</trans-unit>
329345
</body>
330346
</file>
331347
</xliff>

‎src/Symfony/Component/Validator/Resources/translations/validators.en.xlf‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,22 @@
326326
<source>This value should be a multiple of {{ compared_value }}.</source>
327327
<target>This value should be a multiple of {{ compared_value }}.</target>
328328
</trans-unit>
329+
<trans-unitid="85">
330+
<source>This value should be positive.</source>
331+
<target>This value should be positive.</target>
332+
</trans-unit>
333+
<trans-unitid="86">
334+
<source>This value should be either positive or zero.</source>
335+
<target>This value should be either positive or zero.</target>
336+
</trans-unit>
337+
<trans-unitid="87">
338+
<source>This value should be negative.</source>
339+
<target>This value should be negative.</target>
340+
</trans-unit>
341+
<trans-unitid="88">
342+
<source>This value should be either negative or zero.</source>
343+
<target>This value should be either negative or zero.</target>
344+
</trans-unit>
329345
</body>
330346
</file>
331347
</xliff>

‎src/Symfony/Component/Validator/Resources/translations/validators.vi.xlf‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,22 @@
278278
<source>This value should not be identical to {{ compared_value_type }} {{ compared_value }}.</source>
279279
<target>Giá trị không được phép giống như {{ compared_value_type }} {{ compared_value }}.</target>
280280
</trans-unit>
281+
<trans-unitid="85">
282+
<source>This value should be positive.</source>
283+
<target>Giá trị này có thể thực hiện được.</target>
284+
</trans-unit>
285+
<trans-unitid="86">
286+
<source>This value should be either positive or zero.</source>
287+
<target>Giá trị này có thể thực hiện được hoặc bằng không.</target>
288+
</trans-unit>
289+
<trans-unitid="87">
290+
<source>This value should be negative.</source>
291+
<target>Giá trị này nên bị từ chối.</target>
292+
</trans-unit>
293+
<trans-unitid="88">
294+
<source>This value should be either negative or zero.</source>
295+
<target>Giá trị này nên bị từ chối hoặc bằng không.</target>
296+
</trans-unit>
281297
</body>
282298
</file>
283299
</xliff>
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Validator\Tests\Constraints;
13+
14+
useSymfony\Component\Validator\Constraints\PositiveOrZero;
15+
16+
/**
17+
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
18+
*/
19+
class GreaterThanOrEqualValidatorWithPositiveOrZeroConstraintTestextends GreaterThanOrEqualValidatorTest
20+
{
21+
protectedfunctioncreateConstraint(array$options =null)
22+
{
23+
returnnewPositiveOrZero();
24+
}
25+
26+
/**
27+
* {@inheritdoc}
28+
*/
29+
publicfunctionprovideValidComparisons()
30+
{
31+
returnarray(
32+
array(0,0),
33+
array(1,0),
34+
array(2,0),
35+
array(2.5,0),
36+
array('0','0'),
37+
array('333','0'),
38+
array(null,0),
39+
);
40+
}
41+
42+
/**
43+
* {@inheritdoc}
44+
*/
45+
publicfunctionprovideInvalidComparisons()
46+
{
47+
returnarray(
48+
array(-1,'-1',0,'0','integer'),
49+
array(-2,'-2',0,'0','integer'),
50+
array(-2.5,'-2.5',0,'0','integer'),
51+
);
52+
}
53+
54+
/**
55+
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
56+
* @expectedExceptionMessage The "Symfony\Component\Validator\Constraints\PositiveOrZero" constraint can not be configured via options.
57+
*/
58+
publicfunctiontestThrowsConstraintDefinitionExceptionIfConfiguredViaOptions()
59+
{
60+
newPositiveOrZero(array('value' =>1));
61+
}
62+
63+
/**
64+
* @dataProvider provideInvalidConstraintOptions
65+
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
66+
* @expectedExceptionMessage requires either the "value" or "propertyPath" option to be set.
67+
*/
68+
publicfunctiontestThrowsConstraintExceptionIfNoValueOrPropertyPath($options)
69+
{
70+
$this->markTestSkipped('Value property always set for PositiveOrZero constraint');
71+
}
72+
73+
/**
74+
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
75+
* @expectedExceptionMessage requires only one of the "value" or "propertyPath" options to be set, not both.
76+
*/
77+
publicfunctiontestThrowsConstraintExceptionIfBothValueAndPropertyPath()
78+
{
79+
$this->markTestSkipped('Value property is set for PositiveOrZero constraint automatically');
80+
}
81+
82+
publicfunctiontestInvalidValuePath()
83+
{
84+
$this->markTestSkipped('PropertyPath property is not used in PositiveOrZero constraint');
85+
}
86+
87+
/**
88+
* @dataProvider provideValidComparisonsToPropertyPath
89+
*/
90+
publicfunctiontestValidComparisonToPropertyPath($comparedValue)
91+
{
92+
$this->markTestSkipped('PropertyPath property is not used in PositiveOrZero constraint');
93+
}
94+
95+
/**
96+
* @dataProvider provideValidComparisonsToPropertyPath
97+
*/
98+
publicfunctiontestValidComparisonToPropertyPathOnArray($comparedValue)
99+
{
100+
$this->markTestSkipped('PropertyPath property is not used in Positive constraint');
101+
}
102+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp