File tree 5 files changed +53
-76
lines changed
src/Symfony/Component/Validator/Constraints
5 files changed +53
-76
lines changed Original file line number Diff line number Diff line change 11
11
12
12
namespace Symfony \Component \Validator \Constraints ;
13
13
14
- use Symfony \Component \Validator \Exception \ConstraintDefinitionException ;
15
-
16
14
/**
17
15
* @Annotation
18
16
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
21
19
*/
22
20
class Negative extends LessThan
23
21
{
22
+ use NumberConstraintTrait;
23
+
24
24
public $ message = 'This value should be negative. ' ;
25
25
26
26
public function __construct ($ options = null )
27
27
{
28
- if (null === $ options ) {
29
- $ options = [];
30
- } elseif (!\is_array ($ options )) {
31
- $ options = [$ this ->getDefaultOption () => $ options ];
32
- }
33
-
34
- if (isset ($ options ['propertyPath ' ])) {
35
- throw new ConstraintDefinitionException (sprintf ('The "propertyPath" option of the "%s" constraint cannot be set. ' , \get_class ($ this )));
36
- }
37
-
38
- if (isset ($ options ['value ' ])) {
39
- throw new ConstraintDefinitionException (sprintf ('The "value" option of the "%s" constraint cannot be set. ' , \get_class ($ this )));
40
- }
41
-
42
- $ options ['value ' ] = 0 ;
43
-
44
- parent ::__construct ($ options );
28
+ parent ::__construct ($ this ->configureNumbe
10000
rConstraintOptions ($ options ));
45
29
}
46
30
47
31
public function validatedBy (): string
Original file line number Diff line number Diff line change 11
11
12
12
namespace Symfony \Component \Validator \Constraints ;
13
13
14
- use Symfony \Component \Validator \Exception \ConstraintDefinitionException ;
15
-
16
14
/**
17
15
* @Annotation
18
16
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
21
19
*/
22
20
class NegativeOrZero extends LessThanOrEqual
23
21
{
22
+ use NumberConstraintTrait;
23
+
24
24
public $ message = 'This value should be either negative or zero. ' ;
25
25
26
26
public function __construct ($ options = null )
27
27
{
28
- if (null === $ options ) {
29
- $ options = [];
30
- } elseif (!\is_array ($ options )) {
31
- $ options = [$ this ->getDefaultOption () => $ options ];
32
- }
33
-
34
- if (isset ($ options ['propertyPath ' ])) {
35
- throw new ConstraintDefinitionException (sprintf ('The "propertyPath" option of the "%s" constraint cannot be set. ' , \get_class ($ this )));
36
- }
37
-
38
- if (isset ($ options ['value ' ])) {
39
- throw new ConstraintDefinitionException (sprintf ('The "value" option of the "%s" constraint cannot be set. ' , \get_class ($ this )));
40
- }
41
-
42
- $ options ['value ' ] = 0 ;
43
-
44
- parent ::__construct ($ options );
28
+ parent ::__construct ($ this ->configureNumberConstraintOptions ($ options ));
45
29
}
46
30
47
31
public function validatedBy (): string
Original file line number Diff line number Diff line change
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
+ namespace Symfony \Component \Validator \Constraints ;
13
+
14
+ use Symfony \Component \Validator \Exception \ConstraintDefinitionException ;
15
+
16
+ /**
17
+ * @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
18
+ */
19
+ trait NumberConstraintTrait
20
+ {
21
+ private function configureNumberConstraintOptions ($ options ): array
22
+ {
23
+ if (null === $ options ) {
24
+ $ options = [];
25
+ } elseif (!\is_array ($ options )) {
26
+ $ options = [$ this ->getDefaultOption () => $ options ];
27
+ }
28
+
29
+ if (isset ($ options ['propertyPath ' ])) {
30
+ throw new ConstraintDefinitionException (sprintf ('The "propertyPath" option of the "%s" constraint cannot be set. ' , \get_class ($ this )));
31
+ }
32
+
33
+ if (isset ($ options ['value ' ])) {
34
+ throw new ConstraintDefinitionException (sprintf ('The "value" option of the "%s" constraint cannot be set. ' , \get_class ($ this )));
35
+ }
36
+
37
+ $ options ['value ' ] = 0 ;
38
+
39
+ return $ options ;
40
+ }
41
+ }
Original file line number Diff line number Diff line change 11
11
12
12
namespace Symfony \Component \Validator \Constraints ;
13
13
14
- use Symfony \Component \Validator \Exception \ConstraintDefinitionException ;
15
-
16
14
/**
17
15
* @Annotation
18
16
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
21
19
*/
22
20
class Positive extends GreaterThan
23
21
{
22
+ use NumberConstraintTrait;
23
+
24
24
public $ message = 'This value should be positive. ' ;
25
25
26
26
public function __construct ($ options = null )
27
27
{
28
- if (null === $ options ) {
29
- $ options = [];
30
- } elseif (!\is_array ($ options )) {
31
- $ options = [$ this ->getDefaultOption () => $ options ];
32
- }
33
-
34
- if (isset ($ options ['propertyPath ' ])) {
35
- throw new ConstraintDefinitionException (sprintf ('The "propertyPath" option of the "%s" constraint cannot be set. ' , \get_class ($ this )));
36
- }
37
-
38
- if (isset ($ options ['value ' ])) {
39
- throw new ConstraintDefinitionException (sprintf ('The "value" option of the "%s" constraint cannot be set. ' , \get_class ($ this )));
40
- }
41
-
42
- $ options ['value ' ] = 0 ;
43
-
44
- parent ::__construct ($ options );
28
+ parent ::__construct ($ this ->configureNumberConstraintOptions ($ options ));
45
29
}
46
30
47
31
public function validatedBy (): string
Original file line number Diff line number Diff line change 11
11
12
12
namespace Symfony \Component \Validator \Constraints ;
13
13
14
- use Symfony \Component \Validator \Exception \ConstraintDefinitionException ;
15
-
16
14
/**
17
15
* @Annotation
18
16
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
21
19
*/
22
20
class PositiveOrZero extends GreaterThanOrEqual
23
21
{
22
+ use NumberConstraintTrait;
23
+
24
24
public $ message = 'This value should be either positive or zero. ' ;
25
25
26
26
public function __construct ($ options = null )
27
27
{
28
- if (null === $ options ) {
29
- $ options = [];
30
- } elseif (!\is_array ($ options )) {
31
- $ options = [$ this ->getDefaultOption () => $ options ];
32
- }
33
-
34
- if (isset ($ options ['propertyPath ' ])) {
35
- throw new ConstraintDefinitionException (sprintf ('The "propertyPath" option of the "%s" constraint cannot be set. ' , \get_class ($ this )));
36
- }
37
-
38
- if (isset ($ options ['value ' ])) {
39
- throw new ConstraintDefinitionException (sprintf ('The "value" option of the "%s" constraint cannot be set. ' , \get_class ($ this )));
40
- }
41
-
42
- $ options ['value ' ] = 0 ;
43
-
44
- parent ::__construct ($ options );
28
+ parent ::__construct ($ this ->configureNumberConstraintOptions ($ options ));
45
29
}
46
30
47
31
public function validatedBy (): string
You can’t perform that action at this time.
0 commit comments