Exists.php 652 B

12345678910111213141516171819202122232425262728293031323334
  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 file_exists;
  10. use function is_string;
  11. /**
  12. * @author Henrique Moody <henriquemoody@gmail.com>
  13. * @author William Espindola <oi@williamespindola.com.br>
  14. */
  15. final class Exists extends AbstractRule
  16. {
  17. /**
  18. * {@inheritDoc}
  19. */
  20. public function validate($input): bool
  21. {
  22. if ($input instanceof SplFileInfo) {
  23. $input = $input->getPathname();
  24. }
  25. return is_string($input) && file_exists($input);
  26. }
  27. }