@@ -273,46 +273,58 @@ public function addResource(ResourceInterface $resource): static
273
273
if ($ resource instanceof DirectoryResource && $ this ->inVendors ($ resource ->getResource ())) {
274
274
return $ this ;
275
275
}
276
- if ($ resource instanceof ClassExistenceResource) {
277
- $ class = $ resource-> getResource () ;
276
+ if (! $ resource instanceof ClassExistenceResource) {
277
+ $ this -> resources [( string ) $ resource ] = $ resource ;
278
278
279
- $ inVendor = false ;
280
- foreach (spl_autoload_functions () as $ autoloader ) {
281
- if (!\is_array ($ autoloader )) {
282
- continue ;
283
- }
279
+ return $ this ;
280
+ }
284
281
285
- if ($ autoloader [0 ] instanceof DebugClassLoader) {
286
- $ autoloader = $ autoloader [0 ]->getClassLoader ();
287
- }
282
+ $ class = $ resource ->getResource ();
283
+
284
+ if (!(new ClassExistenceResource ($ class , false ))->isFresh (1 )) {
285
+ if (!$ this ->inVendors ((new \ReflectionClass ($ class ))->getFileName ())) {
286
+ $ this ->resources [$ class ] = $ resource ;
287
+ }
288
+
289
+ return $ this ;
290
+ }
291
+
292
+ $ inVendor = true ;
293
+ foreach (spl_autoload_functions () as $ autoloader ) {
294
+ if (!\is_array ($ autoloader )) {
295
+ $ inVendor = false ;
296
+ break ;
297
+ }
298
+
299
+ if ($ autoloader [0 ] instanceof DebugClassLoader) {
300
+ $ autoloader = $ autoloader [0 ]->getClassLoader ();
301
+ }
288
302
289
- if (!\is_array ($ autoloader ) || !$ autoloader [0 ] instanceof ClassLoader || !$ autoloader [0 ]->findFile (__CLASS__ )) {
303
+ if (!\is_array ($ autoloader ) || !$ autoloader [0 ] instanceof ClassLoader) {
304
+ $ inVendor = false ;
305
+ break ;
306
+ }
307
+
308
+ foreach ($ autoloader [0 ]->getPrefixesPsr4 () as $ prefix => $ dirs ) {
309
+ if (!str_starts_with ($ class , $ prefix )) {
290
310
continue ;
291
311
}
292
312
293
- foreach ($ autoloader [ 0 ]-> getPrefixesPsr4 () as $ prefix => $ dirs ) {
294
- if ('' === $ prefix || ! str_starts_with ( $ class , $ prefix )) {
313
+ foreach ($ dirs as $ dir ) {
314
+ if (! $ dir = realpath ( $ dir )) {
295
315
continue ;
296
316
}
297
317
298
- foreach ($ dirs as $ dir ) {
299
- if (!$ dir = realpath ($ dir )) {
300
- continue ;
301
- }
302
-
303
- if (!$ inVendor = $ this ->inVendors ($ dir )) {
304
- break 3 ;
305
- }
318
+ if (!$ inVendor = $ this ->inVendors ($ dir )) {
319
+ break 3 ;
306
320
}
307
321
}
308
322
}
309
-
310
- if ($ inVendor ) {
311
- return $ this ;
312
- }
313
323
}
314
324
315
- $ this ->resources [(string ) $ resource ] = $ resource ;
325
+ if (!$ inVendor ) {
326
+ $ this ->resources [$ class ] = $ resource ;
327
+ }
316
328
317
329
return $ this ;
318
330
}
0 commit comments