respect-validation/library/Rules/Executable.php

41 lines
762 B
PHP
Raw Normal View History

2014-08-28 05:34:17 +02:00
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
2014-08-28 05:34:17 +02:00
namespace Respect\Validation\Rules;
use SplFileInfo;
use function is_executable;
use function is_scalar;
/**
* Validates if a file is an executable.
*
* @author Henrique Moody <henriquemoody@gmail.com>
* @author William Espindola <oi@williamespindola.com.br>
*/
final class Executable extends AbstractRule
2014-08-28 05:34:17 +02:00
{
/**
* {@inheritDoc}
*/
public function validate($input): bool
2014-08-28 05:34:17 +02:00
{
if ($input instanceof SplFileInfo) {
2014-08-28 05:34:17 +02:00
return $input->isExecutable();
}
if (!is_scalar($input)) {
return false;
}
return is_executable((string) $input);
2014-08-28 05:34:17 +02:00
}
}