These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace League\Plates\RenderTemplate; |
||
4 | |||
5 | use League\Plates; |
||
6 | |||
7 | final class PhpRenderTemplate implements Plates\RenderTemplate |
||
8 | { |
||
9 | private $bind; |
||
10 | |||
11 | 16 | public function __construct(callable $bind = null) { |
|
12 | 16 | $this->bind = $bind; |
|
13 | 16 | } |
|
14 | |||
15 | 16 | public function renderTemplate(Plates\Template $template, Plates\RenderTemplate $render = null) { |
|
16 | 16 | $inc = self::createInclude(); |
|
17 | 16 | $inc = $this->bind ? ($this->bind)($inc, $template) : $inc; |
|
18 | |||
19 | 16 | $cur_level = ob_get_level(); |
|
20 | try { |
||
21 | 16 | return $inc($template->get('path'), $template->data); |
|
22 | } catch (\Exception $e) {} |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
Loading history...
|
|||
23 | catch (\Throwable $e) {} |
||
24 | |||
25 | // clean the ob stack |
||
26 | while (ob_get_level() > $cur_level) { |
||
27 | ob_end_clean(); |
||
28 | } |
||
29 | |||
30 | throw $e; |
||
31 | } |
||
32 | |||
33 | private static function createInclude() { |
||
34 | 16 | return function() { |
|
35 | 16 | ob_start(); |
|
36 | 16 | extract(func_get_arg(1)); |
|
37 | 16 | include func_get_arg(0); |
|
38 | 16 | return ob_get_clean(); |
|
39 | 16 | }; |
|
40 | } |
||
41 | } |
||
42 |