Skip to content
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
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 Exception;
use Illuminate\View\Compilers\CompilerInterface;
use Illuminate\View\ViewException;

class CompilerEngine extends PhpEngine
{
Expand Down Expand Up @@ -74,7 +74,7 @@ public function get($path, array $data = [])
*/
protected function handleViewException(Exception $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($exception, 'report')) {
$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