1 | <?php |
||
14 | final class TwigConfiguration implements ConfigurationInterface |
||
15 | { |
||
16 | use EnvTrait; |
||
17 | |||
18 | const PREFIX = 'TWIG_'; |
||
19 | |||
20 | 1 | public function apply(Injector $injector) |
|
21 | { |
||
22 | 1 | $env = $this->env; |
|
23 | |||
24 | 1 | $path = $env->getValue('TWIG_TEMPLATES'); |
|
25 | |||
26 | 1 | $injector->define(FilesystemLoader::class, [ |
|
27 | 1 | ':path' => $path, |
|
28 | 1 | ':fileExtensions' => $this->fileExtensions($env), |
|
29 | ]); |
||
30 | |||
31 | 1 | $injector->define(Twig_Environment::class, [ |
|
32 | 1 | 'loader' => FilesystemLoader::class, |
|
33 | 1 | ':options' => $this->options($env), |
|
34 | ]); |
||
35 | 1 | } |
|
36 | |||
37 | 1 | private function fileExtensions(Env $env): array |
|
38 | { |
||
39 | 1 | $fileExtensions = $env->getValue('TWIG_FILE_EXTENSIONS', 'html.twig,twig'); |
|
40 | |||
41 | 1 | return explode(',', $fileExtensions); |
|
42 | } |
||
43 | |||
44 | 1 | private function options(Env $env): array |
|
45 | { |
||
46 | 1 | static $options = [ |
|
47 | 'debug' => false, |
||
48 | 'strict_variables' => false, |
||
49 | 'cache' => false, |
||
50 | 'auto_reload' => false, |
||
51 | 'charset' => 'UTF-8', |
||
52 | 'autoescape' => 'html', |
||
53 | 'base_template_class' => 'Twig_Template', |
||
54 | 'optimizations' => -1, |
||
55 | ]; |
||
56 | |||
57 | 1 | foreach ($this->envTwig($env) as $option => $value) { |
|
58 | 1 | list(, $option) = explode('_', strtolower($option), 2); |
|
59 | 1 | if (isset($options[$option])) { |
|
60 | 1 | $options[$option] = $value; |
|
61 | } |
||
62 | } |
||
63 | |||
64 | 1 | return $options; |
|
65 | } |
||
66 | |||
67 | private function envTwig(Env $env): array |
||
75 | } |
||
76 |