diff --git a/src/Auth/SharpAuthorizationManager.php b/src/Auth/SharpAuthorizationManager.php index 43d3b5737..8fb8c2b6c 100644 --- a/src/Auth/SharpAuthorizationManager.php +++ b/src/Auth/SharpAuthorizationManager.php @@ -77,4 +77,9 @@ private function deny() { throw new SharpAuthorizationException('Unauthorized action'); } + + public function reset(): void + { + $this->cachedPolicies = []; + } } diff --git a/src/Http/Middleware/AddLinkHeadersForPreloadedRequests.php b/src/Http/Middleware/AddLinkHeadersForPreloadedRequests.php index d174be25d..6f874aadd 100644 --- a/src/Http/Middleware/AddLinkHeadersForPreloadedRequests.php +++ b/src/Http/Middleware/AddLinkHeadersForPreloadedRequests.php @@ -39,6 +39,11 @@ public function handle(Request $request, $next) }); } + public function reset(): void + { + $this->preloadedRequests = []; + } + private function isSafari(): bool { return str_contains(request()->userAgent(), 'Safari') diff --git a/src/SharpInternalServiceProvider.php b/src/SharpInternalServiceProvider.php index e21673ed6..c9ec52810 100644 --- a/src/SharpInternalServiceProvider.php +++ b/src/SharpInternalServiceProvider.php @@ -49,6 +49,10 @@ 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 { @@ -85,6 +89,8 @@ public function boot() setlocale(LC_ALL, config('sharp.locale')); Carbon::setLocale(config('sharp.locale')); } + + $this->configureOctane(); } public function register() @@ -211,4 +217,35 @@ 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(); + } } diff --git a/src/Utils/Menu/SharpMenu.php b/src/Utils/Menu/SharpMenu.php index f30ff9b3a..a47692150 100644 --- a/src/Utils/Menu/SharpMenu.php +++ b/src/Utils/Menu/SharpMenu.php @@ -60,4 +60,13 @@ final public function isVisible(): bool } abstract public function build(): self; + + final public function reset(): self + { + $this->items = []; + $this->userMenu = null; + $this->visible = true; + + return $this; + } } diff --git a/src/Utils/Menu/SharpMenuManager.php b/src/Utils/Menu/SharpMenuManager.php index 9993942a9..903aaefde 100644 --- a/src/Utils/Menu/SharpMenuManager.php +++ b/src/Utils/Menu/SharpMenuManager.php @@ -85,4 +85,12 @@ private function filterSeparators(Collection $items): Collection return $filtered->reverse(); } + + public function reset(): void + { + if ($this->menu) { + $this->menu->reset(); + $this->buildMenu(); + } + } } diff --git a/src/Utils/Uploads/SharpUploadManager.php b/src/Utils/Uploads/SharpUploadManager.php index 9727a100d..2b9efae1f 100644 --- a/src/Utils/Uploads/SharpUploadManager.php +++ b/src/Utils/Uploads/SharpUploadManager.php @@ -52,4 +52,10 @@ public function queueHandleTransformedFile( 'transformFilters', ); } + + public function reset(): void + { + $this->uploadedFileQueue = []; + $this->transformedFileQueue = []; + } }