Refactor Validators.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
f85bc047b8
commit
b43759f3f4
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Validation\Validators;
|
||||||
|
use App\Models\Validation\Validators\Validator;
|
||||||
|
|
||||||
|
abstract class NextValidator extends Validator {
|
||||||
|
protected Validator $nextValidator;
|
||||||
|
|
||||||
|
public function setNextValidator(Validator $validator): void
|
||||||
|
{
|
||||||
|
$this->nextValidator = $validator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNextValidator(): Validator
|
||||||
|
{
|
||||||
|
return $this->nextValidator;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract public function isCurrentValid(): bool;
|
||||||
|
|
||||||
|
public function isValid(): bool
|
||||||
|
{
|
||||||
|
return $this->isCurrentValid() && $this->getNextValidator()->isValid();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Validation\Validators;
|
||||||
|
|
||||||
|
use App\Models\Validation\Validators\NextValidator;
|
||||||
|
|
||||||
|
abstract class NextValidatorByName extends NextValidator {
|
||||||
|
private string $name;
|
||||||
|
|
||||||
|
public function __construct(string $name, Validator $nextValidator)
|
||||||
|
{
|
||||||
|
$this->setName($name);
|
||||||
|
$this->setNextValidator($nextValidator);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName(string $name): void
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName(): string
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract public function isCurrentValid(): bool;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in new issue