@@ -581,80 +581,92 @@ protected function initializeContainer()
581
581
$ class = $ this ->getContainerClass ();
582
582
$ cacheDir = $ this ->warmupDir ?: $ this ->getCacheDir ();
583
583
$ cache = new ConfigCache ($ cacheDir .'/ ' .$ class .'.php ' , $ this ->debug );
584
+ $ oldContainer = null ;
584
585
if ($ fresh = $ cache ->isFresh ()) {
585
586
// Silence E_WARNING to ignore "include" failures - don't use "@" to prevent silencing fatal errors
586
587
$ errorLevel = error_reporting (\E_ALL ^ \E_WARNING );
588
+ $ fresh = $ oldContainer = false ;
587
589
try {
588
590
$ this ->container = include $ cache ->getPath ();
591
+ if (\is_object ($ this ->container )) {
592
+ $ this ->container ->set ('kernel ' , $ this );
593
+ $ oldContainer = $ this ->container ;
594
+ $ fresh = true ;
595
+ }
596
+ } catch (\Throwable $ e ) {
597
+ } catch (\Exception $ e ) {
589
598
} finally {
590
599
error_reporting ($ errorLevel );
591
600
}
592
- $ fresh = \is_object ($ this ->container );
593
601
}
594
- if (!$ fresh ) {
595
- if ($ this ->debug ) {
596
- $ collectedLogs = array ();
597
- $ previousHandler = defined ('PHPUNIT_COMPOSER_INSTALL ' );
598
- $ previousHandler = $ previousHandler ?: set_error_handler (function ($ type , $ message , $ file , $ line ) use (&$ collectedLogs , &$ previousHandler ) {
599
- if (E_USER_DEPRECATED !== $ type && E_DEPRECATED !== $ type ) {
600
- return $ previousHandler ? $ previousHandler ($ type & ~E_WARNING , $ message , $ file , $ line ) : E_WARNING === $ type ;
601
- }
602
602
603
- if (isset ($ collectedLogs [$ message ])) {
604
- ++$ collectedLogs [$ message ]['count ' ];
603
+ if ($ fresh ) {
604
+ return ;
605
+ }
605
606
606
- return ;
607
- }
607
+ if ($ this ->debug ) {
608
+ $ collectedLogs = array ();
609
+ $ previousHandler = defined ('PHPUNIT_COMPOSER_INSTALL ' );
610
+ $ previousHandler = $ previousHandler ?: set_error_handler (function ($ type , $ message , $
F438
span>file , $ line ) use (&$ collectedLogs , &$ previousHandler ) {
611
+ if (E_USER_DEPRECATED !== $ type && E_DEPRECATED !== $ type ) {
612
+ return $ previousHandler ? $ previousHandler ($ type , $ message , $ file , $ line ) : false ;
613
+ }
614
+
615
+ if (isset ($ collectedLogs [$ message ])) {
616
+ ++$ collectedLogs [$ message ]['count ' ];
617
+
618
+ return ;
619
+ }
608
620
609
- $ backtrace = debug_backtrace (DEBUG_BACKTRACE_IGNORE_ARGS , 3 );
610
- // Clean the trace by removing first frames added by the error handler itself.
611
- for ($ i = 0 ; isset ($ backtrace [$ i ]); ++$ i ) {
612
- if (isset ($ backtrace [$ i ]['file ' ], $ backtrace [$ i ]['line ' ]) && $ backtrace [$ i ]['line ' ] === $ line && $ backtrace [$ i ]['file ' ] === $ file ) {
613
- $ backtrace = array_slice ($ backtrace , 1 + $ i );
614
- break ;
615
- }
621
+ $ backtrace = debug_backtrace (DEBUG_BACKTRACE_IGNORE_ARGS , 3 );
622
+ // Clean the trace by removing first frames added by the error handler itself.
623
+ for ($ i = 0 ; isset ($ backtrace [$ i ]); ++$ i ) {
624
+ if (isset ($ backtrace [$ i ]['file ' ], $ backtrace [$ i ]['line ' ]) && $ backtrace [$ i ]['line ' ] === $ line && $ backtrace [$ i ]['file ' ] === $ file ) {
625
+ $ backtrace = array_slice ($ backtrace , 1 + $ i );
626
+ break ;
616
627
}
628
+ }
617
629
618
- $ collectedLogs [$ message ] = array (
619
- 'type ' => $ type ,
620
- 'message ' => $ message ,
621
- 'file ' => $ file ,
622
- 'line ' => $ line ,
623
- 'trace ' => $ backtrace ,
624
- 'count ' => 1 ,
625
- );
626
- });
627
- } else {
628
- $ errorLevel = error_reporting (\E_ALL ^ \E_WARNING );
630
+ $ collectedLogs [$ message ] = array (
631
+ 'type ' => $ type ,
632
+ 'message ' => $ message ,
633
+ 'file ' => $ file ,
634
+ 'line ' => $ line ,
635
+ 'trace ' => $ backtrace ,
636
+ 'count ' => 1 ,
637
+ );
638
+ });
639
+ }
640
+
641
+ try {
642
+ $ container = null ;
643
+ $ container = $ this ->buildContainer ();
644
+ $ container ->compile ();
645
+ } finally {
646
+ if ($ this ->debug && true !== $ previousHandler ) {
647
+ restore_error_handler ();
648
+
649
+ file_put_contents ($ cacheDir .'/ ' .$ class .'Deprecations.log ' , serialize (array_values ($ collectedLogs )));
650
+ file_put_contents ($ cacheDir .'/ ' .$ class .'Compiler.log ' , null !== $ container ? implode ("\n" , $ container ->getCompiler ()->getLog ()) : '' );
629
651
}
652
+ }
630
653
654
+ if (null === $ oldContainer ) {
655
+ $ errorLevel = error_reporting (\E_ALL ^ \E_WARNING );
631
656
try {
632
- $ container = null ;
633
- $ container = $ this ->buildContainer ();
634
- $ container ->compile ();
635
-
636
- $ oldContainer = file_exists ($ cache ->getPath ()) && is_object ($ oldContainer = include $ cache ->getPath ()) ? new \ReflectionClass ($ oldContainer ) : false ;
657
+ $ oldContainer = include $ cache ->getPath ();
658
+ } catch (\Throwable $ e ) {
659
+ } catch (\Exception $ e ) {
637
660
} finally {
638
- if (!$ this ->debug ) {
639
- error_reporting ($ errorLevel );
640
- } elseif (true !== $ previousHandler ) {
641
- restore_error_handler ();
642
-
643
- file_put_contents ($ cacheDir .'/ ' .$ class .'Deprecations.log ' , serialize (array_values ($ collectedLogs )));
644
- file_put_contents ($ cacheDir .'/ ' .$ class .'Compiler.log ' , null !== $ container ? implode ("\n" , $ container ->getCompiler ()->getLog ()) : '' );
645
- }
661
+ error_reporting ($ errorLevel );
646
662
}
647
-
648
- $ this ->dumpContainer ($ cache , $ container , $ class , $ this ->getContainerBaseClass ());
649
- $ this ->container = require $ cache ->getPath ();
650
663
}
664
+ $ oldContainer = is_object ($ oldContainer ) ? new \ReflectionClass ($ oldContainer ) : false ;
651
665
666
+ $ this ->dumpContainer ($ cache , $ container , $ class , $ this ->getContainerBaseClass ());
667
+ $ this ->container = require $ cache ->getPath ();
652
668
$ this ->container ->set ('kernel ' , $ this );
653
669
654
- if ($ fresh ) {
655
- return ;
656
- }
657
-
658
670
if ($ oldContainer && get_class ($ this ->container ) !== $ oldContainer ->name ) {
659
671
// Because concurrent requests might still be using them,
660
672
// old container files are not removed immediately,
0 commit comments