From 98b184ed485f5e4d73df61c98ab9777ba2910d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Mon, 20 Jan 2014 21:43:53 +0100 Subject: [PATCH] [Console] Add ContainerAwareCommand --- .../Command/ContainerAwareCommand.php | 23 ++-------- src/Symfony/Component/Console/CHANGELOG.md | 1 + .../ContainerAwareCommand.php | 45 +++++++++++++++++++ 3 files changed, 50 insertions(+), 19 deletions(-) create mode 100644 src/Symfony/Component/Console/DependencyInjection/ContainerAwareCommand.php diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerAwareCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerAwareCommand.php index 035f5536ee8dc..94fb314cb1e71 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerAwareCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerAwareCommand.php @@ -11,39 +11,24 @@ namespace Symfony\Bundle\FrameworkBundle\Command; -use Symfony\Component\Console\Command\Command; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\DependencyInjection\ContainerAwareInterface; +use Symfony\Component\Console\DependencyInjection\ContainerAwareCommand as BaseContainerAwareCommand; /** * Command. * * @author Fabien Potencier */ -abstract class ContainerAwareCommand extends Command implements ContainerAwareInterface +abstract class ContainerAwareCommand extends BaseContainerAwareCommand { - /** - * @var ContainerInterface|null - */ - private $container; - /** * @return ContainerInterface */ protected function getContainer() { - if (null === $this->container) { + if (null === parent::getContainer()) { $this->container = $this->getApplication()->getKernel()->getContainer(); } - return $this->container; - } - - /** - * {@inheritdoc} - */ - public function setContainer(ContainerInterface $container = null) - { - $this->container = $container; + return parent::getContainer(); } } diff --git a/src/Symfony/Component/Console/CHANGELOG.md b/src/Symfony/Component/Console/CHANGELOG.md index 19d03ca3039ea..59fd08ca7515e 100644 --- a/src/Symfony/Component/Console/CHANGELOG.md +++ b/src/Symfony/Component/Console/CHANGELOG.md @@ -6,6 +6,7 @@ CHANGELOG * added a way to set a default command instead of `ListCommand` * added a way to set the process name of a command +* added ContainerAwareCommand 2.4.0 ----- diff --git a/src/Symfony/Component/Console/DependencyInjection/ContainerAwareCommand.php b/src/Symfony/Component/Console/DependencyInjection/ContainerAwareCommand.php new file mode 100644 index 0000000000000..9c79b7af6378d --- /dev/null +++ b/src/Symfony/Component/Console/DependencyInjection/ContainerAwareCommand.php @@ -0,0 +1,45 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\DependencyInjection; + +use Symfony\Component\Console\Command\Command; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\ContainerAwareInterface; + +/** + * Command. + * + * @author Fabien Potencier + */ +abstract class ContainerAwareCommand extends Command implements ContainerAwareInterface +{ + /** + * @var ContainerInterface|null + */ + private $container; + + /** + * @return ContainerInterface + */ + protected function getContainer() + { + return $this->container; + } + + /** + * {@inheritdoc} + */ + public function setContainer(ContainerInterface $container = null) + { + $this->container = $container; + } +}