1
|
|
|
<?php |
2
|
|
|
namespace TYPO3Fluid\Fluid\Core\ViewHelper\Traits; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Class DeprecatedViewHelper |
6
|
|
|
* |
7
|
|
|
* Contains methods which are deprecated and scheduled for removal. |
8
|
|
|
*/ |
9
|
|
|
trait DeprecatedViewHelper |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* ViewHelper Variable Container |
13
|
|
|
* @var ViewHelperVariableContainer |
14
|
|
|
* @deprecated Will be removed in Fluid 3.0; use $renderingContext->getViewHelperVariableContainer() instead. |
15
|
|
|
* @api |
16
|
|
|
*/ |
17
|
|
|
protected $viewHelperVariableContainer; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Current variable container reference. |
21
|
|
|
* @var VariableProviderInterface |
22
|
|
|
* @deprecated Will be removed in Fluid 3.0; use $renderingContext->getVariableProvider() instead. |
23
|
|
|
* @api |
24
|
|
|
*/ |
25
|
|
|
protected $templateVariableContainer; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var NodeInterface[] array |
29
|
|
|
* @api |
30
|
|
|
* @deprecated Will be removed in Fluid 3.0; use $this->viewHelperNode->getChildNodes() instead. |
31
|
|
|
*/ |
32
|
|
|
protected $childNodes = []; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Overridden method which sets deprecated properties. |
36
|
|
|
* |
37
|
|
|
* @param RenderingContextInterface $renderingContext |
38
|
|
|
* @return void |
39
|
|
|
*/ |
40
|
|
|
public function setRenderingContext(RenderingContextInterface $renderingContext) |
41
|
|
|
{ |
42
|
|
|
parent::setRenderingContext($renderingContext); |
43
|
|
|
$this->templateVariableContainer = $renderingContext->getVariableProvider(); |
|
|
|
|
44
|
|
|
$this->viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer(); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* DEPRECATED - is no longer called. |
49
|
|
|
* |
50
|
|
|
* This is PURELY INTERNAL! Never override this method!! |
51
|
|
|
* |
52
|
|
|
* @deprecated |
53
|
|
|
* @param NodeInterface[] $childNodes |
54
|
|
|
* @return void |
55
|
|
|
*/ |
56
|
|
|
public function setChildNodes(array $childNodes) |
57
|
|
|
{ |
58
|
|
|
$this->childNodes = $childNodes; |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* DEPRECATED - is no longer called. |
63
|
|
|
* |
64
|
|
|
* Resets the ViewHelper state. |
65
|
|
|
* |
66
|
|
|
* Overwrite this method if you need to get a clean state of your ViewHelper. |
67
|
|
|
* |
68
|
|
|
* @deprecated |
69
|
|
|
* @return void |
70
|
|
|
*/ |
71
|
|
|
public function resetState() |
72
|
|
|
{ |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* DEPRECATED - is no longer called. |
77
|
|
|
* |
78
|
|
|
* Initializes the ViewHelper. Deprecated since frameworks by the norm provide object lifecycle methods. |
79
|
|
|
* |
80
|
|
|
* @deprecated |
81
|
|
|
* @return void |
82
|
|
|
*/ |
83
|
|
|
public function initialize() |
84
|
|
|
{ |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* DEPRECATED - is no longer called; handled by ViewHelperArgumentValidator |
89
|
|
|
* |
90
|
|
|
* Validate arguments, and throw exception if arguments do not validate. |
91
|
|
|
* |
92
|
|
|
* @deprecated |
93
|
|
|
* @return void |
94
|
|
|
* @throws \InvalidArgumentException |
95
|
|
|
*/ |
96
|
|
|
public function validateArguments() |
97
|
|
|
{ |
98
|
|
|
$argumentDefinitions = $this->prepareArguments(); |
|
|
|
|
99
|
|
|
foreach ($argumentDefinitions as $argumentName => $registeredArgument) { |
100
|
|
|
if ($this->hasArgument($argumentName)) { |
|
|
|
|
101
|
|
|
$value = $this->arguments[$argumentName]; |
|
|
|
|
102
|
|
|
$type = $registeredArgument->getType(); |
103
|
|
|
if ($value !== $registeredArgument->getDefaultValue() && $type !== 'mixed') { |
104
|
|
|
$givenType = is_object($value) ? get_class($value) : gettype($value); |
105
|
|
|
if (!$this->isValidType($type, $value)) { |
106
|
|
|
throw new \InvalidArgumentException( |
107
|
|
|
'The argument "' . $argumentName . '" was registered with type "' . $type . '", but is of type "' . |
108
|
|
|
$givenType . '" in view helper "' . get_class($this) . '".', |
109
|
|
|
1256475113 |
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Check whether the defined type matches the value type |
119
|
|
|
* |
120
|
|
|
* @param string $type |
121
|
|
|
* @param mixed $value |
122
|
|
|
* @return boolean |
123
|
|
|
*/ |
124
|
|
|
protected function isValidType($type, $value) |
125
|
|
|
{ |
126
|
|
|
if ($type === 'object') { |
127
|
|
|
if (!is_object($value)) { |
128
|
|
|
return false; |
129
|
|
|
} |
130
|
|
|
} elseif ($type === 'array' || substr($type, -2) === '[]') { |
131
|
|
|
if (!is_array($value) && !$value instanceof \ArrayAccess && !$value instanceof \Traversable && !empty($value)) { |
132
|
|
|
return false; |
133
|
|
|
} elseif (substr($type, -2) === '[]') { |
134
|
|
|
$firstElement = $this->getFirstElementOfNonEmpty($value); |
135
|
|
|
if ($firstElement === null) { |
136
|
|
|
return true; |
137
|
|
|
} |
138
|
|
|
return $this->isValidType(substr($type, 0, -2), $firstElement); |
139
|
|
|
} |
140
|
|
|
} elseif ($type === 'string') { |
141
|
|
|
if (is_object($value) && !method_exists($value, '__toString')) { |
142
|
|
|
return false; |
143
|
|
|
} |
144
|
|
|
} elseif ($type === 'boolean' && !is_bool($value)) { |
145
|
|
|
return false; |
146
|
|
|
} elseif (class_exists($type) && $value !== null && !$value instanceof $type) { |
147
|
|
|
return false; |
148
|
|
|
} elseif (is_object($value) && !is_a($value, $type, true)) { |
149
|
|
|
return false; |
150
|
|
|
} |
151
|
|
|
return true; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Return the first element of the given array, ArrayAccess or Traversable |
156
|
|
|
* that is not empty |
157
|
|
|
* |
158
|
|
|
* @param mixed $value |
159
|
|
|
* @return mixed |
160
|
|
|
*/ |
161
|
|
|
protected function getFirstElementOfNonEmpty($value) |
162
|
|
|
{ |
163
|
|
|
if (is_array($value)) { |
164
|
|
|
return reset($value); |
165
|
|
|
} elseif ($value instanceof \Traversable) { |
166
|
|
|
foreach ($value as $element) { |
167
|
|
|
return $element; |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
return null; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
} |
174
|
|
|
|
This property has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.