[BUGFIX] Use late static binding for compilable viewhelpers
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Format / UrlencodeViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
3
4 /* *
5 * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * The TYPO3 project - inspiring people to share! *
12 * */
13
14 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
15 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
16 use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
17
18 /**
19 * Encodes the given string according to http://www.faqs.org/rfcs/rfc3986.html (applying PHPs rawurlencode() function)
20 * @see http://www.php.net/manual/function.rawurlencode.php
21 *
22 * = Examples =
23 *
24 * <code title="default notation">
25 * <f:format.rawurlencode>foo @+%/</f:format.rawurlencode>
26 * </code>
27 * <output>
28 * foo%20%40%2B%25%2F (rawurlencode() applied)
29 * </output>
30 *
31 * <code title="inline notation">
32 * {text -> f:format.urlencode()}
33 * </code>
34 * <output>
35 * Url encoded text (rawurlencode() applied)
36 * </output>
37 *
38 * @api
39 */
40 class UrlencodeViewHelper extends AbstractViewHelper implements CompilableInterface {
41
42 /**
43 * Disable the escaping interceptor because otherwise the child nodes would be escaped before this view helper
44 * can decode the text's entities.
45 *
46 * @var bool
47 */
48 protected $escapingInterceptorEnabled = FALSE;
49
50 /**
51 * Escapes special characters with their escaped counterparts as needed using PHPs rawurlencode() function.
52 *
53 * @param string $value string to format
54 * @return mixed
55 * @see http://www.php.net/manual/function.rawurlencode.php
56 * @api
57 */
58 public function render($value = NULL) {
59 return static::renderStatic(
60 array(
61 'value' => $value
62 ),
63 $this->buildRenderChildrenClosure(),
64 $this->renderingContext
65 );
66 }
67
68 /**
69 * @param array $arguments
70 * @param callable $renderChildrenClosure
71 * @param RenderingContextInterface $renderingContext
72 *
73 * @return string
74 */
75 static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
76 $value = $arguments['value'];
77
78 if ($value === NULL) {
79 $value = $renderChildrenClosure();
80 }
81 if (!is_string($value)) {
82 return $value;
83 }
84 return rawurlencode($value);
85 }
86
87 }