1111
1212use Nette ;
1313use Nette \DI ;
14+ use Nette \DI \Definitions ;
1415use Nette \DI \Definitions \Reference ;
1516use Nette \DI \Definitions \Statement ;
1617use Nette \Neon ;
@@ -42,7 +43,6 @@ public function load(string $file): array
4243 $ node = $ decoder ->parseToNode ($ input );
4344 $ traverser = new Neon \Traverser ;
4445 $ node = $ traverser ->traverse ($ node , $ this ->deprecatedQuestionMarkVisitor (...));
45- $ node = $ traverser ->traverse ($ node , $ this ->firstClassCallableVisitor (...));
4646 $ node = $ traverser ->traverse ($ node , $ this ->removeUnderscoreVisitor (...));
4747 $ node = $ traverser ->traverse ($ node , $ this ->convertAtSignVisitor (...));
4848 $ node = $ traverser ->traverse ($ node , $ this ->deprecatedParametersVisitor (...));
@@ -114,19 +114,6 @@ function (&$val): void {
114114 }
115115
116116
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-
130117 private function preventMergingVisitor (Node $ node ): void
131118 {
132119 if ($ node instanceof Node \ArrayItemNode
@@ -181,14 +168,37 @@ private function entityToExpressionVisitor(Node $node): Node
181168 }
182169
183170
184- private function buildExpression (array $ chain ): Statement
171+ private function buildExpression (array $ chain ): Definitions \ Expression
185172 {
186173 $ node = array_pop ($ chain );
187174 $ entity = $ node ->toValue ();
188- return new Statement (
175+ $ stmt = new Statement (
189176 $ chain ? [$ this ->buildExpression ($ chain ), ltrim ($ entity ->value , ': ' )] : $ entity ->value ,
190177 $ entity ->attributes ,
191178 );
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 === '... ' ;
192202 }
193203
194204
@@ -210,7 +220,11 @@ private function removeUnderscoreVisitor(Node $node): void
210220 unset($ node ->attributes [$ i ]);
211221 $ index = true ;
212222
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+ ) {
214228 trigger_error ("Replace ... with _ in configuration file ' $ this ->file '. " , E_USER_DEPRECATED );
215229 unset($ node ->attributes [$ i ]);
216230 $ index = true ;
0 commit comments