13
13
14
14
use Symfony \Bridge \ProxyManager \LazyProxy \Instantiator \RuntimeInstantiator ;
15
15
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 ;
16
19
use Symfony \Component \DependencyInjection \ContainerInterface ;
17
20
use Symfony \Component \DependencyInjection \ContainerBuilder ;
18
21
use Symfony \Component \DependencyInjection \Dumper \PhpDumper ;
@@ -60,6 +63,11 @@ abstract class Kernel implements KernelInterface, TerminableInterface
60
63
protected $ startTime ;
61
64
protected $ loadClassCache ;
62
65
66
+ /**
67
+ * @var ConfigCacheFactoryInterface
68
+ */
69
+ private $ configCacheFactory ;
70
+
63
71
const VERSION = '2.7.0-DEV ' ;
64
72
const VERSION_ID = '20700 ' ;
65
73
const MAJOR_VERSION = '2 ' ;
@@ -73,17 +81,19 @@ abstract class Kernel implements KernelInterface, TerminableInterface
73
81
/**
74
82
* Constructor.
75
83
*
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
78
87
*
79
88
* @api
80
89
*/
81
- public function __construct ($ environment , $ debug )
90
+ public function __construct ($ environment , $ debug, ConfigCacheFactoryInterface $ configCacheFactory = null )
82
91
{
83
92
$ this ->environment = $ environment ;
84
93
$ this ->debug = (bool ) $ debug ;
85
94
$ this ->rootDir = $ this ->getRootDir ();
86
95
$ this ->name = $ this ->getName ();
96
+ $ this ->configCacheFactory = $ configCacheFactory ?: new ConfigCacheFactory ($ this ->debug );
87
97
88
98
if ($ this ->debug ) {
89
99
$ this ->startTime = microtime (true );
@@ -539,15 +549,15 @@ protected function getContainerBaseClass()
539
549
protected function initializeContainer ()
540
550
{
541
551
$ 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
543
553
$ fresh = true ;
544
- if (! $ cache-> isFresh () ) {
554
+ $ c
8000
ache = $ this -> configCacheFactory -> cache ( $ this -> getCacheDir (). ' / ' . $ class . ' .php ' , function ( ConfigCacheInterface $ cache ) use ( $ that , & $ fresh ) {
545
555
$ container = $ this ->buildContainer ();
546
556
$ container ->compile ();
547
- $ this ->dumpContainer ($ cache , $ container , $ class , $ this ->getContainerBaseClass ());
557
+ $ that ->dumpContainer ($ cache , $ container , $ that -> getContainerClass () , $ this ->getContainerBaseClass ());
548
558
549
559
$ fresh = false ;
550
- }
560
+ });
551
561
552
562
require_once $ cache ->getPath ();
553
563
@@ -684,12 +694,12 @@ protected function getContainerBuilder()
684
694
/**
685
695
* Dumps the service container to PHP code in the cache.
686
696
*
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
691
701
*/
692
- protected function dumpContainer (ConfigCache $ cache , ContainerBuilder $ container , $ class , $ baseClass )
702
+ protected function dumpContainer (ConfigCacheInterface $ cache , ContainerBuilder $ container , $ class , $ baseClass )
693
703
{
694
704
// cache the container
695
705
$ dumper = new PhpDumper ($ container );
0 commit comments