Total Complexity | 3 |
Total Lines | 20 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
18 | class TemplateEngine |
||
19 | { |
||
20 | private readonly Twig $twig; |
||
|
|||
21 | |||
22 | 41 | public function __construct(Twig $twig = null) |
|
23 | { |
||
24 | 41 | $this->twig = $twig ?? new Twig( |
|
25 | 39 | new FilesystemLoader(__DIR__ . '/../resources/templates'), |
|
26 | 39 | ['strict_variables' => true] |
|
27 | ); |
||
28 | 41 | $this->twig->addFilter(new Filter( |
|
29 | 'whitespace', |
||
30 | 41 | static fn (string $html): ?string => preg_replace('/\s\s+/', '', $html) |
|
31 | )); |
||
32 | } |
||
33 | |||
34 | /** @param mixed[] $values */ |
||
35 | 32 | public function render(string $template, array $values): string |
|
36 | { |
||
37 | try { |
||
38 | 32 | return $this->twig->render($template, $values); |
|
44 |