Skip to content
Browse files

Move the command "tiwg:lint" to the bridge

  • Loading branch information...
1 parent c15175a commit 8861f9c411ccecd022b775128928f4ce0ea87dcc @GromNaN committed Dec 19, 2013
View
33 ...Bundle/TwigBundle/Command/LintCommand.php → ...mfony/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 <marc.weistroff@sensiolabs.com>
*/
-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;
+ }
}
View
6 src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
@@ -25,6 +25,7 @@
<parameter key="twig.translation.extractor.class">Symfony\Bridge\Twig\Translation\TwigExtractor</parameter>
<parameter key="twig.exception_listener.class">Symfony\Component\HttpKernel\EventListener\ExceptionListener</parameter>
<parameter key="twig.controller.exception.class">Symfony\Bundle\TwigBundle\Controller\ExceptionController</parameter>
+ <parameter key="twig.command.lint.class">Symfony\Bridge\Twig\Command\LintCommand</parameter>
</parameters>
<services>
@@ -131,5 +132,10 @@
<argument type="service" id="twig" />
<argument>%kernel.debug%</argument>
</service>
+
+ <service id="twig.command.lint" class="%twig.command.lint.class%">
+ <tag name="console.command" />
+ <argument type="service" id="twig" />
+ </service>
</services>
</container>

0 comments on commit 8861f9c

Please sign in to comment.
Something went wrong with that request. Please try again.