@@ -479,6 +479,7 @@ protected function getContainerBaseClass()
479
479
*/
480
480
protected function initializeContainer ()
481
481
{
482
+ $ asFiles = $ this ->getKernelParameters ()['container.dump_as_files ' ] ?? true ;
482
483
$ class = $ this ->getContainerClass ();
483
484
$ cacheDir = $ this ->warmupDir ?: $ this ->getCacheDir ();
484
485
$ cache = new ConfigCache ($ cacheDir .'/ ' .$ class .'.php ' , $ this ->debug );
@@ -488,6 +489,13 @@ protected function initializeContainer()
488
489
$ errorLevel = error_reporting (\E_ALL ^ \E_WARNING );
489
490
$ fresh = $ oldContainer = false ;
490
491
try {
492
+ if (!$ asFiles ) {
493
+ require_once $ cache ->getPath ();
494
+ $ this ->container = new $ class ();
495
+ $ this ->container ->set ('kernel ' , $ this );
496
+
497
+ return ;
498
+ }
491
499
if (file_exists ($ cache ->getPath ()) && \is_object ($ this ->container = include $ cache ->getPath ())) {
492
500
$ this ->container ->set ('kernel ' , $ this );
493
501
$ oldContainer = $ this ->container ;
@@ -557,7 +565,7 @@ protected function initializeContainer()
557
565
}
558
566
}
559
567
560
- if (null === $ oldContainer && file_exists ($ cache ->getPath ())) {
568
+ if ($ asFiles && null === $ oldContainer && file_exists ($ cache ->getPath ())) {
561
569
$ errorLevel = error_reporting (\E_ALL ^ \E_WARNING );
562
570
try {
563
571
$ oldContainer = include $ cache ->getPath ();
@@ -569,7 +577,12 @@ protected function initializeContainer()
569
577
$ oldContainer = \is_object ($ oldContainer ) ? new \ReflectionClass ($ oldContainer ) : false ;
570
578
571
579
$ this ->dumpContainer ($ cache , $ container , $ class , $ this ->getContainerBaseClass ());
572
- $ this ->container = require $ cache ->getPath ();
580
+ if ($ asFiles ) {
581
+ $ this ->container = require $ cache ->getPath ();
582
+ } else {
583
+ require $ cache ->getPath ();
584
+ $ this ->container = new $ class ();
585
+ }
573
586
$ this ->container ->set ('kernel ' , $ this );
574
587
575
588
if ($ oldContainer && \get_class ($ this ->container ) !== $ oldContainer ->name ) {
@@ -731,26 +744,32 @@ protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container
731
744
$ dumper ->setProxyDumper (new ProxyDumper ());
732
745
}
733
746
747
+ $ asFiles = $ container ->hasParameter ('container.dump_as_files ' ) ? $ container ->getParameter ('container.dump_as_files ' ) : true ;
748
+
734
749
$ content = $ dumper ->dump ([
735
750
'class ' => $ class ,
736
751
'base_class ' => $ baseClass ,
737
752
'file ' => $ cache ->getPath (),
738
- 'as_files ' => true ,
753
+ 'as_files ' => $ asFiles ,
739
754
'debug ' => $ this ->debug ,
740
755
'build_time ' => $ container ->hasParameter ('kernel.container_build_time ' ) ? $ container ->getParameter ('kernel.container_build_time ' ) : time (),
741
756
]);
742
757
743
- $ rootCode = array_pop ($ content );
744
- $ dir = \dirname ($ cache ->getPath ()).'/ ' ;
745
- $ fs = new Filesystem ();
758
+ if ($ asFiles ) {
759
+ $ rootCode = array_pop ($ content );
760
+ $ dir = \dirname ($ cache ->getPath ()).'/ ' ;
761
+ $ fs = new Filesystem ();
746
762
747
- foreach ($ content as $ file => $ code ) {
748
- $ fs ->dumpFile ($ dir .$ file , $ code );
749
- @chmod ($ dir .$ file , 0666 & ~umask ());
750
- }
751
- $ legacyFile = \dirname ($ dir .$ file ).'.legacy ' ;
752
- if (file_exists ($ legacyFile )) {
753
- @unlink ($ legacyFile );
763
+ foreach ($ content as $ file => $ code ) {
764
+ $ fs ->dumpFile ($ dir .$ file , $ code );
765
+ @chmod ($ dir .$ file , 0666 & ~umask ());
766
+ }
767
+ $ legacyFile = \dirname ($ dir .$ file ).'.legacy ' ;
768
+ if (file_exists ($ legacyFile )) {
769
+ @unlink ($ legacyFile );
770
+ }
771
+ } else {
772
+ $ rootCode = $ content ;
754
773
}
755
774
756
775
$ cache ->write ($ rootCode , $ container ->getResources ());
0 commit comments