Completed
Push — 183-default-layout-ext ( a97107 )
by
unknown
10:37
created

src/RenderTemplate/PhpRenderTemplate.php (1 issue)

Upgrade to new PHP Analysis Engine

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
    public function __construct(callable $bind = null) {
12
        $this->bind = $bind;
13
    }
14
15
    public function renderTemplate(Plates\Template $template, Plates\RenderTemplate $render = null) {
16
        $inc = self::createInclude();
17
        $inc = $this->bind ? ($this->bind)($inc, $template) : $inc;
18
19
        $cur_level = ob_get_level();
20
        try {
21
            return $inc($template->get('path'), $template->data);
22
        } catch (\Exception $e) {}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
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
        return function() {
35
            ob_start();
36
            extract(func_get_arg(1));
37
            include func_get_arg(0);
38
            return ob_get_clean();
39
        };
40
    }
41
}
42