1 | <?php |
||
23 | class Twig implements TemplateEngineInterface |
||
24 | { |
||
25 | |||
26 | /** |
||
27 | * @var array |
||
28 | */ |
||
29 | private $optionsMap = [ |
||
30 | 'debug' => 'debug', |
||
31 | 'autoEscape' => 'autoescape', |
||
32 | 'strictVariables' => 'strict_variables', |
||
33 | 'autoReload' => 'auto_reload', |
||
34 | 'cache' => 'cache', |
||
35 | 'baseTemplateClass' => 'base_template_class', |
||
36 | 'charset' => 'charset', |
||
37 | 'optimizations' => 'optimizations' |
||
38 | ]; |
||
39 | |||
40 | /** |
||
41 | * @var array |
||
42 | */ |
||
43 | private $defaultOptions = [ |
||
44 | 'debug' => false, |
||
45 | 'autoEscape' => true, |
||
46 | 'strictVariables' => false, |
||
47 | 'autoReload' => false, |
||
48 | 'cache' => false, |
||
49 | 'baseTemplateClass' => 'Twig_Template', |
||
50 | 'charset' => 'utf8', |
||
51 | 'optimizations' => -1 |
||
52 | ]; |
||
53 | |||
54 | /** |
||
55 | * @var array |
||
56 | */ |
||
57 | private $options = []; |
||
58 | |||
59 | /** |
||
60 | * @var Twig_Environment |
||
61 | */ |
||
62 | private $twigEnvironment; |
||
63 | |||
64 | /** |
||
65 | * @var array |
||
66 | */ |
||
67 | private $locations = []; |
||
68 | |||
69 | /** |
||
70 | * @var Twig_Loader_Filesystem |
||
71 | */ |
||
72 | private $loader; |
||
73 | |||
74 | /** |
||
75 | * @var Twig_TemplateWrapper |
||
76 | */ |
||
77 | private $template; |
||
78 | |||
79 | /** |
||
80 | * Creates a Twig template engine |
||
81 | * |
||
82 | * @param array $options |
||
83 | * @param Twig_Environment $twigEnvironment |
||
84 | */ |
||
85 | public function __construct(array $options = [], Twig_Environment $twigEnvironment = null) |
||
90 | |||
91 | /** |
||
92 | * Engine configuration options |
||
93 | * |
||
94 | * @return array |
||
95 | */ |
||
96 | public function options() |
||
100 | |||
101 | /** |
||
102 | * Parses the source template code. |
||
103 | * |
||
104 | * @param string $source The template to parse |
||
105 | * |
||
106 | * @return TemplateEngineInterface|self|$this |
||
107 | * |
||
108 | * @throws \Twig_Error_Loader When the template cannot be found |
||
109 | * @throws \Twig_Error_Runtime When a previously generated cache is corrupted |
||
110 | * @throws \Twig_Error_Syntax When an error occurred during compilation |
||
111 | */ |
||
112 | public function parse($source) |
||
117 | |||
118 | /** |
||
119 | * Processes the template with data to produce the final output. |
||
120 | * |
||
121 | * @param mixed $data The data that will be used to process the view. |
||
122 | * |
||
123 | * @return string Returns processed output string. |
||
124 | */ |
||
125 | public function process($data = array()) |
||
129 | |||
130 | /** |
||
131 | * Sets the list of available locations for template files. |
||
132 | * |
||
133 | * @param array $locations |
||
134 | * |
||
135 | * @return TemplateEngineInterface|self|$this |
||
136 | */ |
||
137 | public function setLocations(array $locations) |
||
142 | |||
143 | /** |
||
144 | 4 | * Returns the source template engine |
|
145 | 4 | * |
|
146 | 3 | * @return object |
|
147 | 2 | */ |
|
148 | 2 | public function getSourceEngine() |
|
152 | |||
153 | 2 | /** |
|
154 | * Creates a twig environment if not injected |
||
155 | * |
||
156 | * @return Twig_Environment |
||
157 | */ |
||
158 | private function getTwigEnvironment() |
||
165 | |||
166 | 4 | /** |
|
167 | 2 | * Creates the twig environment |
|
168 | 2 | * |
|
169 | 2 | * @return Twig_Environment |
|
170 | 2 | */ |
|
171 | private function createTwigEnvironment() |
||
184 | |||
185 | 14 | /** |
|
186 | 14 | * Creates a file system loader |
|
187 | * |
||
188 | * @return Twig_Loader_Filesystem |
||
189 | */ |
||
190 | private function getLoader() |
||
199 | |||
200 | /** |
||
201 | * Returns current configured options |
||
202 | * |
||
203 | * @return array |
||
204 | */ |
||
205 | 6 | private function getOptions() |
|
213 | } |
||
214 |