[TASK] Use fully qualified name resolution in PHP 5.5
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / Core / Parser / Interceptor / Escape.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Core\Parser\Interceptor;
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 /**
15 * An interceptor adding the escape viewhelper to the suitable places.
16 */
17 class Escape implements \TYPO3\CMS\Fluid\Core\Parser\InterceptorInterface {
18
19 /**
20 * Is the interceptor enabled right now?
21 *
22 * @var bool
23 */
24 protected $interceptorEnabled = TRUE;
25
26 /**
27 * A stack of ViewHelperNodes which currently disable the interceptor.
28 * Needed to enable the interceptor again.
29 *
30 * @var array<\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\NodeInterface>
31 */
32 protected $viewHelperNodesWhichDisableTheInterceptor = array();
33
34 /**
35 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
36 * @inject
37 */
38 protected $objectManager;
39
40 /**
41 * Adds a ViewHelper node using the Format\HtmlspecialcharsViewHelper to the given node.
42 * If "escapingInterceptorEnabled" in the ViewHelper is FALSE, will disable itself inside the ViewHelpers body.
43 *
44 * @param \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\NodeInterface $node
45 * @param int $interceptorPosition One of the INTERCEPT_* constants for the current interception point
46 * @param \TYPO3\CMS\Fluid\Core\Parser\ParsingState $parsingState the current parsing state. Not needed in this interceptor.
47 * @return \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\NodeInterface
48 */
49 public function process(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\NodeInterface $node, $interceptorPosition, \TYPO3\CMS\Fluid\Core\Parser\ParsingState $parsingState) {
50 if ($interceptorPosition === \TYPO3\CMS\Fluid\Core\Parser\InterceptorInterface::INTERCEPT_OPENING_VIEWHELPER) {
51 if (!$node->getUninitializedViewHelper()->isEscapingInterceptorEnabled()) {
52 $this->interceptorEnabled = FALSE;
53 $this->viewHelperNodesWhichDisableTheInterceptor[] = $node;
54 }
55 } elseif ($interceptorPosition === \TYPO3\CMS\Fluid\Core\Parser\InterceptorInterface::INTERCEPT_CLOSING_VIEWHELPER) {
56 if (end($this->viewHelperNodesWhichDisableTheInterceptor) === $node) {
57 array_pop($this->viewHelperNodesWhichDisableTheInterceptor);
58 if (count($this->viewHelperNodesWhichDisableTheInterceptor) === 0) {
59 $this->interceptorEnabled = TRUE;
60 }
61 }
62 } elseif ($this->interceptorEnabled && $node instanceof \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ObjectAccessorNode) {
63 $escapeViewHelper = $this->objectManager->get(\TYPO3\CMS\Fluid\ViewHelpers\Format\HtmlspecialcharsViewHelper::class);
64 $node = $this->objectManager->get(
65 \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode::class,
66 $escapeViewHelper,
67 array('value' => $node)
68 );
69 }
70 return $node;
71 }
72
73 /**
74 * This interceptor wants to hook into object accessor creation, and opening / closing ViewHelpers.
75 *
76 * @return array Array of INTERCEPT_* constants
77 */
78 public function getInterceptionPoints() {
79 return array(
80 \TYPO3\CMS\Fluid\Core\Parser\InterceptorInterface::INTERCEPT_OPENING_VIEWHELPER,
81 \TYPO3\CMS\Fluid\Core\Parser\InterceptorInterface::INTERCEPT_CLOSING_VIEWHELPER,
82 \TYPO3\CMS\Fluid\Core\Parser\InterceptorInterface::INTERCEPT_OBJECTACCESSOR
83 );
84 }
85 }