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
Next Next commit
[HttpKernel] enabling cache-reloading when cache file is rebuilt
This allows the cache file to be deleted and thus rebuilt between Container builds in WebTestCase scenario, to enable testing of multiple configurations of the same application through WebTestCase.
  • Loading branch information
stampy committed Sep 28, 2016
commit 977b27f2cd2c5a27d98abfb7aa68a3221da2266a
35 changes: 34 additions & 1 deletion src/Symfony/Component/HttpKernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,12 +482,17 @@ protected function initializeContainer()
if (!$cache->isFresh()) {
$container = $this->buildContainer();
$container->compile();
$class = $this->getNextClassVersion($class);
$this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());

$fresh = false;
} else {
$class = $this->getLatestClassVersion($class);
}

require_once $cache->getPath();
if(!class_exists($class)) {
require $cache->getPath();
}

$this->container = new $class();
$this->container->set('kernel', $this);
Expand All @@ -497,6 +502,34 @@ protected function initializeContainer()
}
}

/**
* Returns the first version of the given class name that doesn't yet exist.
*
* eg. 'MyClass' is the first version, 'MyClass1' the second, 'MyClass2' the second, etc.
*
* @param string $class
* @return string
*/
protected function getNextClassVersion($class)
{
for ($classVer = 0; class_exists($class . ($classVer ?: '')); $classVer++);

return $class . ($classVer ?: '');
}

/**
* Returns the last version of the given class name that does exist
*
* @param string $class
* @return string
*/
protected function getLatestClassVersion($class)
{
for ($classVer = 0; class_exists($class . ($classVer ?: '')); $classVer++);

return $class . ($classVer > 1 ? $classVer - 1 : '');
}

/**
* Returns the kernel parameters.
*
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy