1 | <?php |
||
13 | class Twig implements ViewInterface |
||
14 | { |
||
15 | /** |
||
16 | * Twig environment |
||
17 | * @var \Twig_Environment |
||
18 | */ |
||
19 | protected $twig; |
||
20 | |||
21 | /** |
||
22 | * @var PluginInterface[] |
||
23 | */ |
||
24 | protected $plugins = []; |
||
25 | |||
26 | |||
27 | /** |
||
28 | * Class constructor |
||
29 | * |
||
30 | * @param \Twig_Environment|array $options |
||
31 | */ |
||
32 | 22 | public function __construct($options) |
|
43 | |||
44 | /** |
||
45 | * Create a new Twig environment |
||
46 | * |
||
47 | * @param array $options |
||
48 | * @return \Twig_Environment |
||
49 | */ |
||
50 | 2 | protected function createTwigEnvironment(array $options) |
|
61 | |||
62 | /** |
||
63 | * Add paths to Twig loader |
||
64 | * |
||
65 | * @param \Twig_Loader_Filesystem $loader |
||
66 | * @param string|array $paths |
||
67 | * @return type |
||
68 | */ |
||
69 | 1 | protected function addLoaderPaths(\Twig_Loader_Filesystem $loader, $paths) |
|
79 | |||
80 | /** |
||
81 | * Get Twig environment |
||
82 | * |
||
83 | * @return \Twig_Environment |
||
84 | */ |
||
85 | 15 | public function getTwig() |
|
89 | |||
90 | |||
91 | /** |
||
92 | * Assert valid variable, function and filter name |
||
93 | * |
||
94 | * @param string $name |
||
95 | * @throws \InvalidArgumentException |
||
96 | */ |
||
97 | 10 | protected function assertViewVariableName($name) |
|
108 | |||
109 | /** |
||
110 | * Expose a function to the view. |
||
111 | * |
||
112 | * @param string $name Function name in template |
||
113 | * @param callable|null $function |
||
114 | * @param string $as 'function' or 'filter' |
||
115 | * @return $this |
||
116 | */ |
||
117 | 10 | public function expose($name, $function = null, $as = 'function') |
|
134 | |||
135 | |||
136 | /** |
||
137 | * Add a plugin to the view |
||
138 | * |
||
139 | * @param PluginInterface $plugin |
||
140 | * @return $this |
||
141 | */ |
||
142 | 3 | public function addPlugin(PluginInterface $plugin) |
|
149 | |||
150 | /** |
||
151 | * Get all plugins |
||
152 | * |
||
153 | * @return PluginInterface[] |
||
154 | */ |
||
155 | 3 | public function getPlugins() |
|
159 | |||
160 | /** |
||
161 | * Invoke the onRender method of all plugins |
||
162 | * |
||
163 | * @param string $template Template filename |
||
164 | * @param array $context |
||
165 | */ |
||
166 | 6 | protected function invokePluginsOnRender($template, array $context) |
|
172 | |||
173 | /** |
||
174 | * Add the official Twig extension and Jansy Twig extensions. |
||
175 | * @deprecated |
||
176 | * |
||
177 | * @return $this |
||
178 | */ |
||
179 | 1 | public function addDefaultExtensions() |
|
183 | |||
184 | |||
185 | /** |
||
186 | * Get the filename |
||
187 | * |
||
188 | * @return string |
||
189 | */ |
||
190 | 6 | protected function getFilename($name) |
|
198 | |||
199 | /** |
||
200 | * Render and output template |
||
201 | * |
||
202 | * @param ResponseInterface $response |
||
203 | * @param string $name Template name |
||
204 | * @param array $context Template context as associated array |
||
205 | * @return ResponseInterface |
||
206 | */ |
||
207 | 6 | public function render(ResponseInterface $response, $name, array $context = []) |
|
223 | } |
||
224 | |||
225 |