Skip to content

Commit be221e5

Browse files
committed
Merge branch 'registerable-exception-renderer'
2 parents a7970f7 + fe93d99 commit be221e5

File tree

5 files changed

+60
-32
lines changed

5 files changed

+60
-32
lines changed

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
"aws/aws-sdk-php": "^3.155",
8282
"doctrine/dbal": "^2.12|^3.0",
8383
"fakerphp/faker": "^1.9.2",
84-
"filp/whoops": "^2.8",
8584
"guzzlehttp/guzzle": "^7.2",
8685
"league/flysystem-aws-s3-v3": "^2.0",
8786
"league/flysystem-ftp": "^2.0",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Illuminate\Contracts\Foundation;
4+
5+
interface ExceptionRenderer
6+
{
7+
/**
8+
* Renders the given exception as HTML.
9+
*
10+
* @param \Throwable $throwable
11+
* @return string
12+
*/
13+
public function render($throwable);
14+
}

src/Illuminate/Foundation/Exceptions/Handler.php

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
use Exception;
77
use Illuminate\Auth\Access\AuthorizationException;
88
use Illuminate\Auth\AuthenticationException;
9-
use Illuminate\Contracts\Container\BindingResolutionException;
109
use Illuminate\Contracts\Container\Container;
1110
use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandlerContract;
11+
use Illuminate\Contracts\Foundation\ExceptionRenderer;
1212
use Illuminate\Contracts\Support\Responsable;
1313
use Illuminate\Database\Eloquent\ModelNotFoundException;
1414
use Illuminate\Database\MultipleRecordsFoundException;
@@ -37,8 +37,6 @@
3737
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
3838
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
3939
use Throwable;
40-
use Whoops\Handler\HandlerInterface;
41-
use Whoops\Run as Whoops;
4240

4341
class Handler implements ExceptionHandlerContract
4442
{
@@ -499,43 +497,23 @@ protected function convertExceptionToResponse(Throwable $e)
499497
protected function renderExceptionContent(Throwable $e)
500498
{
501499
try {
502-
return config('app.debug') && class_exists(Whoops::class)
503-
? $this->renderExceptionWithWhoops($e)
500+
return config('app.debug') && app()->has(ExceptionRenderer::class)
501+
? $this->renderExceptionWithCustomRenderer($e)
504502
: $this->renderExceptionWithSymfony($e, config('app.debug'));
505503
} catch (Exception $e) {
506504
return $this->renderExceptionWithSymfony($e, config('app.debug'));
507505
}
508506
}
509507

510508
/**
511-
* Render an exception to a string using "Whoops".
509+
* Render an exception to a string using the registered `ExceptionRenderer`.
512510
*
513511
* @param \Throwable $e
514512
* @return string
515513
*/
516-
protected function renderExceptionWithWhoops(Throwable $e)
514+
protected function renderExceptionWithCustomRenderer(Throwable $e)
517515
{
518-
return tap(new Whoops, function ($whoops) {
519-
$whoops->appendHandler($this->whoopsHandler());
520-
521-
$whoops->writeToOutput(false);
522-
523-
$whoops->allowQuit(false);
524-
})->handleException($e);
525-
}
526-
527-
/**
528-
* Get the Whoops handler for the application.
529-
*
530-
* @return \Whoops\Handler\Handler
531-
*/
532-
protected function whoopsHandler()
533-
{
534-
try {
535-
return app(HandlerInterface::class);
536-
} catch (BindingResolutionException $e) {
537-
return (new WhoopsHandler)->forDebug();
538-
}
516+
return app(ExceptionRenderer::class)->render($e);
539517
}
540518

541519
/**
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Illuminate\Foundation\Exceptions\Whoops;
4+
5+
use Illuminate\Contracts\Foundation\ExceptionRenderer;
6+
use function tap;
7+
use Whoops\Run as Whoops;
8+
9+
class WhoopsExceptionRenderer implements ExceptionRenderer
10+
{
11+
/**
12+
* Renders the given exception as HTML.
13+
*
14+
* @param \Throwable $throwable
15+
* @return string
16+
*/
17+
public function render($throwable)
18+
{
19+
return tap(new Whoops, function ($whoops) {
20+
$whoops->appendHandler($this->whoopsHandler());
21+
22+
$whoops->writeToOutput(false);
23+
24+
$whoops->allowQuit(false);
25+
})->handleException($throwable);
26+
}
27+
28+
/**
29+
* Get the Whoops handler for the application.
30+
*
31+
* @return \Whoops\Handler\Handler
32+
*/
33+
protected function whoopsHandler()
34+
{
35+
return (new WhoopsHandler)->forDebug();
36+
}
37+
}

src/Illuminate/Foundation/Exceptions/WhoopsHandler.php renamed to src/Illuminate/Foundation/Exceptions/Whoops/WhoopsHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Illuminate\Foundation\Exceptions;
3+
namespace Illuminate\Foundation\Exceptions\Whoops;
44

55
use Illuminate\Filesystem\Filesystem;
66
use Illuminate\Support\Arr;
@@ -19,8 +19,8 @@ public function forDebug()
1919
$handler->handleUnconditionally(true);
2020

2121
$this->registerApplicationPaths($handler)
22-
->registerBlacklist($handler)
23-
->registerEditor($handler);
22+
->registerBlacklist($handler)
23+
->registerEditor($handler);
2424
});
2525
}
2626

0 commit comments

Comments
 (0)