Conditions | 2 |
Paths | 2 |
Total Lines | 17 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
20 | public function render(string $filename, array $data): string |
||
21 | { |
||
22 | $templateContents = file_get_contents($filename); |
||
23 | preg_match_all('/{{ *([a-zA-Z_0-9-]*)? *}}/', $templateContents, $templateVars); |
||
24 | |||
25 | $templateVarNames = array_unique(array_map(function ($item) { |
||
26 | return trim($item); |
||
27 | }, $templateVars[1])); |
||
28 | |||
29 | $tokenized = preg_replace('/{{ *([a-zA-Z_0-9-]*)? *}}/', '{{$1}}', $templateContents); |
||
30 | |||
31 | $varLength = count($templateVars); |
||
|
|||
32 | |||
33 | foreach ($templateVarNames as $toReplace) { |
||
34 | $tokenized = str_replace('{{' . $toReplace . '}}', $data[$toReplace] ?? '', $tokenized); |
||
35 | } |
||
36 | return $tokenized; |
||
37 | } |
||
39 |