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

Skip to content

Commit b57891f

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

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
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

+22Lines changed: 22 additions & 12 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;
@@ -60,6 +63,11 @@ abstract class Kernel implements KernelInterface, TerminableInterface
6063
protected $startTime;
6164
protected $loadClassCache;
6265

66+
/**
67+
* @var ConfigCacheFactoryInterface
68+
*/
69+
private $configCacheFactory;
70+
6371
const VERSION = '2.7.0-DEV';
6472
const VERSION_ID = '20700';
6573
const MAJOR_VERSION = '2';
@@ -73,17 +81,19 @@ abstract class Kernel implements KernelInterface, TerminableInterface
7381
/**
7482
* Constructor.
7583
*
76-
* @param string $environment The environment
77-
* @param bool $debug Whether to enable debugging or not
84+
* @param string $environment The environment
85+
* @param bool $debug Whether to enable debugging or not
86+
* @param ConfigCacheFactoryInterface $configCacheFactory The factory used to create the config cache
7887
*
7988
* @api
8089
*/
81-
public function __construct($environment, $debug)
90+
public function __construct($environment, $debug, ConfigCacheFactoryInterface $configCacheFactory = null)
8291
{
8392
$this->environment = $environment;
8493
$this->debug = (bool) $debug;
8594
$this->rootDir = $this->getRootDir();
8695
$this->name = $this->getName();
96+
$this->configCacheFactory = $configCacheFactory ?: new ConfigCacheFactory($this->debug);
8797

8898
if ($this->debug) {
8999
$this->startTime = microtime(true);
@@ -539,15 +549,15 @@ protected function getContainerBaseClass()
539549
protected function initializeContainer()
540550
{
541551
$class = $this->getContainerClass();
542-
$cache = new ConfigCache($this->getCacheDir().'/'.$class.'.php', $this->debug);
552+
$that = $this; // needed for compatibility with PHP 5.3, to be removed in Symfony 3.0
543553
$fresh = true;
544-
if (!$cache->isFresh()) {
554+
$c 8000 ache = $this->configCacheFactory->cache($this->getCacheDir().'/'.$class.'.php', function (ConfigCacheInterface $cache) use ($that, &$fresh) {
545555
$container = $this->buildContainer();
546556
$container->compile();
547-
$this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());
557+
$that->dumpContainer($cache, $container, $that->getContainerClass(), $this->getContainerBaseClass());
548558

549559
$fresh = false;
550-
}
560+
});
551561

552562
require_once $cache->getPath();
553563

@@ -684,12 +694,12 @@ protected function getContainerBuilder()
684694
/**
685695
* Dumps the service container to PHP code in the cache.
686696
*
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
697+
* @param ConfigCacheInterface $cache The config cache
698+
* @param ContainerBuilder $container The service container
699+
* @param string $class The name of the class to generate
700+
* @param string $baseClass The name of the container's base class
691701
*/
692-
protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass)
702+
protected function dumpContainer(ConfigCacheInterface $cache, ContainerBuilder $container, $class, $baseClass)
693703
{
694704
// cache the container
695705
$dumper = new PhpDumper($container);

0 commit comments

Comments
 (0)
0