8000 [HttpKernel] use ConfigCacheFactory to create ConfigCache instances · symfony/symfony@8d5f992 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d5f992

Browse files
committed
[HttpKernel] use ConfigCacheFactory to create ConfigCache instances
1 parent ec2df34 commit 8d5f992

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

UPGRADE-2.7.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
UPGRADE FROM 2.6 to 2.7
22
=======================
33

4+
HttpKernel
5+
----------
6+
7+
* The `$cache` argument type of the `dumpContainer()` method in the `Symfony\Component\HttpKernel\Kernel`
8+
class was changed from `Symfony\Component\Config\ConfigCache` to `Symfony\Component\Config\ConfigCacheInterface`.
9+
410
Router
511
------
612

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator;
1515
use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
16+
use Symfony\Component\Config\ConfigCacheFactory;
17+
use Symfony\Component\Config\ConfigCacheFactoryInterface;
18+
use Symfony\Component\Config\ConfigCacheInterface;
1619
use Symfony\Component\DependencyInjection\ContainerInterface;
1720
use Symfony\Component\DependencyInjection\ContainerBuilder;
1821
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
@@ -31,7 +34,6 @@
3134
use Symfony\Component\HttpKernel\DependencyInjection\AddClassesToCachePass;
3235
use Symfony\Component\Config\Loader\LoaderResolver;
3336
use Symfony\Component\Config\Loader\DelegatingLoader;
34-
use Symfony\Component\Config\ConfigCache;
3537
use Symfony\Component\ClassLoader\ClassCollectionLoader;
3638

3739
/**
@@ -60,6 +62,11 @@ abstract class Kernel implements KernelInterface, TerminableInterface
6062
protected $startTime;
6163
protected $loadClassCache;
6264

65+
/**
66+
* @var ConfigCacheFactoryInterface
67+
*/
68+
private $configCacheFactory;
69+
6370
const VERSION = '2.7.0-DEV';
6471
const VERSION_ID = '20700';
6572
const MAJOR_VERSION = '2';
@@ -73,17 +80,19 @@ abstract class Kernel implements KernelInterface, TerminableInterface
7380
/**
7481
* Constructor.
7582
*
76-
* @pa 10000 ram string $environment The environment
77-
* @param bool $debug Whether to enable debugging or not
83+
* @param string $environment The environment
84+
* @param bool $debug Whether to enable debugging or not
85+
* @param ConfigCacheFactoryInterface $configCacheFactory The factory used to create the config cache
7886
*
7987
* @api
8088
*/
81-
public function __construct($environment, $debug)
89+
public function __construct($environment, $debug, ConfigCacheFactoryInterface $configCacheFactory = null)
8290
{
8391
$this->environment = $environment;
8492
$this->debug = (bool) $debug;
8593
$this->rootDir = $this->getRootDir();
8694
$this->name = $this->getName();
95+
$this->configCacheFactory = $configCacheFactory ?: new ConfigCacheFactory($this->debug);
8796

8897
if ($this->debug) {
8998
$this->startTime = microtime(true);
@@ -539,15 +548,15 @@ protected function getContainerBaseClass()
539548
protected function initializeContainer()
540549
{
541550
$class = $this->getContainerClass();
542-
$cache = new ConfigCache($this->getCacheDir().'/'.$class.'.php', $this->debug);
551+
$that = $this; // needed for compatibility with PHP 5.3, to be removed in Symfony 3.0
543552
$fresh = true;
544-
if (!$cache->isFresh()) {
553+
$cache = $this->configCacheFactory->cache($this->getCacheDir().'/'.$class.'.php', function (ConfigCacheInterface $cache) use ($that, &$fresh) {
545554
$container = $this->buildContainer();
546555
$container->compile();
547-
$this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());
556+
$that->dumpContainer($cache, $container, $that->getContainerClass(), $this->getContainerBaseClass());
548557

549558
$fresh = false;
550-
}
559+
});
551560

552561
require_once $cache->getPath();
553562

@@ -684,12 +693,12 @@ protected function getContainerBuilder()
684693
/**
685694
* Dumps the service container to PHP code in the cache.
686695
*
687-
* @param ConfigCache $cache The config cache
688-
* @param ContainerBuilder $container The service container
689-
* @param string $class The name of the class to generate
690-
* @param string $baseClass The name of the container's base class
696+
* @param ConfigCacheInterface $cache The config cache
697+
* @param ContainerBuilder $container The service container
698+
* @param string $class The name of the class to generate
699+
* @param string $baseClass The name of the container's base class
691700
*/
692-
protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass)
701+
protected function dumpContainer(ConfigCacheInterface $cache, ContainerBuilder $container, $class, $baseClass)
693702
{
694703
// cache the container
695704
$dumper = new PhpDumper($container);

0 commit comments

Comments
 (0)
0