1: | <?php declare(strict_types = 1); |
2: | |
3: | namespace ApiGen\Renderer\Latte; |
4: | |
5: | use Latte; |
6: | use Throwable; |
7: | |
8: | use function array_filter; |
9: | |
10: | |
11: | class LatteEngineFactory |
12: | { |
13: | public function __construct( |
14: | protected LatteExtension $extension, |
15: | protected ?string $tempDir, |
16: | protected ?string $themeDir, |
17: | ) { |
18: | } |
19: | |
20: | |
21: | public function create(): Latte\Engine |
22: | { |
23: | $latte = new Latte\Engine(); |
24: | $latte->setStrictTypes(); |
25: | $latte->setExceptionHandler(fn(Throwable $e) => throw $e); |
26: | $latte->setTempDirectory($this->tempDir); |
27: | $latte->setLoader(new LatteCascadingLoader(array_filter([$this->themeDir, __DIR__ . '/Template']))); |
28: | $latte->addExtension($this->extension); |
29: | |
30: | return $latte; |
31: | } |
32: | } |
33: | |