88use Illuminate \Foundation \Bootstrap \RegisterProviders ;
99use Illuminate \Foundation \Bootstrap \SetRequestForConsole ;
1010use Illuminate \Support \Facades \Facade ;
11+ use Laravel \Octane \Swoole \Coroutine \CoroutineApplication ;
1112use ReflectionObject ;
1213use RuntimeException ;
1314
@@ -31,6 +32,7 @@ public function createApplication(array $initialInstances = []): Application
3132 if (file_exists ($ path )) {
3233 $ inCoroutine = class_exists (\Swoole \Coroutine::class) && \Swoole \Coroutine::getCid () > 0 ;
3334 $ previousContainer = null ;
35+ $ bootstrapContainer = null ;
3436 $ previousContextApp = null ;
3537 $ previousCurrentApp = null ;
3638 $ previousFacadeApp = null ;
@@ -39,6 +41,7 @@ public function createApplication(array $initialInstances = []): Application
3941
4042 if ($ inCoroutine ) {
4143 $ previousContainer = Container::getInstance ();
44+ $ bootstrapContainer = $ previousContainer ;
4245 $ previousFacadeApp = Facade::getFacadeApplication ();
4346 $ hadContextApp = \Laravel \Octane \Swoole \Coroutine \Context::has ('octane.app ' );
4447 $ previousContextApp = $ hadContextApp
@@ -55,7 +58,11 @@ public function createApplication(array $initialInstances = []): Application
5558 if ($ inCoroutine ) {
5659 // Restore the coroutine proxy as the global container and
5760 // point the current coroutine at the app being bootstrapped.
58- Container::setInstance ($ previousContainer );
61+ if (! $ bootstrapContainer instanceof Application) {
62+ $ bootstrapContainer = new CoroutineApplication ($ app );
63+ }
64+
65+ Container::setInstance ($ bootstrapContainer );
5966 \Laravel \Octane \Swoole \Coroutine \Context::set ('octane.app ' , $ app );
6067 \Laravel \Octane \Swoole \Coroutine \Context::set ('octane.current_app ' , $ app );
6168 }
0 commit comments