11
11
12
12
use Nette ;
13
13
use Nette \DI ;
14
+ use Nette \DI \Definitions ;
14
15
use Nette \DI \Definitions \Reference ;
15
16
use Nette \DI \Definitions \Statement ;
16
17
use Nette \Neon ;
@@ -42,7 +43,6 @@ public function load(string $file): array
42
43
$ node = $ decoder ->parseToNode ($ input );
43
44
$ traverser = new Neon \Traverser ;
44
45
$ node = $ traverser ->traverse ($ node , $ this ->deprecatedQuestionMarkVisitor (...));
45
- $ node = $ traverser ->traverse ($ node , $ this ->firstClassCallableVisitor (...));
46
46
$ node = $ traverser ->traverse ($ node , $ this ->removeUnderscoreVisitor (...));
47
47
$ node = $ traverser ->traverse ($ node , $ this ->convertAtSignVisitor (...));
48
48
$ node = $ traverser ->traverse ($ node , $ this ->deprecatedParametersVisitor (...));
@@ -114,19 +114,6 @@ function (&$val): void {
114
114
}
115
115
116
116
117
- private function firstClassCallableVisitor (Node $ node ): void
118
- {
119
- if ($ node instanceof Node \EntityNode
120
- && count ($ node ->attributes ) === 1
121
- && $ node ->attributes [0 ]->key === null
122
- && $ node ->attributes [0 ]->value instanceof Node \LiteralNode
123
- && $ node ->attributes [0 ]->value ->value === '... '
124
- ) {
125
- $ node ->attributes [0 ]->value ->value = Nette \DI \Resolver::getFirstClassCallable ()[0 ];
126
- }
127
- }
128
-
129
-
130
117
private function preventMergingVisitor (Node $ node ): void
131
118
{
132
119
if ($ node instanceof Node \ArrayItemNode
@@ -181,14 +168,37 @@ private function entityToExpressionVisitor(Node $node): Node
181
168
}
182
169
183
170
184
- private function buildExpression (array $ chain ): Statement
171
+ private function buildExpression (array $ chain ): Definitions \ Expression
185
172
{
186
173
$ node = array_pop ($ chain );
187
174
$ entity = $ node ->toValue ();
188
- return new Statement (
175
+ $ stmt = new Statement (
189
176
$ chain ? [$ this ->buildExpression ($ chain ), ltrim ($ entity ->value , ': ' )] : $ entity ->value ,
190
177
$ entity ->attributes ,
191
178
);
179
+
180
+ if ($ this ->isFirstClassCallable ($ node )) {
181
+ $ entity = $ stmt ->getEntity ();
182
+ if (is_array ($ entity )) {
183
+ if ($ entity [0 ] === '' ) {
184
+ return new Definitions \FunctionCallable ($ entity [1 ]);
185
+ }
186
+ return new Definitions \MethodCallable (...$ entity );
187
+ } else {
188
+ throw new Nette \DI \InvalidConfigurationException ("Cannot create closure for ' $ entity' in config file (used in ' $ this ->file ') " );
189
+ }
190
+ }
191
+
192
+ return $ stmt ;
193
+ }
194
+
195
+
196
+ private function isFirstClassCallable (Node \EntityNode $ node ): bool
197
+ {
198
+ return array_keys ($ node ->attributes ) === [0 ]
199
+ && $ node ->attributes [0 ]->key === null
200
+ && $ node ->attributes [0 ]->value instanceof Node \LiteralNode
201
+ && $ node ->attributes [0 ]->value ->value === '... ' ;
192
202
}
193
203
194
204
@@ -210,7 +220,11 @@ private function removeUnderscoreVisitor(Node $node): void
210
220
unset($ node ->attributes [$ i ]);
211
221
$ index = true ;
212
222
213
- } elseif ($ attr ->value instanceof Node \LiteralNode && $ attr ->value ->value === '... ' ) {
223
+ } elseif (
224
+ $ attr ->value instanceof Node \LiteralNode
225
+ && $ attr ->value ->value === '... '
226
+ && !$ this ->isFirstClassCallable ($ node )
227
+ ) {
214
228
trigger_error ("Replace ... with _ in configuration file ' $ this ->file '. " , E_USER_DEPRECATED );
215
229
unset($ node ->attributes [$ i ]);
216
230
$ index = true ;
0 commit comments