Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 8 additions & 45 deletions src/SharpInternalServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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();
}
}
Loading