respect-validation/library/Rules/NotEmpty.php
Henrique Moody 0066786fa7
Remove deprecated methods check() and validate()
We want to release version 3.0 as fresh as possible, without having to
maintain backward compatibility with the previous versions.

Acked-by: Alexandre Gomes Gaigalas <alganet@gmail.com>
2025-12-18 17:29:02 +01:00

35 lines
721 B
PHP

<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Rules;
use Attribute;
use Respect\Validation\Message\Template;
use Respect\Validation\Result;
use Respect\Validation\Rule;
use function is_string;
use function trim;
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
#[Template(
'{{name}} must not be empty',
'{{name}} must be empty',
)]
final class NotEmpty implements Rule
{
public function evaluate(mixed $input): Result
{
if (is_string($input)) {
$input = trim($input);
}
return new Result(!empty($input), $input, $this);
}
}