10000 [Validator] add is_array check for options · symfony/symfony@c377749 · GitHub
[go: up one dir, main page]

Skip to content

Commit c377749

Browse files
committed
[Validator] add is_array check for options
1 parent 6f7878e commit c377749

File tree

4 files changed

+44
-20
lines changed

4 files changed

+44
-20
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,21 @@ class Negative extends LessThan
2525

2626
public function __construct($options = null)
2727
{
28-
if (isset($options['propertyPath'])) {
29-
throw new ConstraintDefinitionException(sprintf('The "propertyPath" option of the "%s" constraint cannot be set.', \get_class($this)));
28+
if (null === $options) {
29+
$options = array();
3030
}
3131

32-
if (isset($options['value'])) {
33-
throw new ConstraintDefinitionException(sprintf('The "value" option of the "%s" constraint cannot be set.', \get_class($this)));
32+
if (\is_array($options)) {
33+
if (isset($options['propertyPath'])) {
34+
throw new ConstraintDefinitionException(sprintf('The "propertyPath" option of the "%s" constraint cannot be set.', \get_class($this)));
35+
}
36+
37+
if (isset($options['value'])) {
38+
throw new ConstraintDefinitionException(sprintf('The "value" option of the "%s" constraint cannot be set.', \get_class($this)));
39+
}
3440
}
3541

36-
parent::__construct(array_merge((array) $options, array('value' => 0)));
42+
parent::__construct($options = array_merge((array) $options, array('value' => 0)));
3743
}
3844

3945
public function validatedBy()

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,21 @@ class NegativeOrZero extends LessThanOrEqual
2525

2626
public function __construct($options = null)
2727
{
28-
if (isset($options['propertyPath'])) {
29-
throw new ConstraintDefinitionException(sprintf('The "propertyPath" option of the "%s" constraint cannot be set.', \get_class($this)));
28+
if (null === $options) {
29+
$options = array();
3030
}
3131

32-
if (isset($options['value'])) {
33-
throw new ConstraintDefinitionException(sprintf('The "value" option of the "%s" constraint cannot be set.', \get_class($this)));
32+
if (\is_array($options)) {
33+
if (isset($options['propertyPath'])) {
34+
throw new ConstraintDefinitionException(sprintf('The "propertyPath" option of the "%s" constraint cannot be set.', \get_class($this)));
35+
}
36+
37+
if (isset($options['value'])) {
38+
throw new ConstraintDefinitionException(sprintf('The "value" option of the "%s" constraint cannot be set.', \get_class($this)));
39+
}
3440
}
3541

36-
parent::__construct(array_merge((array) $options, array('value' => 0)));
42+
parent::__construct($options = array_merge((array) $options, array('value' => 0)));
3743
}
3844

3945
public function validatedBy()

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,21 @@ class Positive extends GreaterThan
2525

2626
public function __construct($options = null)
2727
{
28-
if (isset($options['propertyPath'])) {
29-
throw new ConstraintDefinitionException(sprintf('The "propertyPath" option of the "%s" constraint cannot be set.', \get_class($this)));
28+
if (null === $options) {
29+
$options = array();
3030
}
3131

32-
if (isset($options['value'])) {
33-
throw new ConstraintDefinitionException(sprintf('The "value" option of the "%s" constraint cannot be set.', \get_class($this)));
32+
if (\is_array($options)) {
33+
if (isset($options['propertyPath'])) {
34+
throw new ConstraintDefinitionException(sprintf('The "propertyPath" option of the "%s" constraint cannot be set.', \get_class($this)));
35+
}
36+
37+
if (isset($options['value'])) {
38+
throw new ConstraintDefinitionException(sprintf('The "value" option of the "%s" constraint cannot be set.', \get_class($this)));
39+
}
3440
}
3541

36-
parent::__construct(array_merge((array) $options, array('value' => 0)));
42+
parent::__construct($options = array_merge((array) $options, array('value' => 0)));
3743
}
3844

3945
public function validatedBy()

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,21 @@ class PositiveOrZero extends GreaterThanOrEqual
2525

2626
public function __construct($options = null)
2727
{
28-
if (isset($options['propertyPath'])) {
29-
throw new ConstraintDefinitionException(sprintf('The "propertyPath" option of the "%s" constraint cannot be set.', \get_class($this)));
28+
if (null === $options) {
29+
$options = array();
3030
}
3131

32-
if (isset($options['value'])) {
33-
throw new ConstraintDefinitionException(sprintf('The "value" option of the "%s" constraint cannot be set.', \get_class($this)));
32+
if (\is_array($options)) {
33+
if (isset($options['propertyPath'])) {
34+
throw new ConstraintDefinitionException(sprintf('The "propertyPath" option of the "%s" constraint cannot be set.', \get_class($this)));
35+
}
36+
37+
if (isset($options['value'])) {
38+
throw new ConstraintDefinitionException(sprintf('The "value" option of the "%s" constraint cannot be set.', \get_class($this)));
39+
}
3440
}
3541

36-
parent::__construct(array_merge((array) $options, array('value' => 0)));
42+
parent::__construct($options = array_merge((array) $options, array('value' => 0)));
3743
}
3844

3945
public function validatedBy()

0 commit comments

Comments
 (0)
0