PHP Fatal error when getContainer method of ContainerAwareCommand has be...

This commit is contained in:
Kevin Vergauwen 2014-05-22 15:39:58 +02:00 committed by Fabien Potencier
parent c505a639b2
commit 8ea5c4c0f6

View File

@ -29,11 +29,17 @@ abstract class ContainerAwareCommand extends Command implements ContainerAwareIn
/** /**
* @return ContainerInterface * @return ContainerInterface
* @throws \LogicException
*/ */
protected function getContainer() protected function getContainer()
{ {
if (null === $this->container) { if (null === $this->container) {
$this->container = $this->getApplication()->getKernel()->getContainer(); $application = $this->getApplication();
if (null === $application) {
throw new \LogicException('The container cannot be retrieved as the application instance is not yet set.');
}
$this->container = $application->getKernel()->getContainer();
} }
return $this->container; return $this->container;