@@ -572,18 +572,25 @@ protected function getContainerBaseClass()
572
572
*/
573
573
protected function initializeContainer ()
574
574
{
575
+ $ asFiles = true ;
575
576
$ class = $ this ->getContainerClass ();
576
577
$ cacheDir = $ this ->warmupDir ?: $ this ->getCacheDir ();
577
578
$ cache = new ConfigCache ($ cacheDir .'/ ' .$ class .'.php ' , $ this ->debug );
578
579
$ oldContainer = null ;
579
580
if ($ fresh = $ cache ->isFresh ()) {
581
+ if (!$ asFiles ) {
582
+ require_once $ cache ->getPath ();
583
+ $ this ->container = new $ class ();
584
+ $ this ->container ->set ('kernel ' , $ this );
585
+
586
+ return ;
587
+ }
580
588
// Silence E_WARNING to ignore "include" failures - don't use "@" to prevent silencing fatal errors
581
589
$ errorLevel = error_reporting (\E_ALL ^ \E_WARNING );
582
590
$ fresh = $ oldContainer = false ;
583
591
try {
584
592
if (file_exists ($ cache ->getPath ()) && \is_object ($ this ->container = include $ cache ->getPath ())) {
585
593
$ this ->container ->set ('kernel ' , $ this );
586
- $ oldContainer = $ this ->container ;
587
594
$ fresh = true ;
588
595
}
589
596
} catch (\Throwable $ e ) {
@@ -634,6 +641,13 @@ protected function initializeContainer()
634
641
try {
635
642
$ container = null ;
636
643
$ container = $ this ->buildContainer ();
644
+ if ($ asFiles ) {
645
+ $ container ->getParameterBag ()->add ([
646
+ 'container.build_id ' => 'static ' ,
647
+ 'container.build_hash ' => 'static ' ,
648
+ 'container.as_files ' => true ,
649
+ ]);
650
+ }
637
651
$ container ->compile ();
638
652
} finally {
639
653
if ($ this ->debug && true !== $ previousHandler ) {
@@ -657,7 +671,12 @@ protected function initializeContainer()
657
671
$ oldContainer = \is_object ($ oldContainer ) ? new \ReflectionClass ($ oldContainer ) : false ;
658
672
659
673
$ this ->dumpContainer ($ cache , $ container , $ class , $ this ->getContainerBaseClass ());
660
- $ this ->container = require $ cache ->getPath ();
674
+ if ($ asFiles ) {
675
+ $ this ->container = require $ cache ->getPath ();
676
+ } else {
677
+ require $ cache ->getPath ();
678
+ $ this ->container = new $ class ();
679
+ }
661
680
$ this ->container ->set ('kernel ' , $ this );
662
681
663
682
if ($ oldContainer && \get_class ($ this ->container ) !== $ oldContainer ->name ) {
@@ -844,27 +863,33 @@ protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container
844
863
$ dumper ->setProxyDumper (new ProxyDumper ());
845
864
}
846
865
866
+ $ asFiles = $ container ->hasParameter ('container.as_files ' ) ? $ container ->getParameter ('container.as_files ' ) : true ;
867
+
847
868
$ content = $ dumper ->dump ([
848
869
'class ' => $ class ,
849
870
'base_class ' => $ baseClass ,
850
871
'file ' => $ cache ->getPath (),
851
- 'as_files ' => true ,
872
+ 'as_files ' => $ asFiles ,
852
873
'debug ' => $ this ->debug ,
853
874
'inline_class_loader_parameter ' => \PHP_VERSION_ID >= 70000 && !$ this ->loadClassCache && !class_exists (ClassCollectionLoader::class, false ) ? 'container.dumper.inline_class_loader ' : null ,
854
875
'build_time ' => $ container ->hasParameter ('kernel.container_build_time ' ) ? $ container ->getParameter ('kernel.container_build_time ' ) : time (),
855
876
]);
856
877
857
- $ rootCode = array_pop ($ content );
858
- $ dir = \dirname ($ cache ->getPath ()).'/ ' ;
859
- $ fs = new Filesystem ();
878
+ if ($ asFiles ) {
879
+ $ rootCode = array_pop ($ content );
880
+ $ dir = \dirname ($ cache ->getPath ()).'/ ' ;
881
+ $ fs = new Filesystem ();
860
882
861
- foreach ($ content as $ file => $ code ) {
862
- $ fs ->dumpFile ($ dir .$ file , $ code );
863
- @chmod ($ dir .$ file , 0666 & ~umask ());
864
- }
865
- $ legacyFile = \dirname ($ dir .$ file ).'.legacy ' ;
866
- if (file_exists ($ legacyFile )) {
867
- @unlink ($ legacyFile );
883
+ foreach ($ content as $ file => $ code ) {
884
+ $ fs ->dumpFile ($ dir .$ file , $ code );
885
+ @chmod ($ dir .$ file , 0666 & ~umask ());
886
+ }
887
+ $ legacyFile = \dirname ($ dir .$ file ).'.legacy ' ;
888
+ if (file_exists ($ legacyFile )) {
889
+ @unlink ($ legacyFile );
890
+ }
891
+ } else {
892
+ $ rootCode = $ content ;
868
893
}
869
894
870
895
$ cache ->write ($ rootCode , $ container ->getResources ());
0 commit comments