Completed
Pull Request — master (#446)
by Claus
02:04
created

CommentViewHelper::allowsChildNodeType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace TYPO3Fluid\Fluid\ViewHelpers;
3
4
/*
5
 * This file belongs to the package "TYPO3 Fluid".
6
 * See LICENSE.txt that was shipped with this package.
7
 */
8
9
use TYPO3Fluid\Fluid\Core\Parser\NodeFilterInterface;
10
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\NodeInterface;
11
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
12
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\ParserRuntimeOnly;
13
14
/**
15
 * This ViewHelper prevents rendering of any content inside the tag
16
 * Note: Contents of the comment will still be **parsed** thus throwing an
17
 * Exception if it contains syntax errors. You can put child nodes in
18
 * CDATA tags to avoid this.
19
 *
20
 * = Examples =
21
 *
22
 * <code title="Commenting out fluid code">
23
 * Before
24
 * <f:comment>
25
 *   This is completely hidden.
26
 *   <f:debug>This does not get rendered</f:debug>
27
 * </f:comment>
28
 * After
29
 * </code>
30
 * <output>
31
 * Before
32
 * After
33
 * </output>
34
 *
35
 * <code title="Prevent parsing">
36
 * <f:comment><![CDATA[
37
 *  <f:some.invalid.syntax />
38
 * ]]></f:comment>
39
 * </code>
40
 * <output>
41
 * </output>
42
 *
43
 * Note: Using this view helper won't have a notable effect on performance, especially once the template is parsed.
44
 * However it can lead to reduced readability. You can use layouts and partials to split a large template into smaller
45
 * parts. Using self-descriptive names for the partials can make comments redundant.
46
 *
47
 * @api
48
 */
49
class CommentViewHelper extends AbstractViewHelper implements NodeFilterInterface
50
{
51
    use ParserRuntimeOnly;
52
53
    /**
54
     * @var boolean
55
     */
56
    protected $escapeChildren = false;
57
58
    /**
59
     * @var boolean
60
     */
61
    protected $escapeOutput = false;
62
63
    /**
64
     * The commenting ViewHelper disallows every node type as child, preventing them from
65
     * being compiled into the PHP version of the template.
66
     *
67
     * @param NodeInterface $node
68
     * @return bool
69
     */
70
    public function allowsChildNodeType(NodeInterface $node): bool
71
    {
72
        return false;
73
    }
74
}
75