Permalink
Browse files

Remove command as a service as it requires too many services to be in…

…itialized
  • Loading branch information...
1 parent d500749 commit 678eddfe7337981ad44c1dcd093914082de7331b @GromNaN committed Dec 29, 2013
@@ -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;
@@ -1,11 +1,6 @@
CHANGELOG
=========
-2.5.0
------
-
- * moved `LintCommand` to the Twig bridge and registered it as a service
-
2.3.0
-----
@@ -0,0 +1,52 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * 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');
+ }
+}
@@ -25,7 +25,6 @@
<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>
@@ -132,10 +131,5 @@
<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 678eddf

Please sign in to comment.