Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 21af4f0

Browse filesBrowse files
committed
bug #20147 [FrameworkBundle] Alter container class instead of kernel name in cache:clear command (nicolas-grekas)
This PR was merged into the 2.7 branch. Discussion ---------- [FrameworkBundle] Alter container class instead of kernel name in cache:clear command | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #19912 | License | MIT | Doc PR | - The decision to alter kernel's name instead of the container's class dates from cc3a40e But this is causing issues such as #19912. Looking more carefully, the real intent is to change the container class and there is no need to alter also the kernel's name at this stage. Commits ------- 73c9693 [FrameworkBundle] Alter container class instead of kernel name in cache:clear command
2 parents 31a68b8 + 73c9693 commit 21af4f0
Copy full SHA for 21af4f0

File tree

4 files changed

+17
-25
lines changed
Filter options

4 files changed

+17
-25
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php
+14-23Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -157,22 +157,13 @@ protected function warmup($warmupDir, $realCacheDir, $enableOptionalWarmers = tr
157157
file_put_contents($file, $content);
158158
}
159159

160-
// fix references to kernel/container related classes
161-
$fileSearch = $tempKernel->getName().ucfirst($tempKernel->getEnvironment()).'*';
162-
$search = array(
163-
$tempKernel->getName().ucfirst($tempKernel->getEnvironment()),
164-
sprintf('\'kernel.name\' => \'%s\'', $tempKernel->getName()),
165-
sprintf('key="kernel.name">%s<', $tempKernel->getName()),
166-
);
167-
$replace = array(
168-
$realKernel->getName().ucfirst($realKernel->getEnvironment()),
169-
sprintf('\'kernel.name\' => \'%s\'', $realKernel->getName()),
170-
sprintf('key="kernel.name">%s<', $realKernel->getName()),
171-
);
172-
foreach (Finder::create()->files()->name($fileSearch)->in($warmupDir) as $file) {
173-
$content = str_replace($search, $replace, file_get_contents($file));
174-
file_put_contents(str_replace($search, $replace, $file), $content);
175-
unlink($file);
160+
// fix references to container's class
161+
$tempContainerClass = get_class($tempKernel->getContainer());
162+
$realContainerClass = get_class($realKernel->getContainer());
163+
foreach (Finder::create()->files()->name($tempContainerClass.'*')->in($warmupDir) as $file) {
164+
$content = str_replace($tempContainerClass, $realContainerClass, file_get_contents($file));
165+
file_put_contents($file, $content);
166+
rename($file, str_replace(DIRECTORY_SEPARATOR.$tempContainerClass, DIRECTORY_SEPARATOR.$realContainerClass, $file));
176167
}
177168

178169
// remove temp kernel file after cache warmed up
@@ -195,8 +186,8 @@ protected function getTempKernel(KernelInterface $parent, $namespace, $parentCla
195186
// the temp kernel class name must have the same length than the real one
196187
// to avoid the many problems in serialized resources files
197188
$class = substr($parentClass, 0, -1).'_';
198-
// the temp kernel name must be changed too
199-
$name = var_export(substr($parent->getName(), 0, -1).'_', true);
189+
// the temp container class must be changed too
190+
$containerClass = var_export(substr(get_class($parent->getContainer()), 0, -1).'_', true);
200191
$code = <<<EOF
201192
<?php
202193
@@ -209,11 +200,6 @@ public function getCacheDir()
209200
return $cacheDir;
210201
}
211202
212-
public function getName()
213-
{
214-
return $name;
215-
}
216-
217203
public function getRootDir()
218204
{
219205
return $rootDir;
@@ -224,6 +210,11 @@ public function getLogDir()
224210
return $logDir;
225211
}
226212
213+
protected function getContainerClass()
214+
{
215+
return $containerClass;
216+
}
217+
227218
protected function buildContainer()
228219
{
229220
\$container = parent::buildContainer();

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ private function registerRouterConfiguration(array $config, ContainerBuilder $co
367367
$loader->load('routing.xml');
368368

369369
$container->setParameter('router.resource', $config['resource']);
370-
$container->setParameter('router.cache_class_prefix', $container->getParameter('kernel.name').ucfirst($container->getParameter('kernel.environment')));
370+
$container->setParameter('router.cache_class_prefix', $container->getParameter('kernel.container_class'));
371371
$router = $container->findDefinition('router.default');
372372
$argument = $router->getArgument(2);
373373
$argument['strict_requirements'] = $config['strict_requirements'];

‎src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/CacheClearCommandTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/CacheClearCommandTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,6 @@ public function testCacheIsFreshAfterCacheClearedWithWarmup()
8383
}
8484
}
8585
$this->assertTrue($found, 'Kernel file should present as resource');
86-
$this->assertRegExp(sprintf('/\'kernel.name\'\s*=>\s*\'%s\'/', $this->kernel->getName()), file_get_contents($containerFile), 'kernel.name is properly set on the dumped container');
86+
$this->assertRegExp(sprintf('/\'kernel.container_class\'\s*=>\s*\'%s\'/', get_class($this->kernel->getContainer())), file_get_contents($containerFile), 'kernel.container_class is properly set on the dumped container');
8787
}
8888
}

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ protected function createContainer(array $data = array())
477477
'kernel.environment' => 'test',
478478
'kernel.name' => 'kernel',
479479
'kernel.root_dir' => __DIR__,
480+
'kernel.container_class' => 'testContainer',
480481
), $data)));
481482
}
482483

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.