Skip to content

Commit df0c4d1

Browse files
committed
Update ApplicationFactory.php
1 parent 83b7ee4 commit df0c4d1

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/ApplicationFactory.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Foundation\Bootstrap\RegisterProviders;
99
use Illuminate\Foundation\Bootstrap\SetRequestForConsole;
1010
use Illuminate\Support\Facades\Facade;
11+
use Laravel\Octane\Swoole\Coroutine\CoroutineApplication;
1112
use ReflectionObject;
1213
use 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

Comments
 (0)