diff --git a/src/SharpInternalServiceProvider.php b/src/SharpInternalServiceProvider.php index 363cec182..28b36b4eb 100644 --- a/src/SharpInternalServiceProvider.php +++ b/src/SharpInternalServiceProvider.php @@ -49,10 +49,6 @@ use Illuminate\Support\Facades\Blade; use Illuminate\Support\ServiceProvider; use Inertia\ServiceProvider as InertiaServiceProvider; -use Laravel\Octane\Events\RequestReceived; -use Laravel\Octane\Events\RequestTerminated; -use Laravel\Octane\Events\TaskReceived; -use Laravel\Octane\Events\TickReceived; class SharpInternalServiceProvider extends ServiceProvider { @@ -89,25 +85,23 @@ public function boot() setlocale(LC_ALL, config('sharp.locale')); Carbon::setLocale(config('sharp.locale')); } - - $this->configureOctane(); } public function register() { - $this->app->singleton(SharpAuthorizationManager::class); - $this->app->singleton(CurrentSharpRequest::class); - $this->app->singleton(SharpMenuManager::class); - $this->app->singleton(SharpUploadManager::class); - $this->app->singleton(SharpUtil::class); - $this->app->singleton( + $this->app->scoped(SharpAuthorizationManager::class); + $this->app->scoped(CurrentSharpRequest::class); + $this->app->scoped(SharpMenuManager::class); + $this->app->scoped(SharpUploadManager::class); + $this->app->scoped(SharpUtil::class); + $this->app->scoped( SharpConfigBuilder::class, fn () => file_exists(config_path('sharp.php')) ? new SharpLegacyConfigBuilder() : new SharpConfigBuilder() ); - $this->app->singleton(SharpImageManager::class); - $this->app->singleton(AddLinkHeadersForPreloadedRequests::class); + $this->app->scoped(SharpImageManager::class); + $this->app->scoped(AddLinkHeadersForPreloadedRequests::class); if (class_exists('\PragmaRX\Google2FA\Google2FA')) { $this->app->bind( @@ -217,35 +211,4 @@ public function loadRoutes(): void $this->loadRoutesFrom(__DIR__.'/routes/auth/impersonate.php'); } } - - private function configureOctane(): void - { - if (isset($_SERVER['LARAVEL_OCTANE'])) { - $this->app['events']->listen(RequestReceived::class, function () { - $this->resetSharp(); - }); - - $this->app['events']->listen(TaskReceived::class, function () { - $this->resetSharp(); - }); - - $this->app['events']->listen(TickReceived::class, function () { - $this->resetSharp(); - }); - - $this->app['events']->listen(RequestTerminated::class, function () { - $this->resetSharp(); - }); - } - } - - private function resetSharp() - { - $this->app->get(SharpMenuManager::class)->reset(); - $this->app->get(SharpAuthorizationManager::class)->reset(); - $this->app->get(SharpUploadManager::class)->reset(); - $this->app->get(SharpUtil::class)->__construct(); - $this->app->get(SharpImageManager::class)->__construct(); - $this->app->get(AddLinkHeadersForPreloadedRequests::class)->reset(); - } }