File tree Expand file tree Collapse file tree 4 files changed +34
-3
lines changed Expand file tree Collapse file tree 4 files changed +34
-3
lines changed Original file line number Diff line number Diff line change 12
12
use PhpParser \Node \Expr \FuncCall ;
13
13
use PhpParser \Node \Name \FullyQualified ;
14
14
use PhpParser \Node \Scalar \String_ ;
15
+ use Symplify \PhpConfigPrinter \Naming \ReferenceFunctionNameResolver ;
15
16
use Symplify \PhpConfigPrinter \NodeFactory \CommonNodeFactory ;
16
17
use Symplify \PhpConfigPrinter \NodeFactory \ConstantNodeFactory ;
17
18
use Symplify \PhpConfigPrinter \ValueObject \FunctionName ;
@@ -69,7 +70,7 @@ public function resolve(
69
70
return $ this ->resolveServiceReferenceExpr (
70
71
$ value ,
71
72
$ skipServiceReference ,
72
- FunctionName:: SERVICE ,
73
+ ReferenceFunctionNameResolver:: resolve () ,
73
74
$ isRoutingImport
74
75
);
75
76
}
Original file line number Diff line number Diff line change 7
7
use PhpParser \Node \ArrayItem ;
8
8
use PhpParser \Node \Expr \Array_ ;
9
9
use Symfony \Component \Yaml \Tag \TaggedValue ;
10
+ use Symplify \PhpConfigPrinter \Naming \ReferenceFunctionNameResolver ;
10
11
use Symplify \PhpConfigPrinter \ValueObject \FunctionName ;
11
12
12
13
final readonly class TaggedReturnsCloneResolver
@@ -23,7 +24,7 @@ public function resolve(TaggedValue $taggedValue): Array_
23
24
$ expr = $ this ->serviceReferenceExprResolver ->resolveServiceReferenceExpr (
24
25
$ serviceName ,
25
26
false ,
26
- FunctionName:: SERVICE
27
+ ReferenceFunctionNameResolver:: resolve ()
27
28
);
28
29
29
30
return new Array_ ([new ArrayItem ($ expr )]);
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Symplify \PhpConfigPrinter \Naming ;
6
+
7
+ use Symplify \PhpConfigPrinter \ValueObject \FunctionName ;
8
+
9
+ /**
10
+ * This helped method loads existing functions to refer a service
11
+ * ref() or service() based on the Symfony version of current project
12
+ */
13
+ final class ReferenceFunctionNameResolver
14
+ {
15
+ /**
16
+ * @return FunctionName::REF|FunctionName::SERVICE
17
+ */
18
+ public static function resolve (): string
19
+ {
20
+ if (function_exists (FunctionName::REF )) {
21
+ return FunctionName::REF ;
22
+ }
23
+
24
+ // fallback to service
25
+ return FunctionName::SERVICE ;
26
+ }
27
+ }
Original file line number Diff line number Diff line change 11
11
use PhpParser \Node \Expr \FuncCall ;
12
12
use PhpParser \Node \Name \FullyQualified ;
13
13
use PhpParser \Node \Scalar \String_ ;
14
+ use Symplify \PhpConfigPrinter \Naming \ReferenceFunctionNameResolver ;
14
15
use Symplify \PhpConfigPrinter \NodeFactory \ArgsNodeFactory ;
15
16
use Symplify \PhpConfigPrinter \ValueObject \FunctionName ;
16
17
@@ -70,6 +71,7 @@ private function createServiceFuncCall(string $serviceName): FuncCall
70
71
{
71
72
$ serviceFuncCallArgs = $ this ->argsNodeFactory ->createFromValues ([$ serviceName ]);
72
73
73
- return new FuncCall (new FullyQualified (FunctionName::SERVICE ), $ serviceFuncCallArgs );
74
+ $ functionName = ReferenceFunctionNameResolver::resolve ();
75
+ return new FuncCall (new FullyQualified ($ functionName ), $ serviceFuncCallArgs );
74
76
}
75
77
}
You can’t perform that action at this time.
0 commit comments