-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pipe through render and report exception methods (#36032)
- Loading branch information
1 parent
3464d02
commit 7e73bd2
Showing
6 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.'); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
tests/Integration/View/templates/renderable-exception.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@php | ||
throw new Illuminate\Tests\Integration\View\RenderableException; | ||
@endphp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
Hello World | ||