43
43
*
44
44
* @author Fabien Potencier <fabien@symfony.com>
45
45
*/
46
- abstract class Kernel implements KernelInterface, TerminableInterface
46
+ abstract class Kernel implements KernelInterface, RebootableInterface, TerminableInterface
47
47
{
48
48
/**
49
49
* @var BundleInterface[]
@@ -61,6 +61,7 @@ abstract class Kernel implements KernelInterface, TerminableInterface
61
61
protected $ loadClassCache ;
62
62
63
63
private $ projectDir ;
64
+ private $ warmupDir ;
64
65
65
66
const VERSION = '3.4.0-DEV ' ;
66
67
const VERSION_ID = 30400 ;
@@ -127,6 +128,16 @@ public function boot()
127
128
$ this ->booted = true ;
128
129
}
129
130
131
+ /**
132
+ * {@inheritdoc}
133
+ */
134
+ public function reboot ($ warmupDir )
135
+ {
136
+ $ this ->shutdown ();
137
+ $ this ->warmupDir = $ warmupDir ;
138
+ $ this ->boot ();
139
+ }
140
+
130
141
/**
131
142
* {@inheritdoc}
132
143
*/
@@ -373,15 +384,15 @@ public function setClassCache(array $classes)
373
384
@trigger_error (__METHOD__ .'() is deprecated since version 3.3, to be removed in 4.0. ' , E_USER_DEPRECATED );
374
385
}
375
386
376
- file_put_contents ($ this ->getCacheDir ().'/classes.map ' , sprintf ('<?php return %s; ' , var_export ($ classes , true )));
387
+ file_put_contents (( $ this ->warmupDir ?: $ this -> getCacheDir () ).'/classes.map ' , sprintf ('<?php return %s; ' , var_export ($ classes , true )));
377
388
}
378
389
379
390
/**
380
391
* @internal
381
392
*/
382
393
public function setAnnotatedClassCache (array $ annotatedClasses )
383
394
{
384
- file_put_contents ($ this ->getCacheDir ().'/annotations.map ' , sprintf ('<?php return %s; ' , var_export ($ annotatedClasses , true )));
395
+ file_put_contents (( $ this ->warmupDir ?: $ this -> getCacheDir () ).'/annotations.map ' , sprintf ('<?php return %s; ' , var_export ($ annotatedClasses , true )));
385
396
}
386
397
387
398
/**
@@ -424,9 +435,10 @@ protected function doLoadClassCache($name, $extension)
424
435
if (\PHP_VERSION_ID >= 70000 ) {
425
436
@trigger_error (__METHOD__ .'() is deprecated since version 3.3, to be removed in 4.0. ' , E_USER_DEPRECATED );
426
437
}
438
+ $ cacheDir = $ this ->warmupDir ?: $ this ->getCacheDir ();
427
439
428
- if (!$ this ->booted && is_file ($ this -> getCacheDir () .'/classes.map ' )) {
429
- ClassCollectionLoader::load (include ($ this -> getCacheDir () .'/classes.map ' ), $ this -> getCacheDir () , $ name , $ this ->debug , false , $ extension );
440
+ if (!$ this ->booted && is_file ($ cacheDir .'/classes.map ' )) {
441
+ ClassCollectionLoader::load (include ($ cacheDir .'/classes.map ' ), $ cacheDir , $ name , $ this ->debug , false , $ extension );
430
442
}
431
443
}
432
444
@@ -536,7 +548,8 @@ protected function getContainerBaseClass()
536
548
protected function initializeContainer ()
537
549
{
538
550
$ class = $ this ->getContainerClass ();
539
- $ cache = new ConfigCache ($ this ->getCacheDir ().'/ ' .$ class .'.php ' , $ this ->debug );
551
+ $ cacheDir = $ this ->warmupDir ?: $ this ->getCacheDir ();
552
+ $ cache = new ConfigCache ($ cacheDir .'/ ' .$ class .'.php ' , $ this ->debug );
540
553
$ fresh = true ;
541
554
if (!$ cache ->isFresh ()) {
542
555
if ($ this ->debug ) {
@@ -580,8 +593,8 @@ protected function initializeContainer()
580
593
if ($ this ->debug ) {
581
594
restore_error_handler ();
582
595
583
- file_put_contents ($ this -> getCacheDir () .'/ ' .$ class .'Deprecations.log ' , serialize (array_values ($ collectedLogs )));
584
- file_put_contents ($ this -> getCacheDir () .'/ ' .$ class .'Compiler.log ' , null !== $ container ? implode ("\n" , $ container ->getCompiler ()->getLog ()) : '' );
596
+ file_put_contents ($ cacheDir .'/ ' .$ class .'Deprecations.log ' , serialize (array_values ($ collectedLogs )));
597
+ file_put_contents ($ cacheDir .'/ ' .$ class .'Compiler.log ' , null !== $ container ? implode ("\n" , $ container ->getCompiler ()->getLog ()) : '' );
585
598
}
586
599
}
587
600
@@ -636,7 +649,7 @@ protected function getKernelParameters()
636
649
'kernel.environment ' => $ this ->environment ,
637
650
'kernel.debug ' => $ this ->debug ,
638
651
'kernel.name ' => $ this ->name ,
639
- 'kernel.cache_dir ' => realpath ($ this ->getCacheDir ()) ?: $ this ->getCacheDir (),
652
+ 'kernel.cache_dir ' => realpath ($ cacheDir = $ this ->warmupDir ?: $ this ->getCacheDir ()) ?: $ cacheDir ,
640
653
'kernel.logs_dir ' => realpath ($ this ->getLogDir ()) ?: $ this ->getLogDir (),
641
654
'kernel.bundles ' => $ bundles ,
642
655
'kernel.bundles_metadata ' => $ bundlesMetadata ,
@@ -682,7 +695,7 @@ protected function getEnvParameters()
682
695
*/
683
696
protected function buildContainer ()
684
697
{
685
- foreach (array ('cache ' => $ this ->getCacheDir (), 'logs ' => $ this ->getLogDir ()) as $ name => $ dir ) {
698
+ foreach (array ('cache ' => $ this ->warmupDir ?: $ this -> getCacheDir (), 'logs ' => $ this ->getLogDir ()) as $ name => $ dir ) {
686
699
if (!is_dir ($ dir )) {
687
700
if (false === @mkdir ($ dir , 0777 , true ) && !is_dir ($ dir )) {
688
701
throw new \RuntimeException (sprintf ("Unable to create the %s directory (%s) \n" , $ name , $ dir ));
0 commit comments