Passed
Push — master ( f8e1da...c49986 )
by Edson
01:13
created

Engine   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 17 2
A config() 0 4 1
A handle() 0 10 1
1
<?php
2
3
namespace Sketch\Tpl;
4
5
class Engine extends Content
6
{
7
    private $config;
8
    private $data = [
9
        '__version' => '1.1.0',
10
    ];
11
12
    public function config(array $config): void
13
    {
14
        $this->data['__session'] = (object) $_SESSION;
15
        $this->config = $config;
16
    }
17
18
    public function render(string $view, array $data = []): string
19
    {
20
        $content = $this->handle($this->getContent($view, $this->config));
21
22
        $this->data = array_merge($data, $this->data);
23
24
        $fname = getcwd() . '/' . $this->config['cache_dir'] . '/' . $view . '.phtml';
25
26
        $file = new File;
27
28
        if ($file->create($fname) !== false) {
29
            $file->write($content);
30
            $content = $file->read($this->data);
31
            $file->close();
32
        }
33
34
        return $content;
35
    }
36
37
    private function handle($content)
38
    {
39
        $content = new Inheritance($content, $this->config);
40
        $content = new IncludeTpl($content, $this->config);
41
        $content = new ForeachTpl($content);
42
        $content = new IfTpl($content);
43
        $content = new FuncTpl($content);
44
        $content = new VariableTpl($content);
45
46
        return $content;
47
    }
48
}
49