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