mirror of
https://github.com/Respect/Validation.git
synced 2026-03-16 23:35:45 +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>
36 lines
709 B
PHP
36 lines
709 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 SplFileInfo;
|
|
|
|
use function is_executable;
|
|
use function is_scalar;
|
|
|
|
#[Template(
|
|
'{{name}} must be an executable file',
|
|
'{{name}} must not be an executable file',
|
|
)]
|
|
final class Executable extends Simple
|
|
{
|
|
public function validate(mixed $input): bool
|
|
{
|
|
if ($input instanceof SplFileInfo) {
|
|
return $input->isExecutable();
|
|
}
|
|
|
|
if (!is_scalar($input)) {
|
|
return false;
|
|
}
|
|
|
|
return is_executable((string) $input);
|
|
}
|
|
}
|