Completed
Push — master ( 920e94...27b195 )
by Mathias
01:43
created

ViewHelperNode::validateArguments()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 2
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
namespace TYPO3Fluid\Fluid\Core\Parser\SyntaxTree;
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\ParsingState;
10
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
11
use TYPO3Fluid\Fluid\Core\ViewHelper\ArgumentDefinition;
12
use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperInterface;
13
14
/**
15
 * Node which will call a ViewHelper associated with this node.
16
 */
17
class ViewHelperNode extends AbstractNode
18
{
19
20
    /**
21
     * @var string
22
     */
23
    protected $viewHelperClassName;
24
25
    /**
26
     * @var NodeInterface[]
27
     */
28
    protected $arguments = [];
29
30
    /**
31
     * @var ViewHelperInterface
32
     */
33
    protected $uninitializedViewHelper = null;
34
35
    /**
36
     * @var ArgumentDefinition[]
37
     */
38
    protected $argumentDefinitions = [];
39
40
    /**
41
     * @var string
42
     */
43
    protected $pointerTemplateCode = null;
44
45
    /**
46
     * Constructor.
47
     *
48
     * @param RenderingContextInterface $renderingContext a RenderingContext, provided by invoker
49
     * @param string $namespace the namespace identifier of the ViewHelper.
50
     * @param string $identifier the name of the ViewHelper to render, inside the namespace provided.
51
     * @param NodeInterface[] $arguments Arguments of view helper - each value is a RootNode.
52
     * @param ParsingState $state
53
     */
54
    public function __construct(RenderingContextInterface $renderingContext, $namespace, $identifier, array $arguments, ParsingState $state)
0 ignored issues
show
Unused Code introduced by
The parameter $state is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
55
    {
56
        $resolver = $renderingContext->getViewHelperResolver();
57
        $this->arguments = $arguments;
58
        $this->viewHelperClassName = $resolver->resolveViewHelperClassName($namespace, $identifier);
59
        $this->uninitializedViewHelper = $resolver->createViewHelperInstanceFromClassName($this->viewHelperClassName);
60
        $this->uninitializedViewHelper->setViewHelperNode($this);
61
        // Note: RenderingContext required here though replaced later. See https://github.com/TYPO3Fluid/Fluid/pull/93
62
        $this->uninitializedViewHelper->setRenderingContext($renderingContext);
63
        $this->argumentDefinitions = $resolver->getArgumentDefinitionsForViewHelper($this->uninitializedViewHelper);
64
    }
65
66
    /**
67
     * @return ArgumentDefinition[]
68
     */
69
    public function getArgumentDefinitions()
70
    {
71
        return $this->argumentDefinitions;
72
    }
73
74
    /**
75
     * Returns the attached (but still uninitialized) ViewHelper for this ViewHelperNode.
76
     * We need this method because sometimes Interceptors need to ask some information from the ViewHelper.
77
     *
78
     * @return ViewHelperInterface
79
     */
80
    public function getUninitializedViewHelper()
81
    {
82
        return $this->uninitializedViewHelper;
83
    }
84
85
    /**
86
     * Get class name of view helper
87
     *
88
     * @return string Class Name of associated view helper
89
     */
90
    public function getViewHelperClassName()
91
    {
92
        return $this->viewHelperClassName;
93
    }
94
95
    /**
96
     * INTERNAL - only needed for compiling templates
97
     *
98
     * @return NodeInterface[]
99
     */
100
    public function getArguments()
101
    {
102
        return $this->arguments;
103
    }
104
105
    /**
106
     * INTERNAL - only needed for compiling templates
107
     *
108
     * @param string $argumentName
109
     * @return ArgumentDefinition
110
     */
111
    public function getArgumentDefinition($argumentName)
112
    {
113
        return $this->argumentDefinitions[$argumentName];
114
    }
115
116
    /**
117
     * @param NodeInterface $childNode
118
     * @return void
119
     */
120
    public function addChildNode(NodeInterface $childNode)
121
    {
122
        parent::addChildNode($childNode);
123
        $this->uninitializedViewHelper->setChildNodes($this->childNodes);
124
    }
125
126
    /**
127
     * @param string $pointerTemplateCode
128
     * @return void
129
     */
130
    public function setPointerTemplateCode($pointerTemplateCode)
131
    {
132
        $this->pointerTemplateCode = $pointerTemplateCode;
133
    }
134
135
    /**
136
     * Call the view helper associated with this object.
137
     *
138
     * First, it evaluates the arguments of the view helper.
139
     *
140
     * If the view helper implements \TYPO3Fluid\Fluid\Core\ViewHelper\ChildNodeAccessInterface,
141
     * it calls setChildNodes(array childNodes) on the view helper.
142
     *
143
     * Afterwards, checks that the view helper did not leave a variable lying around.
144
     *
145
     * @param RenderingContextInterface $renderingContext
146
     * @return string evaluated node after the view helper has been called.
147
     */
148
    public function evaluate(RenderingContextInterface $renderingContext)
149
    {
150
        return $renderingContext->getViewHelperInvoker()->invoke($this->uninitializedViewHelper, $this->arguments, $renderingContext);
151
    }
152
}
153