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

PassthroughViewHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A initializeArguments() 0 5 1
A evaluate() 0 7 2
A sequence() 0 4 1
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