YamlLintCommand.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\FrameworkBundle\Command;
  11. use Symfony\Component\Yaml\Command\LintCommand as BaseLintCommand;
  12. /**
  13. * Validates YAML files syntax and outputs encountered errors.
  14. *
  15. * @author Grégoire Pineau <lyrixx@lyrixx.info>
  16. * @author Robin Chalas <robin.chalas@gmail.com>
  17. *
  18. * @final
  19. */
  20. class YamlLintCommand extends BaseLintCommand
  21. {
  22. protected static $defaultName = 'lint:yaml';
  23. public function __construct()
  24. {
  25. $directoryIteratorProvider = function ($directory, $default) {
  26. if (!is_dir($directory)) {
  27. $directory = $this->getApplication()->getKernel()->locateResource($directory);
  28. }
  29. return $default($directory);
  30. };
  31. $isReadableProvider = function ($fileOrDirectory, $default) {
  32. return 0 === strpos($fileOrDirectory, '@') || $default($fileOrDirectory);
  33. };
  34. parent::__construct(null, $directoryIteratorProvider, $isReadableProvider);
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. protected function configure()
  40. {
  41. parent::configure();
  42. $this->setHelp($this->getHelp().<<<'EOF'
  43. Or find all files in a bundle:
  44. <info>php %command.full_name% @AcmeDemoBundle</info>
  45. EOF
  46. );
  47. }
  48. }