[Ivan] - Validations - Implement decorator pattern [skip ci]

This commit is contained in:
Ivan Diaz 2016-06-22 00:21:03 -03:00
parent 6147fc260d
commit 407200878d
3 changed files with 14 additions and 6 deletions

View File

@ -4,7 +4,9 @@ require_once 'Validator.php';
class EmailValidator extends Validator {
public function validate($value, $fullData) {
if(strpos($value, '@') === false) {
parent::validate($value, $fullData);
if (strpos($value, '@') === false) {
Validator::throwException();
}
}

View File

@ -3,7 +3,7 @@ require_once 'Validator.php';
class PasswordValidator extends Validator {
public function validate($value, $fullData) {
public function validate($value, $fullData = []) {
parent::validate($value, $fullData);
}
}

View File

@ -6,9 +6,15 @@ class Validator {
throw new ValidationException($message);
}
public function validate($value) {
if (!$value) {
throw new ValidationException();
protected $baseValidator;
public function __construct(Validator $baseValidator = null) {
$this->baseValidator = $baseValidator;
}
public function validate($value, $fullData = []) {
if ($this->baseValidator) {
$this->baseValidator->validate($value, $fullData);
}
}
}