diff --git a/UPGRADE-2.7.md b/UPGRADE-2.7.md index f491c7d471ba2..3f0eb4969d610 100644 --- a/UPGRADE-2.7.md +++ b/UPGRADE-2.7.md @@ -1,6 +1,12 @@ UPGRADE FROM 2.6 to 2.7 ======================= +HttpKernel +---------- + + * The `$cache` argument type of the `dumpContainer()` method in the `Symfony\Component\HttpKernel\Kernel` + class was changed from `Symfony\Component\Config\ConfigCache` to `Symfony\Component\Config\ConfigCacheInterface`. + Router ------ diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 27beac75f7546..7e90092a913c0 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -13,6 +13,9 @@ use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator; use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper; +use Symfony\Component\Config\ConfigCacheFactory; +use Symfony\Component\Config\ConfigCacheFactoryInterface; +use Symfony\Component\Config\ConfigCacheInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Dumper\PhpDumper; @@ -31,7 +34,6 @@ use Symfony\Component\HttpKernel\DependencyInjection\AddClassesToCachePass; use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\Config\Loader\DelegatingLoader; -use Symfony\Component\Config\ConfigCache; use Symfony\Component\ClassLoader\ClassCollectionLoader; /** @@ -60,6 +62,11 @@ abstract class Kernel implements KernelInterface, TerminableInterface protected $startTime; protected $loadClassCache; + /** + * @var ConfigCacheFactoryInterface + */ + private $configCacheFactory; + const VERSION = '2.7.0-DEV'; const VERSION_ID = '20700'; const MAJOR_VERSION = '2'; @@ -73,17 +80,19 @@ abstract class Kernel implements KernelInterface, TerminableInterface /** * Constructor. * - * @param string $environment The environment - * @param bool $debug Whether to enable debugging or not + * @param string $environment The environment + * @param bool $debug Whether to enable debugging or not + * @param ConfigCacheFactoryInterface $configCacheFactory The factory used to create the config cache * * @api */ - public function __construct($environment, $debug) + public function __construct($environment, $debug, ConfigCacheFactoryInterface $configCacheFactory = null) { $this->environment = $environment; $this->debug = (bool) $debug; $this->rootDir = $this->getRootDir(); $this->name = $this->getName(); + $this->configCacheFactory = $configCacheFactory ?: new ConfigCacheFactory($this->debug); if ($this->debug) { $this->startTime = microtime(true); @@ -539,15 +548,15 @@ protected function getContainerBaseClass() protected function initializeContainer() { $class = $this->getContainerClass(); - $cache = new ConfigCache($this->getCacheDir().'/'.$class.'.php', $this->debug); + $that = $this; // needed for compatibility with PHP 5.3, to be removed in Symfony 3.0 $fresh = true; - if (!$cache->isFresh()) { - $container = $this->buildContainer(); + $cache = $this->configCacheFactory->cache($this->getCacheDir().'/'.$class.'.php', function (ConfigCacheInterface $cache) use ($that, &$fresh) { + $container = $that->buildContainer(); $container->compile(); - $this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass()); + $that->dumpContainer($cache, $container, $that->getContainerClass(), $that->getContainerBaseClass()); $fresh = false; - } + }); require_once $cache->getPath(); @@ -684,12 +693,12 @@ protected function getContainerBuilder() /** * Dumps the service container to PHP code in the cache. * - * @param ConfigCache $cache The config cache - * @param ContainerBuilder $container The service container - * @param string $class The name of the class to generate - * @param string $baseClass The name of the container's base class + * @param ConfigCacheInterface $cache The config cache + * @param ContainerBuilder $container The service container + * @param string $class The name of the class to generate + * @param string $baseClass The name of the container's base class */ - protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass) + protected function dumpContainer(ConfigCacheInterface $cache, ContainerBuilder $container, $class, $baseClass) { // cache the container $dumper = new PhpDumper($container);