mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 15:50:03 +01:00
By "simple," I mean rules that have nothing in their constructor or that have simple templates. This change introduces two classes that will be the foundation for migrating all the rules to the newest validation engine: * Standard: this abstract rule contains only the accessors to define and retrieve names and templates, which means that the classes that extend it must implement the "evaluate()" method. * Simple: this abstract rule contains the "evaluate()" method, which relies on the "validate()" method, which means that the classes that extend it must implement that method. I expect many changes to the Simple abstract rule once all the rules get migrated to the newest validation engine. I've chosen to keep relying on the "validate()" method because it will make it easier to migrate everything. The "Standard" abstract rule uses a trait that triggers an "E_USER_DEPRECATED" error in every method from the old validation engine. That aims to support the migration because I can see clearly if any places still use the methods I would like to delete once I migrate everything. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
28 lines
572 B
PHP
28 lines
572 B
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
use Respect\Validation\Message\Template;
|
|
|
|
use function is_object;
|
|
use function is_scalar;
|
|
use function method_exists;
|
|
|
|
#[Template(
|
|
'{{name}} must be a string',
|
|
'{{name}} must not be string',
|
|
)]
|
|
final class StringVal extends Simple
|
|
{
|
|
public function validate(mixed $input): bool
|
|
{
|
|
return is_scalar($input) || (is_object($input) && method_exists($input, '__toString'));
|
|
}
|
|
}
|