LintCommand.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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\TwigBundle\Command;
  11. use Symfony\Bridge\Twig\Command\LintCommand as BaseLintCommand;
  12. use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  13. use Symfony\Component\DependencyInjection\ContainerAwareTrait;
  14. use Symfony\Component\Finder\Finder;
  15. /**
  16. * Command that will validate your template syntax and output encountered errors.
  17. *
  18. * @author Marc Weistroff <marc.weistroff@sensiolabs.com>
  19. * @author Jérôme Tamarelle <jerome@tamarelle.net>
  20. */
  21. final class LintCommand extends BaseLintCommand implements ContainerAwareInterface
  22. {
  23. use ContainerAwareTrait;
  24. /**
  25. * {@inheritdoc}
  26. */
  27. protected function getTwigEnvironment()
  28. {
  29. return $this->container->get('twig');
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. protected function configure()
  35. {
  36. parent::configure();
  37. $this
  38. ->setHelp(
  39. $this->getHelp().<<<'EOF'
  40. Or all template files in a bundle:
  41. <info>php %command.full_name% @AcmeDemoBundle</info>
  42. EOF
  43. )
  44. ;
  45. }
  46. protected function findFiles($filename)
  47. {
  48. if (0 === strpos($filename, '@')) {
  49. $dir = $this->getApplication()->getKernel()->locateResource($filename);
  50. return Finder::create()->files()->in($dir)->name('*.twig');
  51. }
  52. return parent::findFiles($filename);
  53. }
  54. }