[FrameworkBundle] Alter container class instead of kernel name in cache:clear command
This commit is contained in:
parent
3086fd38e5
commit
73c96939cd
@ -157,22 +157,13 @@ EOF
|
|||||||
file_put_contents($file, $content);
|
file_put_contents($file, $content);
|
||||||
}
|
}
|
||||||
|
|
||||||
// fix references to kernel/container related classes
|
// fix references to container's class
|
||||||
$fileSearch = $tempKernel->getName().ucfirst($tempKernel->getEnvironment()).'*';
|
$tempContainerClass = get_class($tempKernel->getContainer());
|
||||||
$search = array(
|
$realContainerClass = get_class($realKernel->getContainer());
|
||||||
$tempKernel->getName().ucfirst($tempKernel->getEnvironment()),
|
foreach (Finder::create()->files()->name($tempContainerClass.'*')->in($warmupDir) as $file) {
|
||||||
sprintf('\'kernel.name\' => \'%s\'', $tempKernel->getName()),
|
$content = str_replace($tempContainerClass, $realContainerClass, file_get_contents($file));
|
||||||
sprintf('key="kernel.name">%s<', $tempKernel->getName()),
|
file_put_contents($file, $content);
|
||||||
);
|
rename($file, str_replace(DIRECTORY_SEPARATOR.$tempContainerClass, DIRECTORY_SEPARATOR.$realContainerClass, $file));
|
||||||
$replace = array(
|
|
||||||
$realKernel->getName().ucfirst($realKernel->getEnvironment()),
|
|
||||||
sprintf('\'kernel.name\' => \'%s\'', $realKernel->getName()),
|
|
||||||
sprintf('key="kernel.name">%s<', $realKernel->getName()),
|
|
||||||
);
|
|
||||||
foreach (Finder::create()->files()->name($fileSearch)->in($warmupDir) as $file) {
|
|
||||||
$content = str_replace($search, $replace, file_get_contents($file));
|
|
||||||
file_put_contents(str_replace($search, $replace, $file), $content);
|
|
||||||
unlink($file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove temp kernel file after cache warmed up
|
// remove temp kernel file after cache warmed up
|
||||||
@ -195,8 +186,8 @@ EOF
|
|||||||
// the temp kernel class name must have the same length than the real one
|
// the temp kernel class name must have the same length than the real one
|
||||||
// to avoid the many problems in serialized resources files
|
// to avoid the many problems in serialized resources files
|
||||||
$class = substr($parentClass, 0, -1).'_';
|
$class = substr($parentClass, 0, -1).'_';
|
||||||
// the temp kernel name must be changed too
|
// the temp container class must be changed too
|
||||||
$name = var_export(substr($parent->getName(), 0, -1).'_', true);
|
$containerClass = var_export(substr(get_class($parent->getContainer()), 0, -1).'_', true);
|
||||||
$code = <<<EOF
|
$code = <<<EOF
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
@ -209,11 +200,6 @@ namespace $namespace
|
|||||||
return $cacheDir;
|
return $cacheDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName()
|
|
||||||
{
|
|
||||||
return $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getRootDir()
|
public function getRootDir()
|
||||||
{
|
{
|
||||||
return $rootDir;
|
return $rootDir;
|
||||||
@ -224,6 +210,11 @@ namespace $namespace
|
|||||||
return $logDir;
|
return $logDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getContainerClass()
|
||||||
|
{
|
||||||
|
return $containerClass;
|
||||||
|
}
|
||||||
|
|
||||||
protected function buildContainer()
|
protected function buildContainer()
|
||||||
{
|
{
|
||||||
\$container = parent::buildContainer();
|
\$container = parent::buildContainer();
|
||||||
|
@ -367,7 +367,7 @@ class FrameworkExtension extends Extension
|
|||||||
$loader->load('routing.xml');
|
$loader->load('routing.xml');
|
||||||
|
|
||||||
$container->setParameter('router.resource', $config['resource']);
|
$container->setParameter('router.resource', $config['resource']);
|
||||||
$container->setParameter('router.cache_class_prefix', $container->getParameter('kernel.name').ucfirst($container->getParameter('kernel.environment')));
|
$container->setParameter('router.cache_class_prefix', $container->getParameter('kernel.container_class'));
|
||||||
$router = $container->findDefinition('router.default');
|
$router = $container->findDefinition('router.default');
|
||||||
$argument = $router->getArgument(2);
|
$argument = $router->getArgument(2);
|
||||||
$argument['strict_requirements'] = $config['strict_requirements'];
|
$argument['strict_requirements'] = $config['strict_requirements'];
|
||||||
|
@ -83,6 +83,6 @@ class CacheClearCommandTest extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->assertTrue($found, 'Kernel file should present as resource');
|
$this->assertTrue($found, 'Kernel file should present as resource');
|
||||||
$this->assertRegExp(sprintf('/\'kernel.name\'\s*=>\s*\'%s\'/', $this->kernel->getName()), file_get_contents($containerFile), 'kernel.name is properly set on the dumped container');
|
$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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -477,6 +477,7 @@ abstract class FrameworkExtensionTest extends TestCase
|
|||||||
'kernel.environment' => 'test',
|
'kernel.environment' => 'test',
|
||||||
'kernel.name' => 'kernel',
|
'kernel.name' => 'kernel',
|
||||||
'kernel.root_dir' => __DIR__,
|
'kernel.root_dir' => __DIR__,
|
||||||
|
'kernel.container_class' => 'testContainer',
|
||||||
), $data)));
|
), $data)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user