From 7a49dbc6f6aa17c19b4c194063c8f10ec45b41e0 Mon Sep 17 00:00:00 2001 From: Mohamed Said Date: Wed, 21 Apr 2021 12:03:39 +0200 Subject: [PATCH 1/4] give new app instance to database manager --- .../ProvidesDefaultConfigurationOptions.php | 1 + ...ewApplicationInstanceToDatabaseManager.php | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/Listeners/GiveNewApplicationInstanceToDatabaseManager.php diff --git a/src/Concerns/ProvidesDefaultConfigurationOptions.php b/src/Concerns/ProvidesDefaultConfigurationOptions.php index 3dcd6fef..561f9a4f 100644 --- a/src/Concerns/ProvidesDefaultConfigurationOptions.php +++ b/src/Concerns/ProvidesDefaultConfigurationOptions.php @@ -33,6 +33,7 @@ public static function prepareApplicationForNextOperation(): array return [ \Laravel\Octane\Listeners\CreateConfigurationSandbox::class, \Laravel\Octane\Listeners\GiveNewApplicationInstanceToAuthorizationGate::class, + \Laravel\Octane\Listeners\GiveNewApplicationInstanceToDatabaseManager::class, \Laravel\Octane\Listeners\GiveNewApplicationInstanceToBroadcastManager::class, \Laravel\Octane\Listeners\GiveNewApplicationInstanceToHttpKernel::class, \Laravel\Octane\Listeners\GiveNewApplicationInstanceToMailManager::class, diff --git a/src/Listeners/GiveNewApplicationInstanceToDatabaseManager.php b/src/Listeners/GiveNewApplicationInstanceToDatabaseManager.php new file mode 100644 index 00000000..46dee855 --- /dev/null +++ b/src/Listeners/GiveNewApplicationInstanceToDatabaseManager.php @@ -0,0 +1,23 @@ +sandbox->resolved('db')) { + return; + } + + with($event->sandbox->make('db'), function ($manager) use ($event) { + $manager->setApplication($event->sandbox); + }); + } +} From 716bb09b6d89bf188902a5d437b038901804f821 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 21 Apr 2021 07:54:07 -0500 Subject: [PATCH 2/4] Update ProvidesDefaultConfigurationOptions.php --- src/Concerns/ProvidesDefaultConfigurationOptions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Concerns/ProvidesDefaultConfigurationOptions.php b/src/Concerns/ProvidesDefaultConfigurationOptions.php index 561f9a4f..b59a35c9 100644 --- a/src/Concerns/ProvidesDefaultConfigurationOptions.php +++ b/src/Concerns/ProvidesDefaultConfigurationOptions.php @@ -33,8 +33,8 @@ public static function prepareApplicationForNextOperation(): array return [ \Laravel\Octane\Listeners\CreateConfigurationSandbox::class, \Laravel\Octane\Listeners\GiveNewApplicationInstanceToAuthorizationGate::class, - \Laravel\Octane\Listeners\GiveNewApplicationInstanceToDatabaseManager::class, \Laravel\Octane\Listeners\GiveNewApplicationInstanceToBroadcastManager::class, + \Laravel\Octane\Listeners\GiveNewApplicationInstanceToDatabaseManager::class, \Laravel\Octane\Listeners\GiveNewApplicationInstanceToHttpKernel::class, \Laravel\Octane\Listeners\GiveNewApplicationInstanceToMailManager::class, \Laravel\Octane\Listeners\GiveNewApplicationInstanceToNotificationChannelManager::class, From 44fd2fa2cf3a33d426b29e90fc2606a3540b3dff Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 21 Apr 2021 08:00:34 -0500 Subject: [PATCH 3/4] Update GiveNewApplicationInstanceToDatabaseManager.php --- src/Listeners/GiveNewApplicationInstanceToDatabaseManager.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Listeners/GiveNewApplicationInstanceToDatabaseManager.php b/src/Listeners/GiveNewApplicationInstanceToDatabaseManager.php index 46dee855..e2de5700 100644 --- a/src/Listeners/GiveNewApplicationInstanceToDatabaseManager.php +++ b/src/Listeners/GiveNewApplicationInstanceToDatabaseManager.php @@ -12,7 +12,8 @@ class GiveNewApplicationInstanceToDatabaseManager */ public function handle($event): void { - if (! $event->sandbox->resolved('db')) { + if (! $event->sandbox->resolved('db') || + ! method_exists($event->sandbox->make('db'), 'setApplication')) { return; } From 0ee166909fc3a55efea4a68d67fe15dac62279d0 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 21 Apr 2021 08:00:51 -0500 Subject: [PATCH 4/4] Apply fixes from StyleCI (#226) --- src/Listeners/GiveNewApplicationInstanceToDatabaseManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Listeners/GiveNewApplicationInstanceToDatabaseManager.php b/src/Listeners/GiveNewApplicationInstanceToDatabaseManager.php index e2de5700..c15b5980 100644 --- a/src/Listeners/GiveNewApplicationInstanceToDatabaseManager.php +++ b/src/Listeners/GiveNewApplicationInstanceToDatabaseManager.php @@ -12,7 +12,7 @@ class GiveNewApplicationInstanceToDatabaseManager */ public function handle($event): void { - if (! $event->sandbox->resolved('db') || + if (! $event->sandbox->resolved('db') || ! method_exists($event->sandbox->make('db'), 'setApplication')) { return; }