respect-validation/library/Rules/When.php
Henrique Moody da193b75e0 Use PSR-2 standard
Most changes was made by php-cs-fixer.
Also removes unused `RecursiveTreeIterator` class.
2015-01-08 00:44:12 -02:00

45 lines
1,010 B
PHP

<?php
namespace Respect\Validation\Rules;
use Respect\Validation\Validatable;
class When extends AbstractRule
{
public $when;
public $then;
public $else;
public function __construct(Validatable $when, Validatable $then, Validatable $else)
{
$this->when = $when;
$this->then = $then;
$this->else = $else;
}
public function validate($input)
{
if ($this->when->validate($input)) {
return $this->then->validate($input);
} else {
return $this->else->validate($input);
}
}
public function assert($input)
{
if ($this->when->validate($input)) {
return $this->then->assert($input);
} else {
return $this->else->assert($input);
}
}
public function check($input)
{
if ($this->when->validate($input)) {
return $this->then->check($input);
} else {
return $this->else->check($input);
}
}
}