This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Messages;
|
||||
|
||||
use App\Models\Validation\Validators\Validator;
|
||||
|
||||
abstract class InformativeValidator extends Validator {
|
||||
protected Validator $validator;
|
||||
protected string $message;
|
||||
|
||||
public function isCurrentValid(): bool
|
||||
{
|
||||
return $this->validator->isCurrentValid();
|
||||
}
|
||||
|
||||
public function isValid(): bool
|
||||
{
|
||||
return $this->validator->isValid();
|
||||
}
|
||||
|
||||
public function setValidator($validator): void
|
||||
{
|
||||
$this->validator = $validator;
|
||||
}
|
||||
|
||||
public function setMessage($message): void
|
||||
{
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
public function getMessage(): string
|
||||
{
|
||||
if(!$this->isCurrentValid())
|
||||
return $this->message;
|
||||
|
||||
return $this->nextValidator->getMessage();
|
||||
}
|
||||
|
||||
public function okStatus(): array
|
||||
{
|
||||
if(!$this->isCurrentValid())
|
||||
return ['error' => $this->message];
|
||||
|
||||
return $this->nextValidator->okStatus();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Messages;
|
||||
|
||||
use App\Models\Validation\Messages\InformativeValidator;
|
||||
use App\Models\Validation\Validators\OkValidator;
|
||||
|
||||
class OkInformativeValidator extends InformativeValidator {
|
||||
public function __construct($message)
|
||||
{
|
||||
$this->message = $message;
|
||||
$this->validator = new OkValidator();
|
||||
}
|
||||
|
||||
public function getMessage(): string
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
public function okStatus(): array
|
||||
{
|
||||
return ['ok' => $this->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Messages;
|
||||
|
||||
use App\Models\Validation\Messages\InformativeValidator;
|
||||
use App\Models\Validation\Validators\UpperRangeValidator;
|
||||
|
||||
class UpperRangeInformativeValidator extends InformativeValidator {
|
||||
protected InformativeValidator $nextValidator;
|
||||
|
||||
public function __construct(string $message, UpperRangeValidator $validator, InformativeValidator $nextValidator)
|
||||
{
|
||||
$this->setMessage($message);
|
||||
$this->setValidator($validator);
|
||||
$this->nextValidator = $nextValidator;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user