mirror of
https://github.com/Respect/Validation.git
synced 2024-06-28 18:20:07 +02:00
Merge branch '0.7' into 0.8
This commit is contained in:
commit
8ca24c2f84
|
@ -10,7 +10,7 @@ class Not extends AbstractRule
|
|||
|
||||
public function __construct(Validatable $rule)
|
||||
{
|
||||
if ($rule instanceof AbstractComposite) {
|
||||
if ($rule instanceof AllOff) {
|
||||
$rule = $this->absorbComposite($rule);
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ class Not extends AbstractRule
|
|||
|
||||
public function validate($input)
|
||||
{
|
||||
if ($this->rule instanceof AbstractComposite) {
|
||||
if ($this->rule instanceof AllOff) {
|
||||
return $this->rule->validate($input);
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ class Not extends AbstractRule
|
|||
|
||||
public function assert($input)
|
||||
{
|
||||
if ($this->rule instanceof AbstractComposite) {
|
||||
if ($this->rule instanceof AllOff) {
|
||||
return $this->rule->assert($input);
|
||||
}
|
||||
|
||||
|
@ -43,20 +43,23 @@ class Not extends AbstractRule
|
|||
->setMode(ValidationException::MODE_NEGATIVE);
|
||||
}
|
||||
|
||||
protected function absorbComposite(AbstractComposite $rule)
|
||||
protected function absorbComposite(AbstractComposite $compositeRule)
|
||||
{
|
||||
$clone = clone $rule;
|
||||
$rules = $clone->getRules();
|
||||
$clone->removeRules();
|
||||
if (!$compositeRule instanceof AllOff) {
|
||||
return $compositeRule;
|
||||
}
|
||||
|
||||
foreach ($rules as &$r) {
|
||||
if ($r instanceof AbstractComposite) {
|
||||
$clone->addRule($this->absorbComposite($r));
|
||||
$compositeRuleClone = clone $compositeRule;
|
||||
$compositeRuleClone->removeRules();
|
||||
|
||||
foreach ($compositeRule->getRules() as $rule) {
|
||||
if ($rule instanceof AbstractComposite) {
|
||||
$compositeRuleClone->addRule($this->absorbComposite($rule));
|
||||
} else {
|
||||
$clone->addRule(new static($r));
|
||||
$compositeRuleClone->addRule(new static($rule));
|
||||
}
|
||||
}
|
||||
|
||||
return $clone;
|
||||
return $compositeRuleClone;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,12 @@ class NotTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
return array(
|
||||
array(new Int, 'aaa'),
|
||||
array(new AllOf(new NoWhitespace, new Digit), 'as df')
|
||||
array(new AllOf(new NoWhitespace(), new Digit()), 'as df'),
|
||||
array(new AllOf(new NoWhitespace(), new Digit()), '12 34'),
|
||||
array(new AllOf(new AllOf(new NoWhitespace(), new Digit())), '12 34'),
|
||||
array(new AllOf(new NoneOf(new Numeric(), new Int())), 13.37),
|
||||
array(new NoneOf(new Numeric(), new Int()), 13.37),
|
||||
array(Validator::noneOf(Validator::numeric(), Validator::int()), 13.37),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -51,7 +56,9 @@ class NotTest extends \PHPUnit_Framework_TestCase
|
|||
return array(
|
||||
array(new Int, ''),
|
||||
array(new Int, 123),
|
||||
array(new AllOf(new NoWhitespace, new Digit), '12 34')
|
||||
array(new AllOf(new OneOf(new Numeric(), new Int())), 13.37),
|
||||
array(new OneOf(new Numeric(), new Int()), 13.37),
|
||||
array(Validator::oneOf(Validator::numeric(), Validator::int()), 13.37),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue