8000 [HttpKernel] enabling cache-reloading when cache file is rebuilt by stampycode · Pull Request #20065 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpKernel] enabling cache-reloading when cache file is rebuilt #20065

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

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[HttpKernel] finding loaded class name when loading container from ca…
…che file

When generating multiple versions of the same container class, each new class name is suffixed with an incrementing version number, as you can't re-use class names.
So when we load the class file, the class itself may have a different name than the file name suggests - so after we load the class file, we have to find the class name.
  • Loading branch information
stampy committed Sep 28, 2016
commit a165fa89387aa4d9443ede0b8c440ec171e902b1
13 changes: 13 additions & 0 deletions src/Symfony/Component/HttpKernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,19 @@ protected function initializeContainer()
require $cache->getPath();
}

if(!class_exists($class)) {
//the cache file loaded has a different classVersion than we expected, so we need to find the loaded class.
foreach (array_reverse(get_declared_classes()) as $declaredClass) {
if (rtrim($declaredClass, '0123456789') === $class) {
class_alias($declaredClass, $class);
break;
}
}
if (!class_exists($class)) {
throw new \RuntimeException(sprintf("Failed to load the %s container from cache\n", $class));
}
}

$this->container = new $class();
$this->container->set('kernel', $this);

Expand Down
0