@@ -28,6 +28,8 @@ class ResolveAutowireInlineAttributesPass extends AbstractRecursivePass
28
28
{
29
29
protected bool $ skipScalars = true ;
30
30
31
+ private int $ counter ;
32
+
31
33
protected function processValue (mixed $ value , bool $ isRoot = false ): mixed
32
34
{
33
35
$ value = parent ::processValue ($ value , $ isRoot );
@@ -36,6 +38,10 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
36
38
return $ value ;
37
39
}
38
40
41
+ if ($ isRoot ) {
42
+ $ this ->counter = 0 ;
43
+ }
44
+
39
45
$ isChildDefinition = $ value instanceof ChildDefinition;
40
46
41
47
try {
@@ -92,10 +98,14 @@ private function registerAutowireInlineAttributes(\ReflectionFunctionAbstract $m
92
98
}
93
99
94
100
if (\array_key_exists ('$ ' .$ parameter ->name , $ arguments ) || (\array_key_exists ($ index , $ arguments ) && '' !== $ arguments [$ index ])) {
101
+ $ attribute = \array_key_exists ('$ ' .$ parameter ->name , $ arguments ) ? $ arguments ['$ ' .$ parameter ->name ] : $ arguments [$ index ];
102
+ if (!$ attribute instanceof AutowireInline) {
103
+ continue ;
104
+ }
105
+ } elseif (!$ attribute = $ parameter ->getAttributes (AutowireInline::class, \ReflectionAttribute::IS_INSTANCEOF )[0 ] ?? null ) {
95
106
continue ;
96
- }
97
- if (!$ attribute = $ parameter ->getAttributes (AutowireInline::class, \ReflectionAttribute::IS_INSTANCEOF )[0 ] ?? null ) {
98
- continue ;
107
+ } else {
108
+ $ attribute = $ attribute ->newInstance ();
99
109
}
100
110
101
111
$ type = ProxyHelper::exportType ($ parameter , true );
@@ -104,25 +114,18 @@ private function registerAutowireInlineAttributes(\ReflectionFunctionAbstract $m
104
114
continue ;
105
115
}
106
116
107
- $ attribute = $ attribute ->newInstance ();
108
117
$ definition = $ attribute ->buildDefinition ($ attribute ->value , $ type , $ parameter );
109
118
110
119
$ paramResolverContainer ->setDefinition ('.autowire_inline ' , $ definition );
111
120
(new ResolveParameterPlaceHoldersPass (false , false ))->process ($ paramResolverContainer );
112
121
113
- $ id = '.autowire_inline. ' .ContainerBuilder:: hash ([ $ this ->currentId , $ method -> class ?? null , $ method -> name , ( string ) $ parameter ]) ;
122
+ $ id = '.autowire_inline. ' .$ this ->currentId . ' . ' .++ $ this -> counter ;
114
123
115
124
$ this ->container ->setDefinition ($ id , $ definition );
116
125
$ arguments [$ isChildDefinition ? '$ ' .$ parameter ->name : $ index ] = new Reference ($ id );
117
126
118
127
if ($ definition ->isAutowired ()) {
119
- $ currentId = $ this ->currentId ;
120
- try {
121
- $ this ->currentId = $ id ;
122
- $ this ->processValue ($ definition , true );
123
- } finally {
124
- $ this ->currentId = $ currentId ;
125
- }
128
+ $ this ->processValue ($ definition );
126
129
}
127
130
}
128
131
0 commit comments