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) |
|
94 | |||
95 | /** |
||
96 | * Makes sure that the given string breaks on the delimiter. |
||
97 | * |
||
98 | * @param string $delimiter |
||
99 | * @param string $s |
||
100 | * @return string |
||
101 | */ |
||
102 | 1 | public function breakOnDelimiter($delimiter, $s) |
|
111 | |||
112 | /** |
||
113 | * Replace the part of the path that all files have in common. |
||
114 | * |
||
115 | * @param string $path |
||
116 | * @return string |
||
117 | */ |
||
118 | 1 | public function shorten($path) |
|
126 | |||
127 | private function getDumper() |
||
153 | |||
154 | /** |
||
155 | * Format the given value into a human readable string. |
||
156 | * |
||
157 | * @param mixed $value |
||
158 | * @return string |
||
159 | */ |
||
160 | public function dump($value) |
||
187 | |||
188 | /** |
||
189 | * Format the args of the given Frame as a human readable html string |
||
190 | * |
||
191 | * @param Frame $frame |
||
192 | * @return string the rendered html |
||
193 | */ |
||
194 | public function dumpArgs(Frame $frame) |
||
214 | |||
215 | /** |
||
216 | * Convert a string to a slug version of itself |
||
217 | * |
||
218 | * @param string $original |
||
219 | * @return string |
||
220 | */ |
||
221 | 1 | public function slug($original) |
|
227 | |||
228 | /** |
||
229 | * Given a template path, render it within its own scope. This |
||
230 | * method also accepts an array of additional variables to be |
||
231 | * passed to the template. |
||
232 | * |
||
233 | * @param string $template |
||
234 | * @param array $additionalVariables |
||
235 | */ |
||
236 | 1 | public function render($template, array $additionalVariables = null) |
|
252 | |||
253 | /** |
||
254 | * Sets the variables to be passed to all templates rendered |
||
255 | * by this template helper. |
||
256 | * |
||
257 | * @param array $variables |
||
258 | */ |
||
259 | 1 | public function setVariables(array $variables) |
|
263 | |||
264 | /** |
||
265 | * Sets a single template variable, by its name: |
||
266 | * |
||
267 | * @param string $variableName |
||
268 | * @param mixd $variableValue |
||
269 | */ |
||
270 | 1 | public function setVariable($variableName, $variableValue) |
|
274 | |||
275 | /** |
||
276 | * Gets a single template variable, by its name, or |
||
277 | * $defaultValue if the variable does not exist |
||
278 | * |
||
279 | * @param string $variableName |
||
280 | * @param mixed $defaultValue |
||
281 | * @return mixed |
||
282 | */ |
||
283 | 1 | public function getVariable($variableName, $defaultValue = null) |
|
288 | |||
289 | /** |
||
290 | * Unsets a single template variable, by its name |
||
291 | * |
||
292 | * @param string $variableName |
||
293 | */ |
||
294 | 1 | public function delVariable($variableName) |
|
298 | |||
299 | /** |
||
300 | * Returns all variables for this helper |
||
301 | * |
||
302 | * @return array |
||
303 | */ |
||
304 | 1 | public function getVariables() |
|
308 | |||
309 | /** |
||
310 | * Set the cloner used for dumping variables. |
||
311 | * |
||
312 | * @param AbstractCloner $cloner |
||
313 | */ |
||
314 | 1 | public function setCloner($cloner) |
|
318 | |||
319 | /** |
||
320 | * Get the cloner used for dumping variables. |
||
321 | * |
||
322 | * @return AbstractCloner |
||
323 | */ |
||
324 | public function getCloner() |
||
331 | |||
332 | /** |
||
333 | * Set the application root path. |
||
334 | * |
||
335 | * @param string $applicationRootPath |
||
336 | */ |
||
337 | public function setApplicationRootPath($applicationRootPath) |
||
341 | |||
342 | /** |
||
343 | * Return the application root path. |
||
344 | * |
||
345 | * @return string |
||
346 | */ |
||
347 | public function getApplicationRootPath() |
||
351 | } |
||
352 |