Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Pipe through render and report exception methods #36032

Merged
merged 1 commit into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Illuminate/Foundation/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use Illuminate\Session\TokenMismatchException;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Reflector;
use Illuminate\Support\Traits\ReflectsClosures;
use Illuminate\Support\ViewErrorBag;
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/View/Engines/CompilerEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Illuminate\View\Engines;

use ErrorException;
use Illuminate\Filesystem\Filesystem;
use Illuminate\View\Compilers\CompilerInterface;
use Illuminate\View\ViewException;
use Throwable;

class CompilerEngine extends PhpEngine
Expand Down Expand Up @@ -76,7 +76,7 @@ public function get($path, array $data = [])
*/
protected function handleViewException(Throwable $e, $obLevel)
{
$e = new ErrorException($this->getMessage($e), 0, 1, $e->getFile(), $e->getLine(), $e);
$e = new ViewException($this->getMessage($e), 0, 1, $e->getFile(), $e->getLine(), $e);

parent::handleViewException($e, $obLevel);
}
Expand Down
37 changes: 37 additions & 0 deletions src/Illuminate/View/ViewException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Illuminate\View;

use ErrorException;

class ViewException extends ErrorException
{
/**
* Report the exception.
*
* @return void
*/
public function report()
{
$exception = $this->getPrevious();

if ($exception && method_exists('report', $exception)) {
$exception->report();
}
}

/**
* Render the exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function render($request)
{
$exception = $this->getPrevious();

if ($exception && method_exists($exception, 'render')) {
return $exception->render($request);
}
}
}
36 changes: 36 additions & 0 deletions tests/Integration/View/RenderableViewExceptionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Illuminate\Tests\Integration\View;

use Exception;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\View;
use Orchestra\Testbench\TestCase;

class RenderableViewExceptionTest extends TestCase
{
public function testRenderMethodOfExceptionThrownInViewGetsHandled()
{
Route::get('/', function () {
return View::make('renderable-exception');
});

$response = $this->get('/');

$response->assertSee('This is a renderable exception.');
}

protected function getEnvironmentSetUp($app)
{
$app['config']->set('view.paths', [__DIR__.'/templates']);
}
}

class RenderableException extends Exception
{
public function render($request)
{
return new Response('This is a renderable exception.');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@php
throw new Illuminate\Tests\Integration\View\RenderableException;
@endphp
1 change: 0 additions & 1 deletion tests/View/fixtures/nested/basic.php
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
Hello World