Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| HtmlEngine | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| get | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| canRender | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Engelsystem\Renderer; |
| 6 | |
| 7 | class HtmlEngine extends Engine |
| 8 | { |
| 9 | /** |
| 10 | * Render a template |
| 11 | * |
| 12 | * @param mixed[] $data |
| 13 | */ |
| 14 | public function get(string $path, array $data = []): string |
| 15 | { |
| 16 | $data = array_replace_recursive($this->sharedData, $data); |
| 17 | $template = file_get_contents($path); |
| 18 | |
| 19 | foreach ($data as $name => $content) { |
| 20 | $template = str_replace('%' . $name . '%', $content, $template); |
| 21 | } |
| 22 | |
| 23 | return $template; |
| 24 | } |
| 25 | |
| 26 | public function canRender(string $path): bool |
| 27 | { |
| 28 | return mb_strpos($path, '.htm') !== false && file_exists($path); |
| 29 | } |
| 30 | } |