Executable.php 762 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /*
  3. * Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
  4. * SPDX-License-Identifier: MIT
  5. */
  6. declare(strict_types=1);
  7. namespace Respect\Validation\Rules;
  8. use SplFileInfo;
  9. use function is_executable;
  10. use function is_scalar;
  11. /**
  12. * Validates if a file is an executable.
  13. *
  14. * @author Henrique Moody <henriquemoody@gmail.com>
  15. * @author William Espindola <oi@williamespindola.com.br>
  16. */
  17. final class Executable extends AbstractRule
  18. {
  19. /**
  20. * {@inheritDoc}
  21. */
  22. public function validate($input): bool
  23. {
  24. if ($input instanceof SplFileInfo) {
  25. return $input->isExecutable();
  26. }
  27. if (!is_scalar($input)) {
  28. return false;
  29. }
  30. return is_executable((string) $input);
  31. }
  32. }