Completed
Push — master ( 5a3352...e7f541 )
by Edson
01:28
created

Tpl::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 10
ccs 8
cts 8
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Bonfim\Component\View;
4
5
class Tpl
6
{
7
    use ParseTpl;
8
9 2
    public function render(string $view, array $data = []) : string
10
    {
11 2
        $content = $this->handle($this->getContent($view));
12
13 2
        $this->data = array_merge($data, $this->data);
14 2
        extract($this->data);
15
16 2
        $tmp = tmpfile();
17
18 2
        if ($tmp !== false) {
19 2
            fwrite($tmp, $content);
20 2
            fseek($tmp, 0);
21
22 2
            ob_start();
23 2
            $file = stream_get_meta_data($tmp);
24
25 2
            include $file['uri'];
26 2
            $content = ob_get_clean();
27 2
            fclose($tmp);
28
        }
29 2
        return $content;
30
    }
31
32 2
    private function handle($content)
33
    {
34 2
        $content = new Inheritance($content, $this->config);
35 2
        $content = new IncludeTpl($content, $this->config);
36 2
        $content = new ForeachTpl($content);
37 2
        $content = new IfTpl($content);
38 2
        $content = new FuncTpl($content);
39 2
        $content = new VariableTpl($content);
40
41 2
        return $content;
42
    }
43
}
44