bug #10966 PHP Fatal error when getContainer method of ContainerAwareCommand has be... (kevinvergauwen)

This PR was squashed before being merged into the 2.3 branch (closes #10966).

Discussion
----------

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

PHP Fatal error when getContainer method of ContainerAwareCommand has been called within the configure method of a Command (application property is not been set yet at that time)

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Commits
-------

8ea5c4c PHP Fatal error when getContainer method of ContainerAwareCommand has be...
This commit is contained in:
Fabien Potencier 2014-06-16 10:10:36 +02:00
commit 92d93cea80

View File

@ -29,11 +29,17 @@ abstract class ContainerAwareCommand extends Command implements ContainerAwareIn
/**
* @return ContainerInterface
* @throws \LogicException
*/
protected function getContainer()
{
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;