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 | /** |
||
47 | * Escapes a string for output in an HTML document |
||
48 | * |
||
49 | * @param string $raw |
||
50 | * @return string |
||
51 | */ |
||
52 | 2 | public function escape($raw) |
|
72 | |||
73 | /** |
||
74 | * Escapes a string for output in an HTML document, but preserves |
||
75 | * URIs within it, and converts them to clickable anchor elements. |
||
76 | * |
||
77 | * @param string $raw |
||
78 | * @return string |
||
79 | */ |
||
80 | 1 | public function escapeButPreserveUris($raw) |
|
88 | |||
89 | /** |
||
90 | * Makes sure that the given string breaks on the delimiter. |
||
91 | * |
||
92 | * @param string $delimiter |
||
93 | * @param string $s |
||
94 | * @return string |
||
95 | */ |
||
96 | 1 | public function breakOnDelimiter($delimiter, $s) |
|
105 | |||
106 | /** |
||
107 | * Replace the part of the path that all files have in common. |
||
108 | * |
||
109 | * @param string $path |
||
110 | * @return string |
||
111 | */ |
||
112 | 1 | public function shorten($path) |
|
113 | { |
||
114 | 1 | if ($this->applicationRootPath !== null && $this->applicationRootPath != "/") { |
|
115 | 1 | $path = str_replace($this->applicationRootPath, '…', $path); |
|
116 | 1 | } |
|
117 | |||
118 | 1 | return $path; |
|
119 | } |
||
120 | |||
121 | private function getDumper() |
||
147 | |||
148 | /** |
||
149 | * Format the given value into a human readable string. |
||
150 | * |
||
151 | * @param mixed $value |
||
152 | * @return string |
||
153 | */ |
||
154 | public function dump($value) |
||
181 | |||
182 | /** |
||
183 | * Format the args of the given Frame as a human readable html string |
||
184 | * |
||
185 | * @param Frame $frame |
||
186 | * @return string the rendered html |
||
187 | */ |
||
188 | public function dumpArgs(Frame $frame) |
||
208 | |||
209 | /** |
||
210 | * Convert a string to a slug version of itself |
||
211 | * |
||
212 | * @param string $original |
||
213 | * @return string |
||
214 | */ |
||
215 | 1 | public function slug($original) |
|
221 | |||
222 | /** |
||
223 | * Given a template path, render it within its own scope. This |
||
224 | * method also accepts an array of additional variables to be |
||
225 | * passed to the template. |
||
226 | * |
||
227 | * @param string $template |
||
228 | * @param array $additionalVariables |
||
229 | */ |
||
230 | 1 | public function render($template, array $additionalVariables = null) |
|
246 | |||
247 | /** |
||
248 | * Sets the variables to be passed to all templates rendered |
||
249 | * by this template helper. |
||
250 | * |
||
251 | * @param array $variables |
||
252 | */ |
||
253 | 1 | public function setVariables(array $variables) |
|
257 | |||
258 | /** |
||
259 | * Sets a single template variable, by its name: |
||
260 | * |
||
261 | * @param string $variableName |
||
262 | * @param mixd $variableValue |
||
263 | */ |
||
264 | 1 | public function setVariable($variableName, $variableValue) |
|
268 | |||
269 | /** |
||
270 | * Gets a single template variable, by its name, or |
||
271 | * $defaultValue if the variable does not exist |
||
272 | * |
||
273 | * @param string $variableName |
||
274 | * @param mixed $defaultValue |
||
275 | * @return mixed |
||
276 | */ |
||
277 | 1 | public function getVariable($variableName, $defaultValue = null) |
|
282 | |||
283 | /** |
||
284 | * Unsets a single template variable, by its name |
||
285 | * |
||
286 | * @param string $variableName |
||
287 | */ |
||
288 | 1 | public function delVariable($variableName) |
|
292 | |||
293 | /** |
||
294 | * Returns all variables for this helper |
||
295 | * |
||
296 | * @return array |
||
297 | */ |
||
298 | 1 | public function getVariables() |
|
302 | |||
303 | /** |
||
304 | * Set the cloner used for dumping variables. |
||
305 | * |
||
306 | * @param AbstractCloner $cloner |
||
307 | */ |
||
308 | public function setCloner($cloner) |
||
312 | |||
313 | /** |
||
314 | * Get the cloner used for dumping variables. |
||
315 | * |
||
316 | * @return AbstractCloner |
||
317 | */ |
||
318 | public function getCloner() |
||
325 | |||
326 | /** |
||
327 | * Set the application root path. |
||
328 | * |
||
329 | * @param string $applicationRootPath |
||
330 | */ |
||
331 | public function setApplicationRootPath($applicationRootPath) |
||
335 | |||
336 | /** |
||
337 | * Return the application root path. |
||
338 | * |
||
339 | * @return string |
||
340 | */ |
||
341 | public function getApplicationRootPath() |
||
345 | } |
||
346 |