diff --git a/DependencyInjection/CacheProviderLoader.php b/DependencyInjection/CacheProviderLoader.php index d27b680..78eee28 100644 --- a/DependencyInjection/CacheProviderLoader.php +++ b/DependencyInjection/CacheProviderLoader.php @@ -51,6 +51,10 @@ public function loadCacheProvider($name, array $config, ContainerBuilder $contai $container->setAlias($alias, $serviceId); } + if ($config['lazy']) { + $service->setLazy(true); + } + if ($this->definitionClassExists($type, $container)) { $this->getCacheDefinition($type, $container)->configure($name, $config, $service, $container); } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index a7bf62d..1953a7d 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -173,6 +173,7 @@ public function getConfigTreeBuilder() ->then($normalization) ->end() ->children() + ->scalarNode('lazy')->defaultFalse()->end() ->scalarNode('namespace')->defaultNull()->end() ->scalarNode('type')->defaultNull()->end() ->append($this->addBasicProviderNode('apc')) diff --git a/DependencyInjection/SymfonyBridgeAdapter.php b/DependencyInjection/SymfonyBridgeAdapter.php index 64ad4a4..5d79161 100644 --- a/DependencyInjection/SymfonyBridgeAdapter.php +++ b/DependencyInjection/SymfonyBridgeAdapter.php @@ -98,6 +98,7 @@ public function loadCacheDriver($cacheName, $objectManagerName, array $cacheDriv $type => array(), 'type' => $type, 'namespace' => null, + 'lazy' => false ); if ( ! isset($cacheDriver['namespace'])) { diff --git a/Tests/DependencyInjection/AbstractDoctrineCacheExtensionTest.php b/Tests/DependencyInjection/AbstractDoctrineCacheExtensionTest.php index 41a4fe8..563af29 100644 --- a/Tests/DependencyInjection/AbstractDoctrineCacheExtensionTest.php +++ b/Tests/DependencyInjection/AbstractDoctrineCacheExtensionTest.php @@ -290,6 +290,24 @@ public function testUnrecognizedCacheDriverException() $this->compileContainer('unrecognized'); } + public function testLazy() + { + $container = $this->compileContainer('lazy'); + + $providers = array( + 'doctrine_cache.providers.lazy_provider' => true, + 'doctrine_cache.providers.lazy_false_provider' => false, + 'doctrine_cache.providers.lazy_no_provider' => false, + ); + + foreach ($providers as $key => $lazy) { + $this->assertTrue($container->hasDefinition($key)); + $definition = $container->getDefinition($key); + $this->assertTrue($definition->isLazy() == $lazy); + } + + } + public function testAcl() { $container = $this->compileContainer('acl'); @@ -315,7 +333,6 @@ public function assertCacheProvider(ContainerBuilder $container, $name, $class, $this->assertTrue($definition->isPublic()); $this->assertEquals($class, $definition->getClass()); - foreach (array_unique($expectedCalls) as $methodName => $params) { $this->assertMethodCall($definition, $methodName, $params); } diff --git a/Tests/DependencyInjection/Fixtures/config/xml/lazy.xml b/Tests/DependencyInjection/Fixtures/config/xml/lazy.xml new file mode 100644 index 0000000..0707a78 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/xml/lazy.xml @@ -0,0 +1,20 @@ + + + + + + + true + + + false + + + + + + diff --git a/Tests/DependencyInjection/Fixtures/config/yml/lazy.yml b/Tests/DependencyInjection/Fixtures/config/yml/lazy.yml new file mode 100644 index 0000000..d9e79cd --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/yml/lazy.yml @@ -0,0 +1,10 @@ +doctrine_cache: + providers: + lazy_provider: + type: apc + lazy: true + lazy_false_provider: + type: array + lazy: false + lazy_no_provider: + type: redis