yaml-lint 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env php
  2. <?php
  3. /*
  4. * This file is part of the Symfony package.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. if ('cli' !== \PHP_SAPI) {
  12. throw new Exception('This script must be run from the command line.');
  13. }
  14. /**
  15. * Runs the Yaml lint command.
  16. *
  17. * @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
  18. */
  19. use Symfony\Component\Console\Application;
  20. use Symfony\Component\Yaml\Command\LintCommand;
  21. function includeIfExists(string $file): bool
  22. {
  23. return file_exists($file) && include $file;
  24. }
  25. if (
  26. !includeIfExists(__DIR__ . '/../../../../autoload.php') &&
  27. !includeIfExists(__DIR__ . '/../../vendor/autoload.php') &&
  28. !includeIfExists(__DIR__ . '/../../../../../../vendor/autoload.php')
  29. ) {
  30. fwrite(STDERR, 'Install dependencies using Composer.'.PHP_EOL);
  31. exit(1);
  32. }
  33. if (!class_exists(Application::class)) {
  34. fwrite(STDERR, 'You need the "symfony/console" component in order to run the Yaml linter.'.PHP_EOL);
  35. exit(1);
  36. }
  37. (new Application())->add($command = new LintCommand())
  38. ->getApplication()
  39. ->setDefaultCommand($command->getName(), true)
  40. ->run()
  41. ;