Skip to content

Commit

Permalink
Refactor to regular service provider
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVanderbist committed Jan 11, 2022
1 parent 76a2e62 commit e5fb8d1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 32 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
56 changes: 25 additions & 31 deletions src/IgnitionServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,67 +38,61 @@
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();
$this->registerRenderer();
$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)
);
}
Expand Down

0 comments on commit e5fb8d1

Please sign in to comment.