8000 [FrameworkBundle][Config] fix: do not add resource checkers for no-debug by dmaicher · Pull Request #24824 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle][Config] fix: do not add resource checkers for no-debug #24824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 5 additions & 1 deletion src/Symfony/Component/Config/ResourceCheckerConfigCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,20 @@ 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. */
$cache = new ResourceCheckerConfigCache($this->cacheFile);
$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. */
Expand Down
0