From 8861f9c411ccecd022b775128928f4ce0ea87dcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Thu, 19 Dec 2013 23:11:11 +0100 Subject: [PATCH 01/12] Move the command "tiwg:lint" to the bridge --- .../Twig}/Command/LintCommand.php | 33 ++++++++++++++++--- .../TwigBundle/Resources/config/twig.xml | 6 ++++ 2 files changed, 34 insertions(+), 5 deletions(-) rename src/Symfony/{Bundle/TwigBundle => Bridge/Twig}/Command/LintCommand.php (86%) diff --git a/src/Symfony/Bundle/TwigBundle/Command/LintCommand.php b/src/Symfony/Bridge/Twig/Command/LintCommand.php similarity index 86% rename from src/Symfony/Bundle/TwigBundle/Command/LintCommand.php rename to src/Symfony/Bridge/Twig/Command/LintCommand.php index aa01ce6e7b0aa..aa3752d49a601 100644 --- a/src/Symfony/Bundle/TwigBundle/Command/LintCommand.php +++ b/src/Symfony/Bridge/Twig/Command/LintCommand.php @@ -9,20 +9,35 @@ * file that was distributed with this source code. */ -namespace Symfony\Bundle\TwigBundle\Command; +namespace Symfony\Bridge\Twig\Command; -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Finder\Finder; +use Symfony\Bundle\FrameworkBundle\Console\Application as FrameworkBundleApplication; /** * Command that will validate your template syntax and output encountered errors. * * @author Marc Weistroff */ -class LintCommand extends ContainerAwareCommand +class LintCommand extends Command { + private $twig; + + /** + * Constructor for dependency injection. + * + * @param \Twig_Environment $twig + */ + public function __construct(\Twig_Environment $twig) + { + $this->twig = $twig; + + parent::__construct(); + } + protected function configure() { $this @@ -57,7 +72,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { - $twig = $this->getContainer()->get('twig'); + $twig = $this->getTwig(); $template = null; $filename = $input->getArgument('filename'); @@ -82,7 +97,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $files = array($filename); } elseif (is_dir($filename)) { $files = Finder::create()->files()->in($filename)->name('*.twig'); - } else { + } elseif ($this->getApplication() instanceof FrameworkBundleApplication) { $dir = $this->getApplication()->getKernel()->locateResource($filename); $files = Finder::create()->files()->in($dir)->name('*.twig'); } @@ -148,4 +163,12 @@ protected function getContext($template, $line, $context = 3) return $result; } + + /** + * @return \Twig_Environment + */ + protected function getTwig() + { + return $this->twig; + } } diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml index 5efbe9d6d4f41..019b79005e584 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml @@ -25,6 +25,7 @@ Symfony\Bridge\Twig\Translation\TwigExtractor Symfony\Component\HttpKernel\EventListener\ExceptionListener Symfony\Bundle\TwigBundle\Controller\ExceptionController + Symfony\Bridge\Twig\Command\LintCommand @@ -131,5 +132,10 @@ %kernel.debug% + + + + + From b8bd4aa390afac307d854b7237c65dfaec648404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Tue, 24 Dec 2013 00:44:09 +0100 Subject: [PATCH 02/12] Updage changelog and minimum compatibility versions for moving command twig:lint --- src/Symfony/Bridge/Twig/CHANGELOG.md | 5 +++++ src/Symfony/Bundle/TwigBundle/CHANGELOG.md | 5 +++++ src/Symfony/Bundle/TwigBundle/composer.json | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Twig/CHANGELOG.md b/src/Symfony/Bridge/Twig/CHANGELOG.md index 346d52a5ad41e..da302abaa04d8 100644 --- a/src/Symfony/Bridge/Twig/CHANGELOG.md +++ b/src/Symfony/Bridge/Twig/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +2.5.0 +----- + + * added command `twig:lint` from `TwigBundle` + 2.4.0 ----- diff --git a/src/Symfony/Bundle/TwigBundle/CHANGELOG.md b/src/Symfony/Bundle/TwigBundle/CHANGELOG.md index de36165b56c12..b8a21a5812ad9 100644 --- a/src/Symfony/Bundle/TwigBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/TwigBundle/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +2.5.0 +----- + + * moved `LintCommand` to the Twig bridge and register it as a service + 2.3.0 ----- diff --git a/src/Symfony/Bundle/TwigBundle/composer.json b/src/Symfony/Bundle/TwigBundle/composer.json index 83b8285d5674c..88d866989ad20 100644 --- a/src/Symfony/Bundle/TwigBundle/composer.json +++ b/src/Symfony/Bundle/TwigBundle/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": ">=5.3.3", - "symfony/twig-bridge": "~2.2", + "symfony/twig-bridge": "~2.5", "symfony/http-kernel": "~2.1" }, "require-dev": { From 1124bb602fdd90d123c3c38db23bd547f05c8253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Tue, 24 Dec 2013 12:37:58 +0100 Subject: [PATCH 03/12] Test command twig:lint --- .../Twig/Tests/Command/LintCommandTest.php | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/Symfony/Bridge/Twig/Tests/Command/LintCommandTest.php diff --git a/src/Symfony/Bridge/Twig/Tests/Command/LintCommandTest.php b/src/Symfony/Bridge/Twig/Tests/Command/LintCommandTest.php new file mode 100644 index 0000000000000..3ba4ac49fac4c --- /dev/null +++ b/src/Symfony/Bridge/Twig/Tests/Command/LintCommandTest.php @@ -0,0 +1,99 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\Twig\Tests\Command; + +use Symfony\Component\Console\Tester\CommandTester; +use Symfony\Component\Console\Application; +use Symfony\Bridge\Twig\Command\LintCommand; + +/** + * @covers \Symfony\Bridge\Twig\Command\LintCommand + */ +class LintCommandTest extends \PHPUnit_Framework_TestCase +{ + private $files; + + public function testLintCorrectFile() + { + $tester = $this->createCommandTester(); + $filename = $this->createFile('{{ foo }}'); + + $ret = $tester->execute(array('filename' => $filename)); + + $this->assertEquals(0, $ret, 'Returns 0 in case of success'); + $this->assertRegExp('/^OK in /', $tester->getDisplay()); + } + + public function testLintIncorrectFile() + { + $tester = $this->createCommandTester(); + $filename = $this->createFile('{{ foo'); + + $ret = $tester->execute(array('filename' => $filename)); + + $this->assertEquals(1, $ret, 'Returns 1 in case of error'); + $this->assertRegExp('/^KO in /', $tester->getDisplay()); + } + + /** + * @expectedException \RuntimeException + */ + public function testLintFileNotReadable() + { + $tester = $this->createCommandTester(); + $filename = $this->createFile(''); + unlink($filename); + + $ret = $tester->execute(array('filename' => $filename)); + } + + /** + * @return CommandTester + */ + private function createCommandTester() + { + $twig = new \Twig_Environment(new \Twig_Loader_Filesystem()); + + $application = new Application(); + $application->add(new LintCommand($twig)); + $command = $application->find('twig:lint'); + + return new CommandTester($command); + } + + /** + * @return string Path to the new file + */ + private function createFile($content) + { + $filename = tempnam(sys_get_temp_dir(), 'sf-'); + file_put_contents($filename, $content); + + $this->files[] = $filename; + + return $filename; + } + + public function setUp() + { + $this->files = array(); + } + + public function tearDown() + { + foreach ($this->files as $file) { + if (file_exists($file)) { + unlink($file); + } + } + } +} From d500749f45b185410ed64e1251b474effbca3465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Tue, 24 Dec 2013 12:48:16 +0100 Subject: [PATCH 04/12] Removed getTwig for the command as it was unecessary --- src/Symfony/Bridge/Twig/Command/LintCommand.php | 13 ++----------- src/Symfony/Bundle/TwigBundle/CHANGELOG.md | 2 +- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Command/LintCommand.php b/src/Symfony/Bridge/Twig/Command/LintCommand.php index aa3752d49a601..f7d0398025670 100644 --- a/src/Symfony/Bridge/Twig/Command/LintCommand.php +++ b/src/Symfony/Bridge/Twig/Command/LintCommand.php @@ -72,7 +72,6 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { - $twig = $this->getTwig(); $template = null; $filename = $input->getArgument('filename'); @@ -85,7 +84,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $template .= fread(STDIN, 1024); } - return $this->validateTemplate($twig, $output, $template); + return $this->validateTemplate($this->twig, $output, $template); } if (0 !== strpos($filename, '@') && !is_readable($filename)) { @@ -104,7 +103,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $errors = 0; foreach ($files as $file) { - $errors += $this->validateTemplate($twig, $output, file_get_contents($file), $file); + $errors += $this->validateTemplate($this->twig, $output, file_get_contents($file), $file); } return $errors > 0 ? 1 : 0; @@ -163,12 +162,4 @@ protected function getContext($template, $line, $context = 3) return $result; } - - /** - * @return \Twig_Environment - */ - protected function getTwig() - { - return $this->twig; - } } diff --git a/src/Symfony/Bundle/TwigBundle/CHANGELOG.md b/src/Symfony/Bundle/TwigBundle/CHANGELOG.md index b8a21a5812ad9..aad8ce9314dc4 100644 --- a/src/Symfony/Bundle/TwigBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/TwigBundle/CHANGELOG.md @@ -4,7 +4,7 @@ CHANGELOG 2.5.0 ----- - * moved `LintCommand` to the Twig bridge and register it as a service + * moved `LintCommand` to the Twig bridge and registered it as a service 2.3.0 ----- From 678eddfe7337981ad44c1dcd093914082de7331b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Mon, 30 Dec 2013 00:55:05 +0100 Subject: [PATCH 05/12] Remove command as a service as it requires too many services to be initialized --- .../Bridge/Twig/Command/LintCommand.php | 17 ++++-- src/Symfony/Bundle/TwigBundle/CHANGELOG.md | 5 -- .../Bundle/TwigBundle/Command/LintCommand.php | 52 +++++++++++++++++++ .../TwigBundle/Resources/config/twig.xml | 6 --- 4 files changed, 64 insertions(+), 16 deletions(-) create mode 100644 src/Symfony/Bundle/TwigBundle/Command/LintCommand.php diff --git a/src/Symfony/Bridge/Twig/Command/LintCommand.php b/src/Symfony/Bridge/Twig/Command/LintCommand.php index f7d0398025670..a93b7da4a552e 100644 --- a/src/Symfony/Bridge/Twig/Command/LintCommand.php +++ b/src/Symfony/Bridge/Twig/Command/LintCommand.php @@ -27,15 +27,21 @@ class LintCommand extends Command private $twig; /** - * Constructor for dependency injection. + * Sets the twig environment * * @param \Twig_Environment $twig */ - public function __construct(\Twig_Environment $twig) + public function setTwigEnvironment(\Twig_Environment $twig) { $this->twig = $twig; + } - parent::__construct(); + /** + * @return \Twig_Environment $twig + */ + protected function getTwigEnvironment() + { + return $this->twig; } protected function configure() @@ -72,6 +78,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { + $twig = $this->getTwigEnvironment(); $template = null; $filename = $input->getArgument('filename'); @@ -84,7 +91,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $template .= fread(STDIN, 1024); } - return $this->validateTemplate($this->twig, $output, $template); + return $this->validateTemplate($twig, $output, $template); } if (0 !== strpos($filename, '@') && !is_readable($filename)) { @@ -103,7 +110,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $errors = 0; foreach ($files as $file) { - $errors += $this->validateTemplate($this->twig, $output, file_get_contents($file), $file); + $errors += $this->validateTemplate($twig, $output, file_get_contents($file), $file); } return $errors > 0 ? 1 : 0; diff --git a/src/Symfony/Bundle/TwigBundle/CHANGELOG.md b/src/Symfony/Bundle/TwigBundle/CHANGELOG.md index aad8ce9314dc4..de36165b56c12 100644 --- a/src/Symfony/Bundle/TwigBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/TwigBundle/CHANGELOG.md @@ -1,11 +1,6 @@ CHANGELOG ========= -2.5.0 ------ - - * moved `LintCommand` to the Twig bridge and registered it as a service - 2.3.0 ----- diff --git a/src/Symfony/Bundle/TwigBundle/Command/LintCommand.php b/src/Symfony/Bundle/TwigBundle/Command/LintCommand.php new file mode 100644 index 0000000000000..39f22c97e9204 --- /dev/null +++ b/src/Symfony/Bundle/TwigBundle/Command/LintCommand.php @@ -0,0 +1,52 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\TwigBundle\Command; + +use Symfony\Bridge\Twig\Command\LintCommand as BaseLintCommand; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\ContainerAwareInterface; + +class LintCommand extends BaseLintCommand implements ContainerAwareInterface +{ + /** + * @var ContainerInterface|null + */ + private $container; + + /** + * @return ContainerInterface + */ + protected function getContainer() + { + if (null === $this->container) { + $this->container = $this->getApplication()->getKernel()->getContainer(); + } + + return $this->container; + } + + /** + * {@inheritdoc} + */ + public function setContainer(ContainerInterface $container = null) + { + $this->container = $container; + } + + /** + * {@inheritdoc} + */ + public function getTwigEnvironment() + { + return $this->getContainer()->get('twig'); + } +} diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml index 019b79005e584..5efbe9d6d4f41 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml @@ -25,7 +25,6 @@ Symfony\Bridge\Twig\Translation\TwigExtractor Symfony\Component\HttpKernel\EventListener\ExceptionListener Symfony\Bundle\TwigBundle\Controller\ExceptionController - Symfony\Bridge\Twig\Command\LintCommand @@ -132,10 +131,5 @@ %kernel.debug% - - - - - From a8fd92edf8b632e3ee4b7e220deb313ad1d98ac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Mon, 30 Dec 2013 08:41:22 +0100 Subject: [PATCH 06/12] Fix test, inline method and fix typo --- src/Symfony/Bridge/Twig/CHANGELOG.md | 2 +- .../Twig/Tests/Command/LintCommandTest.php | 5 ++++- .../Bundle/TwigBundle/Command/LintCommand.php | 18 +++++------------- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/Symfony/Bridge/Twig/CHANGELOG.md b/src/Symfony/Bridge/Twig/CHANGELOG.md index da302abaa04d8..4be010ba20e56 100644 --- a/src/Symfony/Bridge/Twig/CHANGELOG.md +++ b/src/Symfony/Bridge/Twig/CHANGELOG.md @@ -4,7 +4,7 @@ CHANGELOG 2.5.0 ----- - * added command `twig:lint` from `TwigBundle` + * moved command `twig:lint` from `TwigBundle` 2.4.0 ----- diff --git a/src/Symfony/Bridge/Twig/Tests/Command/LintCommandTest.php b/src/Symfony/Bridge/Twig/Tests/Command/LintCommandTest.php index 3ba4ac49fac4c..da4460ccbe938 100644 --- a/src/Symfony/Bridge/Twig/Tests/Command/LintCommandTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Command/LintCommandTest.php @@ -63,8 +63,11 @@ private function createCommandTester() { $twig = new \Twig_Environment(new \Twig_Loader_Filesystem()); + $command = new LintCommand(); + $command->setTwigEnvironment($twig); + $application = new Application(); - $application->add(new LintCommand($twig)); + $application->add($command); $command = $application->find('twig:lint'); return new CommandTester($command); diff --git a/src/Symfony/Bundle/TwigBundle/Command/LintCommand.php b/src/Symfony/Bundle/TwigBundle/Command/LintCommand.php index 39f22c97e9204..1dd5e0aebbdca 100644 --- a/src/Symfony/Bundle/TwigBundle/Command/LintCommand.php +++ b/src/Symfony/Bundle/TwigBundle/Command/LintCommand.php @@ -22,18 +22,6 @@ class LintCommand extends BaseLintCommand implements ContainerAwareInterface */ private $container; - /** - * @return ContainerInterface - */ - protected function getContainer() - { - if (null === $this->container) { - $this->container = $this->getApplication()->getKernel()->getContainer(); - } - - return $this->container; - } - /** * {@inheritdoc} */ @@ -47,6 +35,10 @@ public function setContainer(ContainerInterface $container = null) */ public function getTwigEnvironment() { - return $this->getContainer()->get('twig'); + if (null === $this->container) { + $this->container = $this->getApplication()->getKernel()->getContainer(); + } + + return $this->container->get('twig'); } } From b008f49010dbe23d3537ba4e50e8628ee0bc96b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Mon, 30 Dec 2013 17:33:00 +0100 Subject: [PATCH 07/12] Makes command name configurable in the constructor --- src/Symfony/Bridge/Twig/Command/LintCommand.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Twig/Command/LintCommand.php b/src/Symfony/Bridge/Twig/Command/LintCommand.php index a93b7da4a552e..49b584d5a4abe 100644 --- a/src/Symfony/Bridge/Twig/Command/LintCommand.php +++ b/src/Symfony/Bridge/Twig/Command/LintCommand.php @@ -26,6 +26,14 @@ class LintCommand extends Command { private $twig; + /** + * {@inheritDoc} + */ + public function __construct($name = 'twig:lint') + { + parent::__construct($name); + } + /** * Sets the twig environment * @@ -47,7 +55,6 @@ protected function getTwigEnvironment() protected function configure() { $this - ->setName('twig:lint') ->setDescription('Lints a template and outputs encountered errors') ->addArgument('filename') ->setHelp(<< Date: Mon, 30 Dec 2013 17:37:11 +0100 Subject: [PATCH 08/12] Remove useless fallback as the container is always injected into ContainerAwareInterface instances --- src/Symfony/Bundle/TwigBundle/Command/LintCommand.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Symfony/Bundle/TwigBundle/Command/LintCommand.php b/src/Symfony/Bundle/TwigBundle/Command/LintCommand.php index 1dd5e0aebbdca..c90ab522f04c3 100644 --- a/src/Symfony/Bundle/TwigBundle/Command/LintCommand.php +++ b/src/Symfony/Bundle/TwigBundle/Command/LintCommand.php @@ -35,10 +35,6 @@ public function setContainer(ContainerInterface $container = null) */ public function getTwigEnvironment() { - if (null === $this->container) { - $this->container = $this->getApplication()->getKernel()->getContainer(); - } - return $this->container->get('twig'); } } From c244b14d658ffa089e3d2afd096d1fb5f870f968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Mon, 30 Dec 2013 23:05:18 +0100 Subject: [PATCH 09/12] Create method LintCommand->findFiles() to make the bridge command independant from the framework --- .../Bridge/Twig/Command/LintCommand.php | 31 +++++++------------ .../Bundle/TwigBundle/Command/LintCommand.php | 30 ++++++++++++++++++ 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Command/LintCommand.php b/src/Symfony/Bridge/Twig/Command/LintCommand.php index 49b584d5a4abe..b589078c69fdd 100644 --- a/src/Symfony/Bridge/Twig/Command/LintCommand.php +++ b/src/Symfony/Bridge/Twig/Command/LintCommand.php @@ -15,7 +15,6 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Finder\Finder; -use Symfony\Bundle\FrameworkBundle\Console\Application as FrameworkBundleApplication; /** * Command that will validate your template syntax and output encountered errors. @@ -70,11 +69,6 @@ protected function configure() The command finds all twig templates in dirname and validates the syntax of each Twig template. -php %command.full_name% @AcmeMyBundle - -The command finds all twig templates in the AcmeMyBundle bundle and validates -the syntax of each Twig template. - cat filename | php %command.full_name% The command gets the template contents from stdin and validates its syntax. @@ -101,19 +95,7 @@ protected function execute(InputInterface $input, OutputInterface $output) return $this->validateTemplate($twig, $output, $template); } - if (0 !== strpos($filename, '@') && !is_readable($filename)) { - throw new \RuntimeException(sprintf('File or directory "%s" is not readable', $filename)); - } - - $files = array(); - if (is_file($filename)) { - $files = array($filename); - } elseif (is_dir($filename)) { - $files = Finder::create()->files()->in($filename)->name('*.twig'); - } elseif ($this->getApplication() instanceof FrameworkBundleApplication) { - $dir = $this->getApplication()->getKernel()->locateResource($filename); - $files = Finder::create()->files()->in($dir)->name('*.twig'); - } + $files = $this->findFiles($filename); $errors = 0; foreach ($files as $file) { @@ -123,6 +105,17 @@ protected function execute(InputInterface $input, OutputInterface $output) return $errors > 0 ? 1 : 0; } + protected function findFiles($filename) + { + if (is_file($filename)) { + return array($filename); + } elseif (is_dir($filename)) { + return Finder::create()->files()->in($filename)->name('*.twig'); + } + + throw new \RuntimeException(sprintf('File or directory "%s" is not readable', $filename)); + } + protected function validateTemplate(\Twig_Environment $twig, OutputInterface $output, $template, $file = null) { try { diff --git a/src/Symfony/Bundle/TwigBundle/Command/LintCommand.php b/src/Symfony/Bundle/TwigBundle/Command/LintCommand.php index c90ab522f04c3..3853a92ac63cd 100644 --- a/src/Symfony/Bundle/TwigBundle/Command/LintCommand.php +++ b/src/Symfony/Bundle/TwigBundle/Command/LintCommand.php @@ -14,6 +14,7 @@ use Symfony\Bridge\Twig\Command\LintCommand as BaseLintCommand; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerAwareInterface; +use Symfony\Component\Finder\Finder; class LintCommand extends BaseLintCommand implements ContainerAwareInterface { @@ -37,4 +38,33 @@ public function getTwigEnvironment() { return $this->container->get('twig'); } + + protected function configure() + { + parent::configure(); + + $this + ->setHelp( + $this->getHelp().<<php %command.full_name% @AcmeMyBundle + +The command finds all twig templates in the AcmeMyBundle bundle and validates +the syntax of each Twig template. +EOF + ) + ; + } + + protected function findFiles($filename) + { + if (0 === strpos($filename, '@')) { + $dir = $this->getApplication()->getKernel()->locateResource($filename); + + return Finder::create()->files()->in($dir)->name('*.twig'); + } + + return parent::findFiles($filename); + } } From 3d0f93c62637f4c0c1c2b9f4c29e4832315f5748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Mon, 30 Dec 2013 23:20:21 +0100 Subject: [PATCH 10/12] symfony/console becomes a dev requirement of symfony/twig-bridge for tests --- src/Symfony/Bridge/Twig/composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Twig/composer.json b/src/Symfony/Bridge/Twig/composer.json index ea3fb7cde5b9f..02e98c3ccd5c7 100644 --- a/src/Symfony/Bridge/Twig/composer.json +++ b/src/Symfony/Bridge/Twig/composer.json @@ -28,7 +28,8 @@ "symfony/translation": "~2.2", "symfony/yaml": "~2.0", "symfony/security": "~2.4", - "symfony/stopwatch": "~2.2" + "symfony/stopwatch": "~2.2", + "symfony/console": "~2.2" }, "suggest": { "symfony/form": "For using the FormExtension", From 08759f0dcb4b9c72de7bde508d8bf5171415c5c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Tue, 31 Dec 2013 09:57:02 +0100 Subject: [PATCH 11/12] Fix method scope --- src/Symfony/Bundle/TwigBundle/Command/LintCommand.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/TwigBundle/Command/LintCommand.php b/src/Symfony/Bundle/TwigBundle/Command/LintCommand.php index 3853a92ac63cd..71c429977cd8b 100644 --- a/src/Symfony/Bundle/TwigBundle/Command/LintCommand.php +++ b/src/Symfony/Bundle/TwigBundle/Command/LintCommand.php @@ -34,11 +34,14 @@ public function setContainer(ContainerInterface $container = null) /** * {@inheritdoc} */ - public function getTwigEnvironment() + protected function getTwigEnvironment() { return $this->container->get('twig'); } + /** + * {@inheritdoc} + */ protected function configure() { parent::configure(); From eb831e7fa262f2123f15a3ff1d2c5575b1fdb3a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Tue, 31 Dec 2013 10:06:38 +0100 Subject: [PATCH 12/12] Restore class doc block. --- src/Symfony/Bridge/Twig/Command/LintCommand.php | 1 + src/Symfony/Bundle/TwigBundle/Command/LintCommand.php | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/Symfony/Bridge/Twig/Command/LintCommand.php b/src/Symfony/Bridge/Twig/Command/LintCommand.php index b589078c69fdd..5ebd255450d4c 100644 --- a/src/Symfony/Bridge/Twig/Command/LintCommand.php +++ b/src/Symfony/Bridge/Twig/Command/LintCommand.php @@ -20,6 +20,7 @@ * Command that will validate your template syntax and output encountered errors. * * @author Marc Weistroff + * @author Jérôme Tamarelle */ class LintCommand extends Command { diff --git a/src/Symfony/Bundle/TwigBundle/Command/LintCommand.php b/src/Symfony/Bundle/TwigBundle/Command/LintCommand.php index 71c429977cd8b..79a765d768e5f 100644 --- a/src/Symfony/Bundle/TwigBundle/Command/LintCommand.php +++ b/src/Symfony/Bundle/TwigBundle/Command/LintCommand.php @@ -16,6 +16,12 @@ use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\Finder\Finder; +/** + * Command that will validate your template syntax and output encountered errors. + * + * @author Marc Weistroff + * @author Jérôme Tamarelle + */ class LintCommand extends BaseLintCommand implements ContainerAwareInterface { /**