[BUGFIX] Use late static binding for compilable viewhelpers
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Format / CdataViewHelper.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 * Outputs an argument/value without any escaping and wraps it with CDATA tags.
20 *
21 * PAY SPECIAL ATTENTION TO SECURITY HERE (especially Cross Site Scripting),
22 * as the output is NOT SANITIZED!
23 *
24 * = Examples =
25 *
26 * <code title="Child nodes">
27 * <f:format.cdata>{string}</f:format.cdata>
28 * </code>
29 * <output>
30 * <![CDATA[(Content of {string} without any conversion/escaping)]]>
31 * </output>
32 *
33 * <code title="Value attribute">
34 * <f:format.cdata value="{string}" />
35 * </code>
36 * <output>
37 * <![CDATA[(Content of {string} without any conversion/escaping)]]>
38 * </output>
39 *
40 * <code title="Inline notation">
41 * {string -> f:format.cdata()}
42 * </code>
43 * <output>
44 * <![CDATA[(Content of {string} without any conversion/escaping)]]>
45 * </output>
46 *
47 * @api
48 */
49 class CdataViewHelper extends AbstractViewHelper implements CompilableInterface {
50
51 /**
52 * Disable the escaping interceptor because otherwise the child nodes would be escaped before this view helper
53 * can decode the text's entities.
54 *
55 * @var bool
56 */
57 protected $escapingInterceptorEnabled = FALSE;
58
59 /**
60 * @param mixed $value The value to output
61 * @return string
62 */
63 public function render($value = NULL) {
64 return static::renderStatic(
65 array('value' => $value),
66 $this->buildRenderChildrenClosure(),
67 $this->renderingContext
68 );
69 }
70
71 /**
72 * @param array $arguments
73 * @param callable $renderChildrenClosure
74 * @param RenderingContextInterface $renderingContext
75 *
76 * @return string
77 */
78 static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
79 $value = $arguments['value'];
80 if ($value === NULL) {
81 $value = $renderChildrenClosure();
82 }
83 return sprintf('<![CDATA[%s]]>', $value);
84 }
85
86 }