diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index d7d0e16d56115..f7c55ce3f4b27 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -361,6 +361,11 @@ public function load(array $configs, ContainerBuilder $container) $container->registerForAutoconfiguration(ObjectInitializerInterface::class) ->addTag('validator.initializer'); + if (!$container->getParameter('kernel.debug')) { + // remove tagged iterator argument for resource checkers + $container->getDefinition('config_cache_factory')->setArguments(array()); + } + if (\PHP_VERSION_ID < 70000) { $this->addClassesToCompile(array( 'Symfony\\Component\\Config\\ConfigCache', diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 31f34c9859e12..8b2841dc9ab60 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -988,6 +988,17 @@ public function testCachePoolServices() $this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.def', 'cache.app', 11); } + public function testRemovesResourceCheckerConfigCacheFactoryArgumentOnlyIfNoDebug() + { + $container = $this->createContainer(array('kernel.debug' => true)); + (new FrameworkExtension())->load(array(), $container); + $this->assertCount(1, $container->getDefinition('config_cache_factory')->getArguments()); + + $container = $this->createContainer(array('kernel.debug' => false)); + (new FrameworkExtension())->load(array(), $container); + $this->assertEmpty($container->getDefinition('config_cache_factory')->getArguments()); + } + protected function createContainer(array $data = array()) { return new ContainerBuilder(new ParameterBag(array_merge(array( diff --git a/src/Symfony/Component/Config/ResourceCheckerConfigCache.php b/src/Symfony/Component/Config/ResourceCheckerConfigCache.php index ab8c99eeadaa5..d2c5eff24703a 100644 --- a/src/Symfony/Component/Config/ResourceCheckerConfigCache.php +++ b/src/Symfony/Component/Config/ResourceCheckerConfigCache.php @@ -68,7 +68,11 @@ public function isFresh() return false; } - if (!$this->resourceCheckers) { + if ($this->resourceCheckers instanceof \Traversable && !$this->resourceCheckers instanceof \Countable) { + $this->resourceCheckers = iterator_to_array($this->resourceCheckers); + } + + if (!count($this->resourceCheckers)) { return true; // shortcut - if we don't have any checkers we don't need to bother with the meta file at all } diff --git a/src/Symfony/Component/Config/Tests/ResourceCheckerConfigCacheTest.php b/src/Symfony/Component/Config/Tests/ResourceCheckerConfigCacheTest.php index d39742ad88f8c..371c7baa1cc7d 100644 --- a/src/Symfony/Component/Config/Tests/ResourceCheckerConfigCacheTest.php +++ b/src/Symfony/Component/Config/Tests/ResourceCheckerConfigCacheTest.php @@ -57,7 +57,7 @@ public function testCacheIsNotFreshIfEmpty() $this->assertFalse($cache->isFresh()); } - public function testCacheIsFreshIfNocheckerProvided() + public function testCacheIsFreshIfNoCheckerProvided() { /* For example in prod mode, you may choose not to run any checkers at all. In that case, the cache should always be considered fresh. */ @@ -65,6 +65,12 @@ public function testCacheIsFreshIfNocheckerProvided() $this->assertTrue($cache->isFresh()); } + public function testCacheIsFreshIfEmptyCheckerIteratorProvided() + { + $cache = new ResourceCheckerConfigCache($this->cacheFile, new \ArrayIterator(array())); + $this->assertTrue($cache->isFresh()); + } + public function testResourcesWithoutcheckersAreIgnoredAndConsideredFresh() { /* As in the previous test, but this time we have a resource. */