@@ -126,6 +126,7 @@ public function registerClasses(Definition $prototype, string $namespace, string
126
126
if (null === $ errorMessage && $ autoconfigureAttributes ) {
127
127
$ r = $ this ->container ->getReflectionClass ($ class );
128
128
if ($ r ->getAttributes (Exclude::class)[0 ] ?? null ) {
129
+ $ this ->addContainerExcludedTag ($ class , $ source );
129
130
continue ;
130
131
}
131
132
if ($ this ->env ) {
@@ -137,6 +138,7 @@ public function registerClasses(Definition $prototype, string $namespace, string
137
138
}
138
139
}
139
140
if (null !== $ attribute ) {
141
+ $ this ->addContainerExcludedTag ($ class , $ source );
140
142
continue ;
141
143
}
142
144
}
@@ -291,18 +293,29 @@ private function findClasses(string $namespace, string $pattern, array $excludeP
291
293
}
292
294
293
295
if (null !== $ prefixLen ) {
294
- $ attributes = null !== $ source ? ['source ' => sprintf ('in "%s/%s" ' , basename (\dirname ($ source )), basename ($ source ))] : [];
295
-
296
296
foreach ($ excludePaths as $ path => $ _ ) {
297
297
$ class = $ namespace .ltrim (str_replace ('/ ' , '\\' , substr ($ path , $ prefixLen , str_ends_with ($ path , '.php ' ) ? -4 : null )), '\\' );
298
- if (!$ this ->container ->has ($ class )) {
299
- $ this ->container ->register ($ class )
300
- ->setAbstract (true )
301
- ->addTag ('container.excluded ' , $ attributes );
302
- }
298
+ $ this ->addContainerExcludedTag ($ class , $ source );
303
299
}
304
300
}
305
301
306
302
return $ classes ;
307
303
}
304
+
305
+ private function addContainerExcludedTag (string $ class , ?string $ source ): void
306
+ {
307
+ if ($ this ->container ->has ($ class )) {
308
+ return ;
309
+ }
310
+
311
+ static $ attributes = [];
312
+
313
+ if (null !== $ source && !isset ($ attributes [$ source ])) {
314
+ $ attributes [$ source ] = ['source ' => sprintf ('in "%s/%s" ' , basename (\dirname ($ source )), basename ($ source ))];
315
+ }
316
+
317
+ $ this ->container ->register ($ class )
318
+ ->setAbstract (true )
319
+ ->addTag ('container.excluded ' , null !== $ source ? $ attributes [$ source ] : []);
320
+ }
308
321
}
0 commit comments