10000 [HttpKernel] use ConfigCacheFactory to create ConfigCache instances by xabbuh · Pull Request #14636 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpKernel] use ConfigCacheFactory to create ConfigCache instances #14636

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 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions UPGRADE-2.7.md
Original file line number Diff line number Diff line change
@@ -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
------

Expand Down
37 changes: 23 additions & 14 deletions src/Symfony/Component/HttpKernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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';
Expand All @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we will accept this PR as I don't see the use case but in any case, this should be moved to a method instead of a constructor argument. I would even create a protected method like the getCacheDir() method, so configuration happen in the AppKernel class instead of whenever you need to create a Kernel instance (think tests for instance).

{
$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);
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down
0