|
1 | 1 | <?php namespace Flynsarmy\DbBladeCompiler;
|
2 | 2 |
|
3 |
| -use View, Closure, ArrayAccess; |
| 3 | +use ArrayAccess; |
4 | 4 | use Illuminate\Contracts\Support\Arrayable;
|
5 | 5 | use Illuminate\Contracts\Support\Renderable;
|
6 | 6 | use Illuminate\Config\Repository;
|
7 | 7 | use Illuminate\Database\Eloquent\Model;
|
| 8 | +use Illuminate\View\View as BaseView; |
| 9 | +use Illuminate\Support\Facades\View; |
| 10 | +use Throwable; |
8 | 11 |
|
9 |
| -class DbView extends \Illuminate\View\View implements ArrayAccess, Renderable |
| 12 | +class DbView extends BaseView implements ArrayAccess, Renderable |
10 | 13 | {
|
11 | 14 |
|
12 | 15 | protected $content_field = null;
|
@@ -67,20 +70,33 @@ public function field($content_field)
|
67 | 70 | */
|
68 | 71 | public function render(callable $callback = null)
|
69 | 72 | {
|
70 |
| - $contents = $this->renderContents(); |
| 73 | + $usesState = version_compare(app()->version(), '5.4.0') >= 0; |
71 | 74 |
|
72 |
| - $response = isset($callback) ? $callback($this, $contents) : null; |
| 75 | + try { |
| 76 | + $contents = $this->renderContents(); |
73 | 77 |
|
74 |
| - // Once we have the contents of the view, we will flush the sections if we are |
75 |
| - // done rendering all views so that there is nothing left hanging over when |
76 |
| - // anothoer view is rendered in the future by the application developers. |
77 |
| - // Before flushing, check Laravel version for correct method use |
78 |
| - if (version_compare(app()->version(), '5.4.0') >= 0) |
79 |
| - View::flushStateIfDoneRendering(); |
80 |
| - else |
81 |
| - View::flushSectionsIfDoneRendering(); |
| 78 | + $response = isset($callback) ? $callback($this, $contents) : null; |
82 | 79 |
|
83 |
| - return $response ?: $contents; |
| 80 | + // Once we have the contents of the view, we will flush the sections if we are |
| 81 | + // done rendering all views so that there is nothing left hanging over when |
| 82 | + // anothoer view is rendered in the future by the application developers. |
| 83 | + // Before flushing, check Laravel version for correct method use |
| 84 | + if ($usesState) { |
| 85 | + View::flushStateIfDoneRendering(); |
| 86 | + } else { |
| 87 | + View::flushSectionsIfDoneRendering(); |
| 88 | + } |
| 89 | + |
| 90 | + return $response ?: $contents; |
| 91 | + } catch (Throwable $exception) { |
| 92 | + if ($usesState) { |
| 93 | + View::flushState(); |
| 94 | + } else { |
| 95 | + View::flushSections(); |
| 96 | + } |
| 97 | + |
| 98 | + throw $exception; |
| 99 | + } |
84 | 100 | }
|
85 | 101 |
|
86 | 102 | /**
|
|
0 commit comments