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