From e5fb8d1e73c88dcd2625b436c17734134cd7b4ca Mon Sep 17 00:00:00 2001 From: Alex Vanderbist Date: Tue, 11 Jan 2022 18:52:28 +0100 Subject: [PATCH] Refactor to regular service provider --- composer.json | 1 - src/IgnitionServiceProvider.php | 56 +++++++++++++++------------------ 2 files changed, 25 insertions(+), 32 deletions(-) diff --git a/composer.json b/composer.json index ac55dfac..41e24cec 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,6 @@ "ext-mbstring": "*", "monolog/monolog": "^2.0", "spatie/ignition": "^0.0.2", - "spatie/laravel-package-tools": "^1.9", "symfony/console": "^5.0|^6.0", "symfony/var-dumper": "^5.0|^6.0", "illuminate/support": "^8.44|^9.0" diff --git a/src/IgnitionServiceProvider.php b/src/IgnitionServiceProvider.php index 0d805da5..8ce735b4 100644 --- a/src/IgnitionServiceProvider.php +++ b/src/IgnitionServiceProvider.php @@ -3,10 +3,10 @@ namespace Spatie\LaravelIgnition; use Illuminate\Contracts\Debug\ExceptionHandler; -use Illuminate\Contracts\Foundation\ExceptionRenderer; use Illuminate\Foundation\Application; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Route; +use Illuminate\Support\ServiceProvider; use Illuminate\View\ViewException; use Laravel\Octane\Events\RequestReceived; use Laravel\Octane\Events\TaskReceived; @@ -38,20 +38,10 @@ use Spatie\LaravelIgnition\Support\FlareLogHandler; use Spatie\LaravelIgnition\Support\SentReports; use Spatie\LaravelIgnition\Views\ViewExceptionMapper; -use Spatie\LaravelPackageTools\Package; -use Spatie\LaravelPackageTools\PackageServiceProvider; -use Whoops\Handler\HandlerInterface; -class IgnitionServiceProvider extends PackageServiceProvider +class IgnitionServiceProvider extends ServiceProvider { - public function configurePackage(Package $package): void - { - $package - ->name('laravel-ignition') - ->hasConfigFile(['flare', 'ignition']); - } - - public function packageRegistered(): void + public function register(): void { $this->registerFlare(); $this->registerIgnition(); @@ -59,46 +49,50 @@ public function packageRegistered(): void $this->registerRecorders(); } - public function bootingPackage() + public function boot() + { + if ($this->app->runningInConsole()) { + $this->registerCommands(); + } + + $this->configureTinker(); + $this->configureOctane(); + $this->registerViewExceptionMapper(); + $this->registerRoutes(); + $this->registerLogHandler(); + $this->startRecorders(); + $this->configureQueue(); + } + + protected function registerCommands(): void { if ($this->app['config']->get('flare.key')) { - $this->package->hasCommands([ + $this->commands([ TestCommand::class, ]); } if ($this->app['config']->get('ignition.register_commands')) { - $this->package->hasCommands([ + $this->commands([ SolutionMakeCommand::class, SolutionProviderMakeCommand::class, ]); } } - public function packageBooted(): void - { - $this->configureTinker(); - $this->configureOctane(); - $this->registerViewExceptionMapper(); - $this->registerRoutes(); - $this->registerLogHandler(); - $this->startRecorders(); - $this->configureQueue(); - } - protected function registerRenderer(): void { - if (interface_exists(HandlerInterface::class)) { + if (interface_exists('Whoops\Handler\HandlerInterface')) { $this->app->bind( - HandlerInterface::class, + 'Whoops\Handler\HandlerInterface', fn (Application $app) => $app->make(IgnitionWhoopsHandler::class) ); } - if (interface_exists(ExceptionRenderer::class)) { + if (interface_exists('Illuminate\Contracts\Foundation\ExceptionRenderer')) { $this->app->bind( - ExceptionRenderer::class, + 'Illuminate\Contracts\Foundation\ExceptionRenderer', fn (Application $app) => $app->make(IgnitionExceptionRenderer::class) ); }