Clear lazy loading initializer after the service is successfully initialized

This commit is contained in:
Jeremy Livingston 2013-08-28 16:28:53 -04:00 committed by Fabien Potencier
parent 196227bd83
commit 39b610d9ad
5 changed files with 9 additions and 9 deletions

View File

@ -51,10 +51,10 @@ class RuntimeInstantiator implements InstantiatorInterface
return $this->factory->createProxy( return $this->factory->createProxy(
$definition->getClass(), $definition->getClass(),
function (&$wrappedInstance, LazyLoadingInterface $proxy) use ($realInstantiator) { function (&$wrappedInstance, LazyLoadingInterface $proxy) use ($realInstantiator) {
$proxy->setProxyInitializer(null);
$wrappedInstance = call_user_func($realInstantiator); $wrappedInstance = call_user_func($realInstantiator);
$proxy->setProxyInitializer(null);
return true; return true;
} }
); );

View File

@ -75,10 +75,10 @@ class ProxyDumper implements DumperInterface
$instantiation new $proxyClass( $instantiation new $proxyClass(
function (&\$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface \$proxy) use (\$container) { function (&\$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface \$proxy) use (\$container) {
\$proxy->setProxyInitializer(null);
\$wrappedInstance = \$container->$methodName(false); \$wrappedInstance = \$container->$methodName(false);
\$proxy->setProxyInitializer(null);
return true; return true;
} }
); );

View File

@ -50,10 +50,10 @@ class LazyServiceProjectServiceContainer extends Container
return $this->services['foo'] = new stdClass_c1d194250ee2e2b7d2eab8b8212368a8( return $this->services['foo'] = new stdClass_c1d194250ee2e2b7d2eab8b8212368a8(
function (& $wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) use ($container) { function (& $wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) use ($container) {
$proxy->setProxyInitializer(null);
$wrappedInstance = $container->getFooService(false); $wrappedInstance = $container->getFooService(false);
$proxy->setProxyInitializer(null);
return true; return true;
} }
); );

View File

@ -10,10 +10,10 @@ class ProjectServiceContainer extends Container
return $this->services['foo'] = new stdClass_%s( return $this->services['foo'] = new stdClass_%s(
function (&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) use ($container) { function (&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) use ($container) {
$proxy->setProxyInitializer(null);
$wrappedInstance = $container->getFooService(false); $wrappedInstance = $container->getFooService(false);
$proxy->setProxyInitializer(null);
return true; return true;
} }
); );

View File

@ -74,7 +74,7 @@ class ProxyDumperTest extends \PHPUnit_Framework_TestCase
'%wif ($lazyLoad) {%w$container = $this;%wreturn $this->services[\'foo\'] = new ' '%wif ($lazyLoad) {%w$container = $this;%wreturn $this->services[\'foo\'] = new '
. 'SymfonyBridgeProxyManagerLazyProxyTestsInstantiatorProxyDumperTest_%s(%wfunction ' . 'SymfonyBridgeProxyManagerLazyProxyTestsInstantiatorProxyDumperTest_%s(%wfunction '
. '(&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) use ($container) {' . '(&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) use ($container) {'
. '%w$proxy->setProxyInitializer(null);%w$wrappedInstance = $container->getFooService(false);' . '%w$wrappedInstance = $container->getFooService(false);%w$proxy->setProxyInitializer(null);'
. '%wreturn true;%w}%w);%w}%w', . '%wreturn true;%w}%w);%w}%w',
$code $code
); );