Skip to content

Commit

Permalink
Merge pull request #388 from facade/registerable-exception-renderer-f…
Browse files Browse the repository at this point in the history
…or-laravel-9

[WIP] Register ExceptionRenderer to be used in Laravel 9
  • Loading branch information
AlexVanderbist authored Jul 12, 2021
2 parents 4368822 + 98b1975 commit 577f74c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"ext-mbstring": "*",
"facade/flare-client-php": "^1.6",
"facade/ignition-contracts": "^1.0.2",
"filp/whoops": "^2.4",
"illuminate/support": "^7.0|^8.0",
"monolog/monolog": "^2.0",
"symfony/console": "^5.0",
Expand Down
25 changes: 25 additions & 0 deletions src/ErrorPage/IgnitionExceptionRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Facade\Ignition\ErrorPage;

use Illuminate\Contracts\Foundation\ExceptionRenderer;

class IgnitionExceptionRenderer implements ExceptionRenderer
{
/** @var \Facade\Ignition\ErrorPage\ErrorPageHandler */
protected $errorPageHandler;

public function __construct(ErrorPageHandler $errorPageHandler)
{
$this->errorPageHandler = $errorPageHandler;
}

public function render($throwable)
{
ob_start();

$this->errorPageHandler->handle($throwable);

return ob_get_clean();
}
}
22 changes: 15 additions & 7 deletions src/IgnitionServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Facade\Ignition\Commands\TestCommand;
use Facade\Ignition\Context\LaravelContextDetector;
use Facade\Ignition\DumpRecorder\DumpRecorder;
use Facade\Ignition\ErrorPage\IgnitionExceptionRenderer;
use Facade\Ignition\ErrorPage\IgnitionWhoopsHandler;
use Facade\Ignition\ErrorPage\Renderer;
use Facade\Ignition\Exceptions\InvalidConfig;
Expand Down Expand Up @@ -69,7 +70,6 @@
use Livewire\CompilerEngineForIgnition;
use Monolog\Logger;
use Throwable;
use Whoops\Handler\HandlerInterface;

class IgnitionServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -121,8 +121,8 @@ public function register()

$this
->registerSolutionProviderRepository()
->registerRenderer()
->registerExceptionRenderer()
->registerWhoopsHandler()
->registerIgnitionConfig()
->registerFlare()
->registerDumpCollector();
Expand Down Expand Up @@ -204,7 +204,7 @@ protected function registerSolutionProviderRepository()
return $this;
}

protected function registerExceptionRenderer()
protected function registerRenderer()
{
$this->app->bind(Renderer::class, function () {
return new Renderer(__DIR__.'/../resources/views/');
Expand All @@ -213,11 +213,19 @@ protected function registerExceptionRenderer()
return $this;
}

protected function registerWhoopsHandler()
protected function registerExceptionRenderer()
{
$this->app->bind(HandlerInterface::class, function (Application $app) {
return $app->make(IgnitionWhoopsHandler::class);
});
if (interface_exists(\Whoops\Handler\HandlerInterface::class)) {
$this->app->bind(\Whoops\Handler\HandlerInterface::class, function (Application $app) {
return $app->make(IgnitionWhoopsHandler::class);
});
}

if (interface_exists(\Illuminate\Contracts\Foundation\ExceptionRenderer::class)) {
$this->app->bind(\Illuminate\Contracts\Foundation\ExceptionRenderer::class, function (Application $app) {
return $app->make(IgnitionExceptionRenderer::class);
});
}

return $this;
}
Expand Down

0 comments on commit 577f74c

Please sign in to comment.