Skip to content

Commit 63fa241

Browse files
committed
[VarDumper] Draft: Positive*/Negative* constraint extends GreaterThan*/LessThan* constraint
1 parent c234619 commit 63fa241

16 files changed

+196
-671
lines changed

src/Symfony/Component/Validator/Constraints/Negative.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,27 @@
1111

1212
namespace Symfony\Component\Validator\Constraints;
1313

14-
use Symfony\Component\Validator\Constraint;
15-
1614
/**
1715
* @Annotation
1816
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
1917
*
2018
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
2119
*/
22-
class Negative extends Constraint
20+
class Negative extends LessThan
2321
{
24-
const IS_POSITIVE_ERROR = '50430dfd-503a-4451-a9b6-3eb348a1d777';
25-
const IS_ZERO_ERROR = '5013ce74-a117-42d9-84ec-f076f52a6179';
22+
public $message = 'This value should be negative.';
2623

27-
protected static $errorNames = array(
28-
self::IS_POSITIVE_ERROR => 'IS_POSITIVE_ERROR',
29-
self::IS_ZERO_ERROR => 'IS_ZERO_ERROR',
30-
);
24+
public function __construct(array $options = null)
25+
{
26+
if (empty($options)) {
27+
$options = array('value' => 0);
28+
}
3129

32-
public $message = 'This value should be negative.';
30+
parent::__construct($options);
31+
}
32+
33+
public function validatedBy()
34+
{
35+
return 'LessThanValidator';
36+
}
3337
}

src/Symfony/Component/Validator/Constraints/NegativeOrZero.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,27 @@
1111

1212
namespace Symfony\Component\Validator\Constraints;
1313

14-
use Symfony\Component\Validator\Constraint;
15-
1614
/**
1715
* @Annotation
1816
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
1917
*
2018
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
2119
*/
22-
class NegativeOrZero extends Constraint
20+
class NegativeOrZero extends LessThanOrEqual
2321
{
24-
const IS_POSITIVE_ERROR = '7b17bb87-4fce-4817-8167-3bb039dcae8e';
22+
public $message = 'This value should be either negative or zero.';
2523

26-
protected static $errorNames = array(
27-
self::IS_POSITIVE_ERROR => 'IS_POSITIVE_ERROR',
28-
);
24+
public function __construct(array $options = null)
25+
{
26+
if (empty($options)) {
27+
$options = array('value' => 0);
28+
}
2929

30-
public $message = 'This value should be either negative or zero.';
30+
parent::__construct($options);
31+
}
32+
33+
public function validatedBy()
34+
{
35+
return 'LessThanOrEqualValidator';
36+
}
3137
}

src/Symfony/Component/Validator/Constraints/NegativeOrZeroValidator.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/Symfony/Component/Validator/Constraints/NegativeValidator.php

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/Symfony/Component/Validator/Constraints/Positive.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,21 @@
1717
*
1818
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
1919
*/
20-
class Positive extends AbstractComparison
20+
class Positive extends GreaterThan
2121
{
22-
const IS_NEGATIVE_ERROR = 'da93d4fe-371c-4bc2-99a3-9201efe7e1a4';
22+
public $message = 'This value should be positive.';
2323

24-
protected static $errorNames = array(
25-
self::IS_NEGATIVE_ERROR => 'IS_NEGATIVE_ERROR',
26-
);
24+
public function __construct(array $options = null)
25+
{
26+
if (empty($options)) {
27+
$options = array('value' => 0);
28+
}
2729

28-
public $message = 'This value should be positive.';
30+
parent::__construct($options);
31+
}
32+
33+
public function validatedBy()
34+
{
35+
return 'GreaterThanValidator';
36+
}
2937
}

src/Symfony/Component/Validator/Constraints/PositiveOrZero.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,27 @@
1111

1212
namespace Symfony\Component\Validator\Constraints;
1313

14-
use Symfony\Component\Validator\Constraint;
15-
1614
/**
1715
* @Annotation
1816
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
1917
*
2018
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
2119
*/
22-
class PositiveOrZero extends Constraint
20+
class PositiveOrZero extends GreaterThanOrEqual
2321
{
24-
const IS_NEGATIVE_ERROR = 'd3b156b2-a386-4113-96be-76947bc7f16a';
22+
public $message = 'This value should be either positive or zero.';
2523

26-
protected static $errorNames = array(
27-
self::IS_NEGATIVE_ERROR => 'IS_NEGATIVE_ERROR',
28-
);
24+
public function __construct(array $options = null)
25+
{
26+
if (empty($options)) {
27+
$options = array('value' => 0);
28+
}
2929

30-
public $message = 'This value should be either positive or zero.';
30+
parent::__construct($options);
31+
}
32+
33+
public function validatedBy()
34+
{
35+
return 'GreaterThanOrEqualValidator';
36+
}
3137
}

src/Symfony/Component/Validator/Constraints/PositiveOrZeroValidator.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/Symfony/Component/Validator/Constraints/PositiveValidator.php

Lines changed: 0 additions & 59 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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\Tests\Constraints;
13+
14+
use Symfony\Component\Validator\Constraints\PositiveOrZero;
15+
16+
/**
17+
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
18+
*/
19+
class GreaterThanOrEqualValidatorWithPositiveOrZeroConstraintTest extends GreaterThanOrEqualValidatorTest
20+
{
21+
protected function createConstraint(array $options = null)
22+
{
23+
return new PositiveOrZero($options);
24+
}
25+
26+
/**
27+
* @dataProvider provideInvalidConstraintOptions
28+
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
29+
* @expectedExceptionMessage requires either the "value" or "propertyPath" option to be set.
30+
*/
31+
public function testThrowsConstraintExceptionIfNoValueOrPropertyPath($options)
32+
{
33+
$this->markTestSkipped('value property always set for PositiveOrZero constraint');
34+
}
35+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy