1 | <?php |
||
28 | class TwigView extends View |
||
29 | { |
||
30 | public const EXT = '.twig'; |
||
31 | |||
32 | public const ENV_CONFIG = 'WyriHaximus.TwigView.environment'; |
||
33 | |||
34 | /** |
||
35 | * Extension to use. |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $_ext = self::EXT; |
||
40 | |||
41 | /** |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $extensions = [ |
||
45 | self::EXT, |
||
46 | '.php', |
||
47 | ]; |
||
48 | |||
49 | /** |
||
50 | * Twig instance. |
||
51 | * |
||
52 | * @var \Twig\Environment |
||
53 | */ |
||
54 | protected $twig; |
||
55 | |||
56 | /** |
||
57 | * Return empty string when View instance is cast to string. |
||
58 | * |
||
59 | * @return string |
||
60 | */ |
||
61 | public function __toString(): string |
||
65 | |||
66 | /** |
||
67 | * Initialize view. |
||
68 | * |
||
69 | */ |
||
70 | 17 | public function initialize(): void |
|
80 | |||
81 | /** |
||
82 | * @param string $extension |
||
83 | */ |
||
84 | public function unshiftExtension($extension) |
||
88 | |||
89 | /** |
||
90 | * Get twig environment instance. |
||
91 | * |
||
92 | * @return \Twig\Environment |
||
93 | */ |
||
94 | 5 | public function getTwig(): Environment |
|
98 | |||
99 | /** |
||
100 | * @internal |
||
101 | */ |
||
102 | 4 | public function setTwig(Environment $twig): void |
|
106 | |||
107 | /** |
||
108 | * @return array |
||
109 | */ |
||
110 | 17 | protected function resolveConfig(): array |
|
134 | |||
135 | /** |
||
136 | * @return array |
||
137 | */ |
||
138 | 17 | protected function readConfig(): array |
|
151 | |||
152 | /** |
||
153 | * Create the template loader. |
||
154 | * |
||
155 | * @return \WyriHaximus\TwigView\Lib\Twig\Loader |
||
156 | */ |
||
157 | 17 | protected function getLoader(): Loader |
|
164 | |||
165 | /** |
||
166 | * Render the template. |
||
167 | * |
||
168 | * @param string $viewFile Template file. |
||
169 | * @param array $data Data that can be used by the template. |
||
170 | * |
||
171 | * @throws \Exception |
||
172 | * @return string |
||
173 | */ |
||
174 | 3 | protected function _render(string $viewFile, array $data = []): string |
|
206 | |||
207 | /** |
||
208 | * @param string|null $name |
||
209 | * @throws \Exception |
||
210 | * @return string |
||
211 | */ |
||
212 | 3 | protected function _getTemplateFileName(?string $name = null): string |
|
226 | |||
227 | /** |
||
228 | * @param string|null $name |
||
229 | * @throws \Exception |
||
230 | * @return string |
||
231 | */ |
||
232 | 1 | protected function _getLayoutFileName(?string $name = null): string |
|
246 | |||
247 | /** |
||
248 | * @param string $name |
||
249 | * @param bool $pluginCheck |
||
250 | * @return string|bool |
||
251 | */ |
||
252 | protected function _getElementFileName(string $name, bool $pluginCheck = true) |
||
264 | } |
||
265 |