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 = array(); |
||
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 | * Escapes a string for output in an HTML document |
||
43 | * |
||
44 | * @param string $raw |
||
45 | * @return string |
||
46 | */ |
||
47 | 2 | public function escape($raw) |
|
48 | { |
||
49 | 2 | $flags = ENT_QUOTES; |
|
50 | |||
51 | // HHVM has all constants defined, but only ENT_IGNORE |
||
52 | // works at the moment |
||
53 | 2 | if (defined("ENT_SUBSTITUTE") && !defined("HHVM_VERSION")) { |
|
54 | 2 | $flags |= ENT_SUBSTITUTE; |
|
55 | 2 | } else { |
|
56 | // This is for 5.3. |
||
57 | // The documentation warns of a potential security issue, |
||
58 | // but it seems it does not apply in our case, because |
||
59 | // we do not blacklist anything anywhere. |
||
60 | $flags |= ENT_IGNORE; |
||
61 | } |
||
62 | |||
63 | 2 | return htmlspecialchars($raw, $flags, "UTF-8"); |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * Escapes a string for output in an HTML document, but preserves |
||
68 | * URIs within it, and converts them to clickable anchor elements. |
||
69 | * |
||
70 | * @param string $raw |
||
71 | * @return string |
||
72 | */ |
||
73 | 1 | public function escapeButPreserveUris($raw) |
|
81 | |||
82 | private function getDumper() |
||
108 | |||
109 | /** |
||
110 | * Format the given value into a human readable string. |
||
111 | * |
||
112 | * @param mixed $value |
||
113 | * @return string |
||
114 | */ |
||
115 | public function dump($value) |
||
142 | |||
143 | /** |
||
144 | * Format the args of the given Frame as a human readable html string |
||
145 | * |
||
146 | * @param Frame $frame |
||
147 | * @return string the rendered html |
||
148 | */ |
||
149 | public function dumpArgs(Frame $frame) |
||
169 | |||
170 | /** |
||
171 | * Convert a string to a slug version of itself |
||
172 | * |
||
173 | * @param string $original |
||
174 | * @return string |
||
175 | */ |
||
176 | 1 | public function slug($original) |
|
182 | |||
183 | /** |
||
184 | * Given a template path, render it within its own scope. This |
||
185 | * method also accepts an array of additional variables to be |
||
186 | * passed to the template. |
||
187 | * |
||
188 | * @param string $template |
||
189 | * @param array $additionalVariables |
||
190 | */ |
||
191 | 1 | public function render($template, array $additionalVariables = null) |
|
207 | |||
208 | /** |
||
209 | * Sets the variables to be passed to all templates rendered |
||
210 | * by this template helper. |
||
211 | * |
||
212 | * @param array $variables |
||
213 | */ |
||
214 | 1 | public function setVariables(array $variables) |
|
218 | |||
219 | /** |
||
220 | * Sets a single template variable, by its name: |
||
221 | * |
||
222 | * @param string $variableName |
||
223 | * @param mixd $variableValue |
||
224 | */ |
||
225 | 1 | public function setVariable($variableName, $variableValue) |
|
229 | |||
230 | /** |
||
231 | * Gets a single template variable, by its name, or |
||
232 | * $defaultValue if the variable does not exist |
||
233 | * |
||
234 | * @param string $variableName |
||
235 | * @param mixed $defaultValue |
||
236 | * @return mixed |
||
237 | */ |
||
238 | 1 | public function getVariable($variableName, $defaultValue = null) |
|
243 | |||
244 | /** |
||
245 | * Unsets a single template variable, by its name |
||
246 | * |
||
247 | * @param string $variableName |
||
248 | */ |
||
249 | 1 | public function delVariable($variableName) |
|
253 | |||
254 | /** |
||
255 | * Returns all variables for this helper |
||
256 | * |
||
257 | * @return array |
||
258 | */ |
||
259 | 1 | public function getVariables() |
|
263 | |||
264 | /** |
||
265 | * Set the cloner used for dumping variables. |
||
266 | * |
||
267 | * @param AbstractCloner $cloner |
||
268 | */ |
||
269 | public function setCloner($cloner) |
||
273 | |||
274 | /** |
||
275 | * Get the cloner used for dumping variables. |
||
276 | * |
||
277 | * @return AbstractCloner |
||
278 | */ |
||
279 | public function getCloner() |
||
286 | } |
||
287 |