mirror of
https://github.com/Respect/Validation.git
synced 2024-06-27 17:50:13 +02:00
Filtering prototype improvements
This commit is contained in:
parent
15553b309d
commit
edb2d855ab
|
@ -4,10 +4,11 @@ namespace Respect\Validation\Rules;
|
|||
|
||||
use Respect\Validation\Exceptions\ValidationException;
|
||||
use Respect\Validation\Exceptions\ComponentException;
|
||||
use Respect\Validation\Filterable;
|
||||
use Respect\Validation\Validatable;
|
||||
use Respect\Validation\Validator;
|
||||
|
||||
abstract class AbstractComposite extends AbstractRule implements Validatable
|
||||
abstract class AbstractComposite extends AbstractRule implements Validatable, \Respect\Validation\Filterable
|
||||
{
|
||||
|
||||
protected $rules = array();
|
||||
|
@ -27,6 +28,14 @@ abstract class AbstractComposite extends AbstractRule implements Validatable
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function filter($input)
|
||||
{
|
||||
foreach ($this->getRules() as $f)
|
||||
if ($f instanceof Filterable)
|
||||
$input = $f->filter($input);
|
||||
return $input;
|
||||
}
|
||||
|
||||
public function removeRules()
|
||||
{
|
||||
$this->rules = array();
|
||||
|
|
|
@ -2,9 +2,6 @@
|
|||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
use Respect\Validation\Validatable;
|
||||
use Respect\Validation\Filterable;
|
||||
|
||||
class AllOf extends AbstractComposite
|
||||
{
|
||||
|
||||
|
@ -26,23 +23,15 @@ class AllOf extends AbstractComposite
|
|||
public function check($input)
|
||||
{
|
||||
foreach ($this->getRules() as $v)
|
||||
if ($v instanceof Validatable && !$v->check($input))
|
||||
if (!$v->check($input))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function filter($input)
|
||||
{
|
||||
foreach ($this->getRules() as $f)
|
||||
if ($f instanceof Filterable)
|
||||
$input = $f->filter($input);
|
||||
return $input;
|
||||
}
|
||||
|
||||
public function validate($input)
|
||||
{
|
||||
foreach ($this->getRules() as $v)
|
||||
if ($v instanceof Validatable && !$v->validate($input))
|
||||
if (!$v->validate($input))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue