This commit is contained in:
@@ -2,22 +2,13 @@
|
||||
|
||||
namespace App\Models\Validation\Validators;
|
||||
|
||||
use App\Models\Validation\Validators\Validator;
|
||||
use App\Models\Validation\Validators\NextValidatorByName;
|
||||
use App\Models\Company;
|
||||
|
||||
class CompanyValidatorByName extends Validator {
|
||||
private string $name;
|
||||
protected Validator $nextValidator;
|
||||
|
||||
public function __construct(string $name, Validator $nextValidator)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->nextValidator = $nextValidator;
|
||||
}
|
||||
|
||||
class CompanyValidatorByName extends NextValidatorByName {
|
||||
public function isCurrentValid(): bool
|
||||
{
|
||||
$count = Company::where('name', $this->name)->count();
|
||||
$count = Company::where('name', $this->getName())->count();
|
||||
|
||||
return $count != 0;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Models\Validation\Validators;
|
||||
|
||||
use App\Models\Validation\Validators\Validator;
|
||||
use App\Models\Validation\Validators\NextValidator;
|
||||
|
||||
class EmptyNameValidator extends Validator {
|
||||
class EmptyNameValidator extends NextValidator {
|
||||
private string $name;
|
||||
protected Validator $nextValidator;
|
||||
|
||||
|
||||
@@ -2,22 +2,13 @@
|
||||
|
||||
namespace App\Models\Validation\Validators;
|
||||
|
||||
use App\Models\Validation\Validators\Validator;
|
||||
use App\Models\Validation\Validators\NextValidatorByName;
|
||||
use App\Models\Item;
|
||||
|
||||
class ItemValidatorByName extends Validator {
|
||||
private string $name;
|
||||
protected Validator $nextValidator;
|
||||
|
||||
public function __construct(string $name, Validator $nextValidator)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->nextValidator = $nextValidator;
|
||||
}
|
||||
|
||||
class ItemValidatorByName extends NextValidatorByName {
|
||||
public function isCurrentValid(): bool
|
||||
{
|
||||
$count = Item::where('name', $this->name)->count();
|
||||
$count = Item::where('name', $this->getName())->count();
|
||||
|
||||
return $count != 0;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Models\Validation\Validators;
|
||||
|
||||
use App\Models\Validation\Validators\Validator;
|
||||
use App\Models\Validation\Validators\NextValidator;
|
||||
|
||||
class OkValidator extends Validator {
|
||||
class OkValidator extends NextValidator {
|
||||
public function isCurrentValid(): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Models\Validation\Validators;
|
||||
|
||||
use App\Models\Validation\Validators\Validator;
|
||||
use App\Models\Validation\Validators\NextValidator;
|
||||
|
||||
class UpperRangeValidator extends Validator {
|
||||
class UpperRangeValidator extends NextValidator {
|
||||
private int $value;
|
||||
private int $rangeLimit;
|
||||
protected Validator $nextValidator;
|
||||
|
||||
@@ -3,11 +3,6 @@
|
||||
namespace App\Models\Validation\Validators;
|
||||
|
||||
abstract class Validator {
|
||||
abstract public function isCurrentValid(): bool;
|
||||
|
||||
public function isValid(): bool
|
||||
{
|
||||
return $this->isCurrentValid() && $this->nextValidator->isValid();
|
||||
}
|
||||
abstract public function isValid(): bool;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user