mirror of
https://github.com/Respect/Validation.git
synced 2024-06-08 08:42:15 +02:00
Update the validation engine of the "NotEmpty" rule
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
d116086f49
commit
630e6ecb6d
|
@ -10,6 +10,8 @@ declare(strict_types=1);
|
|||
namespace Respect\Validation\Rules;
|
||||
|
||||
use Respect\Validation\Message\Template;
|
||||
use Respect\Validation\Result;
|
||||
use Respect\Validation\Rules\Core\Standard;
|
||||
|
||||
use function is_string;
|
||||
use function trim;
|
||||
|
@ -24,25 +26,17 @@ use function trim;
|
|||
'{{name}} must be empty',
|
||||
self::TEMPLATE_NAMED,
|
||||
)]
|
||||
final class NotEmpty extends AbstractRule
|
||||
final class NotEmpty extends Standard
|
||||
{
|
||||
public const TEMPLATE_NAMED = '__named__';
|
||||
|
||||
public function validate(mixed $input): bool
|
||||
public function evaluate(mixed $input): Result
|
||||
{
|
||||
$template = $input || $this->getName() ? self::TEMPLATE_NAMED : self::TEMPLATE_STANDARD;
|
||||
if (is_string($input)) {
|
||||
$input = trim($input);
|
||||
}
|
||||
|
||||
return !empty($input);
|
||||
}
|
||||
|
||||
protected function getStandardTemplate(mixed $input): string
|
||||
{
|
||||
if ($input || $this->getName()) {
|
||||
return self::TEMPLATE_NAMED;
|
||||
}
|
||||
|
||||
return self::TEMPLATE_STANDARD;
|
||||
return new Result(!empty($input), $input, $this, [], $template);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue