1111
1212use Nette ;
1313use Nette \DI ;
14+ use Nette \DI \Definitions ;
1415use Nette \DI \Definitions \Reference ;
1516use Nette \DI \Definitions \Statement ;
1617use Nette \Neon ;
@@ -43,7 +44,6 @@ public function load(string $file): array
4344 $ node = $ decoder ->parseToNode ($ input );
4445 $ traverser = new Neon \Traverser ;
4546 $ node = $ traverser ->traverse ($ node , $ this ->deprecatedQuestionMarkVisitor (...));
46- $ node = $ traverser ->traverse ($ node , $ this ->firstClassCallableVisitor (...));
4747 $ node = $ traverser ->traverse ($ node , $ this ->removeUnderscoreVisitor (...));
4848 $ node = $ traverser ->traverse ($ node , $ this ->convertAtSignVisitor (...));
4949 $ node = $ traverser ->traverse ($ node , $ this ->deprecatedParametersVisitor (...));
@@ -115,19 +115,6 @@ function (&$val): void {
115115 }
116116
117117
118- private function firstClassCallableVisitor (Node $ node ): void
119- {
120- if ($ node instanceof Node \EntityNode
121- && count ($ node ->attributes ) === 1
122- && $ node ->attributes [0 ]->key === null
123- && $ node ->attributes [0 ]->value instanceof Node \LiteralNode
124- && $ node ->attributes [0 ]->value ->value === '... '
125- ) {
126- $ node ->attributes [0 ]->value ->value = Nette \DI \Resolver::getFirstClassCallable ()[0 ];
127- }
128- }
129-
130-
131118 private function preventMergingVisitor (Node $ node ): void
132119 {
133120 if ($ node instanceof Node \ArrayItemNode
@@ -182,14 +169,37 @@ private function entityToExpressionVisitor(Node $node): Node
182169 }
183170
184171
185- private function buildExpression (array $ chain ): Statement
172+ private function buildExpression (array $ chain ): Definitions \ Expression
186173 {
187174 $ node = array_pop ($ chain );
188175 $ entity = $ node ->toValue ();
189- return new Statement (
176+ $ stmt = new Statement (
190177 $ chain ? [$ this ->buildExpression ($ chain ), ltrim ($ entity ->value , ': ' )] : $ entity ->value ,
191178 $ entity ->attributes ,
192179 );
180+
181+ if ($ this ->isFirstClassCallable ($ node )) {
182+ $ entity = $ stmt ->getEntity ();
183+ if (is_array ($ entity )) {
184+ if ($ entity [0 ] === '' ) {
185+ return new Definitions \FunctionCallable ($ entity [1 ]);
186+ }
187+ return new Definitions \MethodCallable (...$ entity );
188+ } else {
189+ throw new Nette \DI \InvalidConfigurationException ("Cannot create closure for ' $ entity' in config file (used in ' $ this ->file ') " );
190+ }
191+ }
192+
193+ return $ stmt ;
194+ }
195+
196+
197+ private function isFirstClassCallable (Node \EntityNode $ node ): bool
198+ {
199+ return array_keys ($ node ->attributes ) === [0 ]
200+ && $ node ->attributes [0 ]->key === null
201+ && $ node ->attributes [0 ]->value instanceof Node \LiteralNode
202+ && $ node ->attributes [0 ]->value ->value === '... ' ;
193203 }
194204
195205
@@ -211,7 +221,11 @@ private function removeUnderscoreVisitor(Node $node): void
211221 unset($ node ->attributes [$ i ]);
212222 $ index = true ;
213223
214- } elseif ($ attr ->value instanceof Node \LiteralNode && $ attr ->value ->value === '... ' ) {
224+ } elseif (
225+ $ attr ->value instanceof Node \LiteralNode
226+ && $ attr ->value ->value === '... '
227+ && !$ this ->isFirstClassCallable ($ node )
228+ ) {
215229 trigger_error ("Replace ... with _ in configuration file ' $ this ->file '. " , E_USER_DEPRECATED );
216230 unset($ node ->attributes [$ i ]);
217231 $ index = true ;
0 commit comments