1 | <?php |
||
18 | class TemplateHelper |
||
19 | { |
||
20 | /** |
||
21 | * An array of variables to be passed to all templates |
||
22 | * @var array |
||
23 | */ |
||
24 | private $variables = []; |
||
25 | |||
26 | /** |
||
27 | * @var HtmlDumper |
||
28 | */ |
||
29 | private $htmlDumper; |
||
30 | |||
31 | /** |
||
32 | * @var HtmlDumperOutput |
||
33 | */ |
||
34 | private $htmlDumperOutput; |
||
35 | |||
36 | /** |
||
37 | * @var AbstractCloner |
||
38 | */ |
||
39 | private $cloner; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | private $applicationRootPath; |
||
45 | |||
46 | 2 | public function __construct() |
|
51 | |||
52 | /** |
||
53 | * Escapes a string for output in an HTML document |
||
54 | * |
||
55 | * @param string $raw |
||
56 | * @return string |
||
57 | */ |
||
58 | 2 | public function escape($raw) |
|
78 | |||
79 | /** |
||
80 | * Escapes a string for output in an HTML document, but preserves |
||
81 | * URIs within it, and converts them to clickable anchor elements. |
||
82 | * |
||
83 | * @param string $raw |
||
84 | * @return string |
||
85 | */ |
||
86 | 1 | public function escapeButPreserveUris($raw) |
|
95 | |||
96 | /** |
||
97 | * Makes sure that the given string breaks on the delimiter. |
||
98 | * |
||
99 | * @param string $delimiter |
||
100 | * @param string $s |
||
101 | * @return string |
||
102 | */ |
||
103 | 1 | public function breakOnDelimiter($delimiter, $s) |
|
112 | |||
113 | /** |
||
114 | * Replace the part of the path that all files have in common. |
||
115 | * |
||
116 | * @param string $path |
||
117 | * @return string |
||
118 | */ |
||
119 | 1 | public function shorten($path) |
|
127 | |||
128 | private function getDumper() |
||
154 | |||
155 | /** |
||
156 | * Format the given value into a human readable string. |
||
157 | * |
||
158 | * @param mixed $value |
||
159 | * @return string |
||
160 | */ |
||
161 | public function dump($value) |
||
188 | |||
189 | /** |
||
190 | * Format the args of the given Frame as a human readable html string |
||
191 | * |
||
192 | * @param Frame $frame |
||
193 | * @return string the rendered html |
||
194 | */ |
||
195 | public function dumpArgs(Frame $frame) |
||
215 | |||
216 | /** |
||
217 | * Convert a string to a slug version of itself |
||
218 | * |
||
219 | * @param string $original |
||
220 | * @return string |
||
221 | */ |
||
222 | 1 | public function slug($original) |
|
228 | |||
229 | /** |
||
230 | * Given a template path, render it within its own scope. This |
||
231 | * method also accepts an array of additional variables to be |
||
232 | * passed to the template. |
||
233 | * |
||
234 | * @param string $template |
||
235 | * @param array $additionalVariables |
||
236 | */ |
||
237 | 1 | public function render($template, array $additionalVariables = null) |
|
253 | |||
254 | /** |
||
255 | * Sets the variables to be passed to all templates rendered |
||
256 | * by this template helper. |
||
257 | * |
||
258 | * @param array $variables |
||
259 | */ |
||
260 | 1 | public function setVariables(array $variables) |
|
264 | |||
265 | /** |
||
266 | * Sets a single template variable, by its name: |
||
267 | * |
||
268 | * @param string $variableName |
||
269 | * @param mixed $variableValue |
||
270 | */ |
||
271 | 1 | public function setVariable($variableName, $variableValue) |
|
275 | |||
276 | /** |
||
277 | * Gets a single template variable, by its name, or |
||
278 | * $defaultValue if the variable does not exist |
||
279 | * |
||
280 | * @param string $variableName |
||
281 | * @param mixed $defaultValue |
||
282 | * @return mixed |
||
283 | */ |
||
284 | 1 | public function getVariable($variableName, $defaultValue = null) |
|
289 | |||
290 | /** |
||
291 | * Unsets a single template variable, by its name |
||
292 | * |
||
293 | * @param string $variableName |
||
294 | */ |
||
295 | 1 | public function delVariable($variableName) |
|
299 | |||
300 | /** |
||
301 | * Returns all variables for this helper |
||
302 | * |
||
303 | * @return array |
||
304 | */ |
||
305 | 1 | public function getVariables() |
|
309 | |||
310 | /** |
||
311 | * Set the cloner used for dumping variables. |
||
312 | * |
||
313 | * @param AbstractCloner $cloner |
||
314 | */ |
||
315 | 1 | public function setCloner($cloner) |
|
319 | |||
320 | /** |
||
321 | * Get the cloner used for dumping variables. |
||
322 | * |
||
323 | * @return AbstractCloner |
||
324 | */ |
||
325 | public function getCloner() |
||
332 | |||
333 | /** |
||
334 | * Set the application root path. |
||
335 | * |
||
336 | * @param string $applicationRootPath |
||
337 | */ |
||
338 | public function setApplicationRootPath($applicationRootPath) |
||
342 | |||
343 | /** |
||
344 | * Return the application root path. |
||
345 | * |
||
346 | * @return string |
||
347 | */ |
||
348 | public function getApplicationRootPath() |
||
352 | } |
||
353 |