Completed
Pull Request — master (#470)
by Claus
01:34
created

PassthroughViewHelper::evaluate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
namespace TYPO3Fluid\Fluid\ViewHelpers;
4
5
/*
6
 * This file belongs to the package "TYPO3 Fluid".
7
 * See LICENSE.txt that was shipped with this package.
8
 */
9
10
use TYPO3Fluid\Fluid\Component\SequencingComponentInterface;
11
use TYPO3Fluid\Fluid\Core\Parser\Sequencer;
12
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
13
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
14
use TYPO3Fluid\Fluid\ViewHelpers\Format\HtmlspecialcharsViewHelper;
15
16
/**
17
 * Parsing pass-through ViewHelper
18
 * 
19
 * When used in tag mode, does not parse the tag contents
20
 * as Fluid code - instead, outputs it as raw text.
21
 */
22
class PassthroughViewHelper extends AbstractViewHelper implements SequencingComponentInterface
23
{
24
    protected function initializeArguments()
25
    {
26
        parent::initializeArguments();
27
        $this->registerArgument('escape', 'bool', 'Set to false to not escape contents', false, true);
28
    }
29
30
    public function evaluate(RenderingContextInterface $renderingContext)
31
    {
32
        if ($this->getArguments()['escape'] ?? true) {
33
            return (new HtmlspecialcharsViewHelper())->setChildren($this->getChildren())->evaluate($renderingContext);
34
        }
35
        return $this->evaluateChildren($renderingContext);
36
    }
37
38
    public function sequence(Sequencer $sequencer, ?string $namespace, string $method): void
39
    {
40
        $sequencer->sequenceUntilClosingTagAndIgnoreNested($this, $namespace, $method);
41
    }
42
}
43