Total Complexity | 12 |
Total Lines | 98 |
Duplicated Lines | 0 % |
Coverage | 91.67% |
Changes | 0 |
1 | <?php |
||
11 | class Engine |
||
12 | { |
||
13 | /** |
||
14 | * @var array |
||
15 | */ |
||
16 | private $data = []; |
||
17 | |||
18 | /** |
||
19 | * @param array $config |
||
20 | * @throws Exception |
||
21 | */ |
||
22 | 2 | public function config($config): void |
|
23 | { |
||
24 | 2 | $expected = ['environment', 'template_dir', 'cache_dir']; |
|
25 | |||
26 | 2 | foreach ($expected as $exp) { |
|
27 | 2 | if (count($config) == 3) { |
|
28 | 2 | if (!array_key_exists($exp, $config)) { |
|
29 | 2 | throw new Exception("The $exp configuration is expected"); |
|
30 | } |
||
31 | } else { |
||
32 | 2 | throw new Exception("The configuration expected only tree arguments"); |
|
33 | } |
||
34 | } |
||
35 | |||
36 | 2 | Tag::setConfig($config); |
|
37 | 2 | } |
|
38 | |||
39 | /** |
||
40 | * @param string $view |
||
41 | * @param array $data |
||
42 | * @return string |
||
43 | */ |
||
44 | 2 | public function render(string $view, array $data = []): string |
|
69 | } |
||
70 | |||
71 | /** |
||
72 | * @param $content |
||
73 | * @return string |
||
74 | */ |
||
75 | 2 | private function handle($content) |
|
76 | { |
||
77 | 2 | Tag::setContent($content); |
|
78 | |||
79 | 2 | $this->registerTag([ |
|
80 | 2 | 'inheritance', |
|
81 | 'include', |
||
82 | 'foreach', |
||
83 | 'if', |
||
84 | 'func', |
||
85 | 'variable' |
||
86 | ]); |
||
87 | |||
88 | 2 | return Tag::getContent(); |
|
89 | } |
||
90 | |||
91 | /** |
||
92 | * @param File $file |
||
93 | * @param $content |
||
94 | */ |
||
95 | 2 | private function setCache(File $file, $content): void |
|
96 | { |
||
97 | 2 | $file->create(); |
|
98 | 2 | $file->write($content); |
|
99 | 2 | } |
|
100 | |||
101 | /** |
||
102 | * @param array $tags |
||
103 | */ |
||
104 | 2 | private function registerTag(array $tags): void |
|
109 | } |
||
110 | 2 | } |
|
111 | } |
||
112 |