Permalink
Browse files

[DependencyInjection] fixed management of scoped services with an inv…

…alid behavior set to null

The optimization for references has been removed as it does not take
scopes into account.
  • Loading branch information...
1 parent bb83b3e commit 5f2536467a03e1586ae1c47f989b010ee4ace087 @fabpot committed Mar 21, 2013
@@ -88,9 +88,7 @@ private function processArguments(array $arguments, $inMethodCall = false)
$exists = $this->container->has($id);
// resolve invalid behavior
- if ($exists && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
- $arguments[$k] = new Reference($id, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $argument->isStrict());
- } elseif (!$exists && ContainerInterface::NULL_ON_INVALID_REFERENCE === $invalidBehavior) {
+ if (!$exists && ContainerInterface::NULL_ON_INVALID_REFERENCE === $invalidBehavior) {
$arguments[$k] = null;
} elseif (!$exists && ContainerInterface::IGNORE_ON_INVALID_REFERENCE === $invalidBehavior) {
if ($inMethodCall) {
@@ -11,6 +11,7 @@
namespace Symfony\Component\DependencyInjection;
+use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
@@ -271,6 +272,10 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
unset($this->services[$id]);
}
+ if ($e instanceof InactiveScopeException && self::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
+ return null;
+ }
+
throw $e;
}
@@ -15,6 +15,7 @@
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
+use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
class ContainerTest extends \PHPUnit_Framework_TestCase
{
@@ -98,7 +99,7 @@ public function testGetServiceIds()
$this->assertEquals(array('service_container', 'foo', 'bar'), $sc->getServiceIds(), '->getServiceIds() returns all defined service ids');
$sc = new ProjectServiceContainer();
- $this->assertEquals(array('scoped', 'scoped_foo', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'service_container'), $sc->getServiceIds(), '->getServiceIds() returns defined service ids by getXXXService() methods');
+ $this->assertEquals(array('scoped', 'scoped_foo', 'inactive', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'service_container'), $sc->getServiceIds(), '->getServiceIds() returns defined service ids by getXXXService() methods');
}
/**
@@ -180,6 +181,15 @@ public function testGetCircularReference()
}
/**
+ * @covers Symfony\Component\DependencyInjection\Container::get
+ */
+ public function testGetReturnsNullOnInactiveScope()
+ {
+ $sc = new ProjectServiceContainer();
+ $this->assertNull($sc->get('inactive', ContainerInterface::NULL_ON_INVALID_REFERENCE));
+ }
+
+ /**
* @covers Symfony\Component\DependencyInjection\Container::has
*/
public function testHas()
@@ -476,6 +486,11 @@ protected function getScopedFooService()
return $this->services['scoped_foo'] = $this->scopedServices['foo']['scoped_foo'] = new \stdClass();
}
+ protected function getInactiveService()
+ {
+ throw new InactiveScopeException('request', 'request');
+ }
+
protected function getBarService()
{
return $this->__bar;

0 comments on commit 5f25364

Please sign in to comment.