Skip to content

Commit

Permalink
[HttpKernel] enabling cache-reloading when cache file is rebuilt
Browse files Browse the repository at this point in the history
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
1 parent fd0d288 commit 977b27f
Showing 1 changed file with 34 additions and 1 deletion.
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

0 comments on commit 977b27f

Please sign in to comment.