1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,70 +0,0 @@ |
1 |
-<?php |
|
2 |
- |
|
3 |
-namespace Illuminate\View\Engines; |
|
4 |
- |
|
5 |
-use Exception; |
|
6 |
-use Throwable; |
|
7 |
-use Illuminate\Contracts\View\Engine; |
|
8 |
-use Symfony\Component\Debug\Exception\FatalThrowableError; |
|
9 |
- |
|
10 |
-class PhpEngine implements Engine |
|
11 |
-{ |
|
12 |
- /** |
|
13 |
- * Get the evaluated contents of the view. |
|
14 |
- * |
|
15 |
- * @param string $path |
|
16 |
- * @param array $data |
|
17 |
- * @return string |
|
18 |
- */ |
|
19 |
- public function get($path, array $data = []) |
|
20 |
- { |
|
21 |
- return $this->evaluatePath($path, $data); |
|
22 |
- } |
|
23 |
- |
|
24 |
- /** |
|
25 |
- * Get the evaluated contents of the view at the given path. |
|
26 |
- * |
|
27 |
- * @param string $__path |
|
28 |
- * @param array $__data |
|
29 |
- * @return string |
|
30 |
- */ |
|
31 |
- protected function evaluatePath($__path, $__data) |
|
32 |
- { |
|
33 |
- $obLevel = ob_get_level(); |
|
34 |
- |
|
35 |
- ob_start(); |
|
36 |
- |
|
37 |
- extract($__data, EXTR_SKIP); |
|
38 |
- |
|
39 |
- // We'll evaluate the contents of the view inside a try/catch block so we can |
|
40 |
- // flush out any stray output that might get out before an error occurs or |
|
41 |
- // an exception is thrown. This prevents any partial views from leaking. |
|
42 |
- try { |
|
43 |
- include $__path; |
|
44 |
- } catch (Exception $e) { |
|
45 |
- $this->handleViewException($e, $obLevel); |
|
46 |
- } catch (Throwable $e) { |
|
47 |
- $this->handleViewException(new FatalThrowableError($e), $obLevel); |
|
48 |
- } |
|
49 |
- |
|
50 |
- return ltrim(ob_get_clean()); |
|
51 |
- } |
|
52 |
- |
|
53 |
- /** |
|
54 |
- * Handle a view exception. |
|
55 |
- * |
|
56 |
- * @param \Exception $e |
|
57 |
- * @param int $obLevel |
|
58 |
- * @return void |
|
59 |
- * |
|
60 |
- * @throws \Exception |
|
61 |
- */ |
|
62 |
- protected function handleViewException(Exception $e, $obLevel) |
|
63 |
- { |
|
64 |
- while (ob_get_level() > $obLevel) { |
|
65 |
- ob_end_clean(); |
|
66 |
- } |
|
67 |
- |
|
68 |
- throw $e; |
|
69 |
- } |
|
70 |
-} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,70 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+namespace Illuminate\View\Engines; |
|
4 |
+ |
|
5 |
+use Exception; |
|
6 |
+use Throwable; |
|
7 |
+use Illuminate\Contracts\View\Engine; |
|
8 |
+use Symfony\Component\Debug\Exception\FatalThrowableError; |
|
9 |
+ |
|
10 |
+class PhpEngine implements Engine |
|
11 |
+{ |
|
12 |
+ /** |
|
13 |
+ * Get the evaluated contents of the view. |
|
14 |
+ * |
|
15 |
+ * @param string $path |
|
16 |
+ * @param array $data |
|
17 |
+ * @return string |
|
18 |
+ */ |
|
19 |
+ public function get($path, array $data = []) |
|
20 |
+ { |
|
21 |
+ return $this->evaluatePath($path, $data); |
|
22 |
+ } |
|
23 |
+ |
|
24 |
+ /** |
|
25 |
+ * Get the evaluated contents of the view at the given path. |
|
26 |
+ * |
|
27 |
+ * @param string $__path |
|
28 |
+ * @param array $__data |
|
29 |
+ * @return string |
|
30 |
+ */ |
|
31 |
+ protected function evaluatePath($__path, $__data) |
|
32 |
+ { |
|
33 |
+ $obLevel = ob_get_level(); |
|
34 |
+ |
|
35 |
+ ob_start(); |
|
36 |
+ |
|
37 |
+ extract($__data, EXTR_SKIP); |
|
38 |
+ |
|
39 |
+ // We'll evaluate the contents of the view inside a try/catch block so we can |
|
40 |
+ // flush out any stray output that might get out before an error occurs or |
|
41 |
+ // an exception is thrown. This prevents any partial views from leaking. |
|
42 |
+ try { |
|
43 |
+ include $__path; |
|
44 |
+ } catch (Exception $e) { |
|
45 |
+ $this->handleViewException($e, $obLevel); |
|
46 |
+ } catch (Throwable $e) { |
|
47 |
+ $this->handleViewException(new FatalThrowableError($e), $obLevel); |
|
48 |
+ } |
|
49 |
+ |
|
50 |
+ return ltrim(ob_get_clean()); |
|
51 |
+ } |
|
52 |
+ |
|
53 |
+ /** |
|
54 |
+ * Handle a view exception. |
|
55 |
+ * |
|
56 |
+ * @param \Exception $e |
|
57 |
+ * @param int $obLevel |
|
58 |
+ * @return void |
|
59 |
+ * |
|
60 |
+ * @throws \Exception |
|
61 |
+ */ |
|
62 |
+ protected function handleViewException(Exception $e, $obLevel) |
|
63 |
+ { |
|
64 |
+ while (ob_get_level() > $obLevel) { |
|
65 |
+ ob_end_clean(); |
|
66 |
+ } |
|
67 |
+ |
|
68 |
+ throw $e; |
|
69 |
+ } |
|
70 |
+} |