From 93dbc86599a2527267b43766f0ab30130bc901a6 Mon Sep 17 00:00:00 2001 From: Christian Stocker Date: Wed, 14 Jun 2017 17:51:00 +0200 Subject: [PATCH 1/4] Allow providers to be loaded lazy --- DependencyInjection/CacheProviderLoader.php | 4 ++++ DependencyInjection/Configuration.php | 1 + 2 files changed, 5 insertions(+) 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')) From a95228c862d969e5da77b4a16dfcc87e59e7fe50 Mon Sep 17 00:00:00 2001 From: Christian Stocker Date: Thu, 15 Jun 2017 13:12:10 +0200 Subject: [PATCH 2/4] Add tests --- .../AbstractDoctrineCacheExtensionTest.php | 19 +++++++++++++++++- .../Fixtures/config/xml/lazy.xml | 20 +++++++++++++++++++ .../Fixtures/config/yml/lazy.yml | 11 ++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 Tests/DependencyInjection/Fixtures/config/xml/lazy.xml create mode 100644 Tests/DependencyInjection/Fixtures/config/yml/lazy.yml 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..9d22344 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/yml/lazy.yml @@ -0,0 +1,11 @@ +doctrine_cache: + providers: + lazy_provider: + type: apc + lazy: true + lazy_false_provider: + type: array + lazy: false + lazy_no_provider: + type: redis + lazy: false From 9edd29135872a6113bb31235ec204e6d44ab7719 Mon Sep 17 00:00:00 2001 From: Christian Stocker Date: Thu, 15 Jun 2017 13:12:26 +0200 Subject: [PATCH 3/4] set lazy also in SymfonyBridgeAdapter --- DependencyInjection/SymfonyBridgeAdapter.php | 1 + 1 file changed, 1 insertion(+) 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'])) { From 4ea3393fbbdd84b206a3c19453ee8512015e404f Mon Sep 17 00:00:00 2001 From: Christian Stocker Date: Fri, 16 Jun 2017 09:24:22 +0200 Subject: [PATCH 4/4] remove the lazy config from the last test --- Tests/DependencyInjection/Fixtures/config/yml/lazy.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/Tests/DependencyInjection/Fixtures/config/yml/lazy.yml b/Tests/DependencyInjection/Fixtures/config/yml/lazy.yml index 9d22344..d9e79cd 100644 --- a/Tests/DependencyInjection/Fixtures/config/yml/lazy.yml +++ b/Tests/DependencyInjection/Fixtures/config/yml/lazy.yml @@ -8,4 +8,3 @@ doctrine_cache: lazy: false lazy_no_provider: type: redis - lazy: false