Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d1f5d25

Browse files
jfsimonfabpot
authored andcommitted
[FrameworkBundle] Fixes invalid serialized objects in cache
1 parent 0e7b5fb commit d1f5d25

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

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

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,31 @@ protected function warmup($warmupDir, $enableOptionalWarmers = true)
104104

105105
$warmer->warmUp($warmupDir);
106106

107+
foreach (Finder::create()->files()->name('*.meta')->in($warmupDir) as $file) {
108+
// fix meta references to the Kernel
109+
$content = preg_replace(
110+
'/C\:\d+\:"'.preg_quote($class.$this->getTempKernelSuffix(), '"/').'"/',
111+
sprintf('C:%s:"%s"', strlen($class), $class),
112+
file_get_contents($file)
113+
);
114+
115+
// fix meta references to cache files
116+
$realWarmupDir = substr($warmupDir, 0, -4);
117+
$content = preg_replace_callback(
118+
'/s\:\d+\:"'.preg_quote($warmupDir, '/').'([^"]+)"/',
119+
function (array $matches) use ($realWarmupDir) {
120+
$path = $realWarmupDir.$matches[1];
121+
return sprintf('s:%s:"%s"', strlen($path), $path);
122+
},
123+
$content
124+
);
125+
126+
file_put_contents($file, $content);
127+
}
128+
107129
// fix container files and classes
108130
$regex = '/'.preg_quote($this->getTempKernelSuffix(), '/').'/';
109-
$finder = new Finder();
110-
foreach ($finder->files()->name(get_class($kernel->getContainer()).'*')->in($warmupDir) as $file) {
131+
foreach (Finder::create()->files()->name(get_class($kernel->getContainer()).'*')->in($warmupDir) as $file) {
111132
$content = file_get_contents($file);
112133
$content = preg_replace($regex, '', $content);
113134

@@ -117,16 +138,6 @@ protected function warmup($warmupDir, $enableOptionalWarmers = true)
117138
file_put_contents(preg_replace($regex, '', $file), $content);
118139
unlink($file);
119140
}
120-
121-
// fix meta references to the Kernel
122-
foreach ($finder->files()->name('*.meta')->in($warmupDir) as $file) {
123-
$content = preg_replace(
124-
'/C\:\d+\:"'.preg_quote($class.$this->getTempKernelSuffix(), '"/').'"/',
125-
sprintf('C:%s:"%s"', strlen($class), $class),
126-
file_get_contents($file)
127-
);
128-
file_put_contents($file, $content);
129-
}
130141
}
131142

132143
protected function getTempKernelSuffix()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ private function registerRouterConfiguration(array $config, ContainerBuilder $co
246246
$loader->load('routing.xml');
247247

248248
$container->setParameter('router.resource', $config['resource']);
249+
$container->setParameter('router.cache_class_prefix', $container->getParameter('kernel.name').ucfirst($container->getParameter('kernel.environment')));
249250
$router = $container->findDefinition('router.default');
250-
251251
$argument = $router->getArgument(2);
252252
$argument['strict_requirements'] = $config['strict_requirements'];
253253
if (isset($config['type'])) {

src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
<parameter key="router.options.matcher_base_class">Symfony\Bundle\FrameworkBundle\Routing\RedirectableUrlMatcher</parameter>
2020
<parameter key="router.options.matcher_dumper_class">Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper</parameter>
2121
<parameter key="router.cache_warmer.class">Symfony\Bundle\FrameworkBundle\CacheWarmer\RouterCacheWarmer</parameter>
22-
<parameter key="router.options.matcher.cache_class">%kernel.name%%kernel.environment%UrlMatcher</parameter>
23-
<parameter key="router.options.generator.cache_class">%kernel.name%%kernel.environment%UrlGenerator</parameter>
22+
<parameter key="router.options.matcher.cache_class">%router.cache_class_prefix%UrlMatcher</parameter>
23+
<parameter key="router.options.generator.cache_class">%router.cache_class_prefix%UrlGenerator</parameter>
2424
<parameter key="router_listener.class">Symfony\Component\HttpKernel\EventListener\RouterListener</parameter>
2525
<parameter key="router.request_context.host">localhost</parameter>
2626
<parameter key="router.request_context.scheme">http</parameter>

0 commit comments

Comments
 (0)