|
| 1 | +#!/usr/bin/env php |
| 2 | +<?php |
| 3 | + |
| 4 | +/* |
| 5 | + * This file is part of the Symfony package. |
| 6 | + * |
| 7 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 8 | + * |
| 9 | + * For the full copyright and license information, please view the LICENSE |
| 10 | + * file that was distributed with this source code. |
| 11 | + */ |
| 12 | + |
| 13 | +/** |
| 14 | + * Runs the Yaml lint command. |
| 15 | + * |
| 16 | + * @author Jan Schädlich <jan.schaedlich@sensiolabs.de> |
| 17 | + */ |
| 18 | + |
| 19 | +use Psr\Log\LoggerInterface; |
| 20 | +use Symfony\Component\Console\Application; |
| 21 | +use Symfony\Component\Console\Input\ArgvInput; |
| 22 | +use Symfony\Component\Console\Logger\ConsoleLogger; |
| 23 | +use Symfony\Component\Console\Output\ConsoleOutput; |
| 24 | +use Symfony\Component\Yaml\Command\LintCommand; |
| 25 | + |
| 26 | +function includeIfExists(string $file): bool |
| 27 | +{ |
| 28 | + return file_exists($file) && include $file; |
| 29 | +} |
| 30 | + |
| 31 | +if ( |
| 32 | + !includeIfExists(__DIR__ . '/../../../../autoload.php') && |
| 33 | + !includeIfExists(__DIR__ . '/../../vendor/autoload.php') && |
| 34 | + !includeIfExists(__DIR__ . '/../../../../../../vendor/autoload.php') |
| 35 | +) { |
| 36 | + fwrite(STDERR, 'Install dependencies using Composer.'.PHP_EOL); |
| 37 | + exit(1); |
| 38 | +} |
| 39 | + |
| 40 | +if (!class_exists(Application::class)) { |
| 41 | + fwrite(STDERR, 'You need the "symfony/console" component in order to run the Yaml linter.'.PHP_EOL); |
| 42 | + exit(1); |
| 43 | +} |
| 44 | + |
| 45 | +$input = new ArgvInput(); |
| 46 | +$output = new ConsoleOutput(); |
| 47 | +$logger = interface_exists(LoggerInterface::class) ? new ConsoleLogger($output->getErrorOutput()) : null; |
| 48 | + |
| 49 | +$app = new Application(); |
| 50 | + |
| 51 | +$app->add($command = new LintCommand()) |
| 52 | + ->getApplication() |
| 53 | + ->setDefaultCommand($command->getName(), true) |
| 54 | + ->run($input, $output) |
| 55 | +; |
0 commit comments