protected function warmup($warmupDir)
{
$this->getContainer()->get('filesystem')->remove($warmupDir);
$parent = $this->getContainer()->get('kernel');
$class = get_class($parent);
$namespace = '';
if (false !== $pos = strrpos($class, '\\')) {
$namespace = substr($class, 0, $pos);
$class = substr($class, $pos + 1);
}
$kernel = $this->getTempKernel($parent, $namespace, $class, $warmupDir);
$kernel->boot();
$warmer = $kernel->getContainer()->get('cache_warmer');
$warmer->enableOptionalWarmers();
$warmer->warmUp($warmupDir);
// fix container files and classes
$regex = '/'.preg_quote($this->getTempKernelSuffix(), '/').'/';
$finder = new Finder();
foreach ($finder->files()->name(get_class($kernel->getContainer()).'*')->in($warmupDir) as $file) {
$content = file_get_contents($file);
$content = preg_replace($regex, '', $content);
file_put_contents(preg_replace($regex, '', $file), $content);
unlink($file);
}
// fix meta references to the Kernel
foreach ($finder->files()->name('*.meta')->in($warmupDir) as $file) {
$content = preg_replace(
'/C\:\d+\:"'.preg_quote($class.$this->getTempKernelSuffix(), '"/').'"/',
sprintf('C:%s:"%s"', strlen($class), $class),
file_get_contents($file)
);
file_put_contents($file, $content);
}
}