1 | <?php |
||
16 | class HandlebarsEnvironment |
||
17 | { |
||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $options; |
||
22 | |||
23 | /** |
||
24 | * @var Filesystem |
||
25 | */ |
||
26 | protected $cache; |
||
27 | |||
28 | /** |
||
29 | * @var FilesystemLoader |
||
30 | */ |
||
31 | protected $loader; |
||
32 | |||
33 | /** |
||
34 | * @var bool |
||
35 | */ |
||
36 | protected $autoReload; |
||
37 | |||
38 | /** |
||
39 | * @var bool |
||
40 | */ |
||
41 | protected $debug; |
||
42 | |||
43 | /** |
||
44 | * @var HandlebarsProfileExtension |
||
45 | */ |
||
46 | private $profiler; |
||
47 | |||
48 | /** |
||
49 | * @var HandlebarsHelperServiceInterface |
||
50 | */ |
||
51 | private $helper; |
||
52 | |||
53 | /** |
||
54 | * @var \ArrayObject |
||
55 | */ |
||
56 | private $partials; |
||
57 | |||
58 | 13 | public function __construct( |
|
59 | FilesystemLoader $loader, |
||
60 | HandlebarsHelperServiceInterface $helper, |
||
61 | $options = [], |
||
62 | Filesystem $cache, |
||
63 | HandlebarsProfileExtension $profiler |
||
64 | ) |
||
65 | { |
||
66 | 13 | $this->loader = $loader; |
|
67 | 13 | $this->partials = $partials = new \ArrayObject(); |
|
68 | 13 | $this->helper = $helper; |
|
69 | |||
70 | 13 | $this->options = array_merge([ |
|
71 | 13 | 'auto_reload' => null, |
|
72 | 'debug' => true, |
||
73 | 13 | 'helpers' => $this->helper->getHelperMethods(), |
|
74 | 13 | 'partialresolver' => function($cx, $name) use ($loader, &$partials) { |
|
75 | 4 | $extension = $this->getTemplateExtension($loader, $name); |
|
76 | 3 | if ($extension === false) { |
|
77 | return null; |
||
78 | } |
||
79 | 3 | $partials[] = new FileResource($loader->getCacheKey($name.$extension)); |
|
80 | 3 | return $loader->getSource($name.$extension); |
|
81 | 13 | }, |
|
82 | 13 | ], $options); |
|
83 | 13 | $this->debug = (bool) $this->options['debug']; |
|
84 | 13 | $this->autoReload = null === $this->options['auto_reload'] ? $this->debug : (bool) $this->options['auto_reload']; |
|
85 | 13 | $this->cache = $cache; |
|
86 | 13 | $this->profiler = $profiler; |
|
87 | 13 | } |
|
88 | |||
89 | 4 | private function getTemplateExtension(FilesystemLoader $loader, $name) { |
|
98 | |||
99 | 8 | public function compile($name) |
|
115 | |||
116 | 3 | public function render($name, array $context = []) |
|
127 | |||
128 | 13 | public function getCacheFilename($name) |
|
134 | |||
135 | 8 | public function getLoader() |
|
139 | |||
140 | /** |
||
141 | * @param $templateName |
||
142 | * @return callable |
||
143 | */ |
||
144 | 8 | public function loadTemplate($templateName) |
|
155 | |||
156 | /** |
||
157 | * Checks if the auto_reload option is enabled. |
||
158 | * |
||
159 | * @return bool true if auto_reload is enabled, false otherwise |
||
160 | */ |
||
161 | 1 | public function isAutoReload() |
|
165 | } |
||
166 |