Skip to content

Commit

Permalink
Formatting and config merging
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVanderbist committed Jan 11, 2022
1 parent 8e1bd4a commit 5fe42bc
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions src/IgnitionServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class IgnitionServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->registerConfig();
$this->registerFlare();
$this->registerIgnition();
$this->registerRenderer();
Expand All @@ -53,6 +54,7 @@ public function boot()
{
if ($this->app->runningInConsole()) {
$this->registerCommands();
$this->publishConfigs();
}

$this->configureTinker();
Expand All @@ -64,6 +66,12 @@ public function boot()
$this->configureQueue();
}

protected function registerConfig(): void
{
$this->mergeConfigFrom(__DIR__ . '/../config/flare.php', 'flare');
$this->mergeConfigFrom(__DIR__ . '/../config/ignition.php', 'ignition');
}

protected function registerCommands(): void
{
if ($this->app['config']->get('flare.key')) {
Expand All @@ -80,20 +88,28 @@ protected function registerCommands(): void
}
}

protected function publishConfigs(): void
{
$this->publishes([
__DIR__ . '/../config/flare.php' => config_path('flare.php'),
__DIR__ . '/../config/ignition.php' => config_path('ignition.php'),
]);
}

protected function registerRenderer(): void
{
if (interface_exists('Whoops\Handler\HandlerInterface')) {
$this->app->bind(
'Whoops\Handler\HandlerInterface',
fn (Application $app) => $app->make(IgnitionWhoopsHandler::class)
fn(Application $app) => $app->make(IgnitionWhoopsHandler::class)
);
}


if (interface_exists('Illuminate\Contracts\Foundation\ExceptionRenderer')) {
$this->app->bind(
'Illuminate\Contracts\Foundation\ExceptionRenderer',
fn (Application $app) => $app->make(IgnitionExceptionRenderer::class)
fn(Application $app) => $app->make(IgnitionExceptionRenderer::class)
);
}
}
Expand All @@ -119,11 +135,11 @@ protected function registerIgnition(): void
$solutionProviders = $this->getSolutionProviders();
$solutionProviderRepository = new SolutionProviderRepository($solutionProviders);

$this->app->singleton(IgnitionConfig::class, fn () => $ignitionConfig);
$this->app->singleton(IgnitionConfig::class, fn() => $ignitionConfig);

$this->app->singleton(SolutionProviderRepositoryContract::class, fn () => $solutionProviderRepository);
$this->app->singleton(SolutionProviderRepositoryContract::class, fn() => $solutionProviderRepository);

$this->app->singleton(Ignition::class, fn () => (new Ignition()));
$this->app->singleton(Ignition::class, fn() => (new Ignition()));
}

protected function registerRecorders(): void
Expand Down Expand Up @@ -158,7 +174,7 @@ function (Application $app): QueryRecorder {

public function configureTinker(): void
{
if (! $this->app->runningInConsole()) {
if (!$this->app->runningInConsole()) {
if (isset($_SERVER['argv']) && ['artisan', 'tinker'] === $_SERVER['argv']) {
app(Flare::class)->sendReportsImmediately();
}
Expand All @@ -176,7 +192,7 @@ protected function registerViewExceptionMapper(): void
{
$handler = $this->app->make(ExceptionHandler::class);

if (! method_exists($handler, 'map')) {
if (!method_exists($handler, 'map')) {
return;
}

Expand Down Expand Up @@ -221,11 +237,11 @@ protected function registerLogHandler(): void

return tap(
new Logger('Flare'),
fn (Logger $logger) => $logger->pushHandler($handler)
fn(Logger $logger) => $logger->pushHandler($handler)
);
});

Log::extend('flare', fn ($app) => $app['flare.logger']);
Log::extend('flare', fn($app) => $app['flare.logger']);
}

protected function startRecorders(): void
Expand All @@ -243,7 +259,7 @@ protected function startRecorders(): void

protected function configureQueue(): void
{
if (! $this->app->bound('queue')) {
if (!$this->app->bound('queue')) {
return;
}

Expand All @@ -267,7 +283,7 @@ protected function getLogLevel(string $logLevelString): int
{
$logLevel = Logger::getLevels()[strtoupper($logLevelString)] ?? null;

if (! $logLevel) {
if (!$logLevel) {
throw InvalidConfig::invalidLogLevel($logLevelString);
}

Expand Down Expand Up @@ -296,7 +312,7 @@ protected function getSolutionProviders(): array
{
return collect(config('ignition.solution_providers'))
->reject(
fn (string $class) => in_array($class, config('ignition.ignored_solution_providers'))
fn(string $class) => in_array($class, config('ignition.ignored_solution_providers'))
)
->toArray();
}
Expand Down

0 comments on commit 5fe42bc

Please sign in to comment.