Skip to content

Commit

Permalink
merged branch fabpot/container-fix (PR #7697)
Browse files Browse the repository at this point in the history
This PR was merged into the master branch.

Discussion
----------

[DependencyInjection] fixed management of scoped services with an invalid behavior set to null

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

Commits
-------

edd7649 [DependencyInjection] fixed management of scoped services with an invalid behavior set to null (closes #7636)
  • Loading branch information
fabpot committed Apr 18, 2013
2 parents 30e6fe7 + edd7649 commit c980dbd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Symfony/Component/DependencyInjection/ContainerBuilder.php
Expand Up @@ -430,6 +430,12 @@ public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INV

try {
return parent::get($id, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE);
} catch (InactiveScopeException $e) {
if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
return null;
}

throw $e;
} catch (InvalidArgumentException $e) {
if (isset($this->loading[$id])) {
throw new LogicException(sprintf('The service "%s" has a circular reference to itself.', $id), 0, $e);
Expand All @@ -455,6 +461,11 @@ public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INV
$service = $this->createService($definition, $id);
} catch (\Exception $e) {
unset($this->loading[$id]);

if ($e instanceof InactiveScopeException && self::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
return null;
}

throw $e;
}

Expand Down
Expand Up @@ -138,6 +138,17 @@ public function testGetUnsetLoadingServiceWhenCreateServiceThrowsAnException()
$builder->get('foo');
}

/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::get
*/
public function testGetReturnsNullOnInactiveScope()
{
$builder = new ContainerBuilder();
$builder->register('foo', 'stdClass')->setScope('request');

$this->assertNull($builder->get('foo', ContainerInterface::NULL_ON_INVALID_REFERENCE));
}

/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::getServiceIds
*/
Expand Down

0 comments on commit c980dbd

Please sign in to comment.