@@ -53,6 +53,17 @@ final class StreamWrapper implements StreamWrapperInterface
5353
5454 private static string $ cacheDir = '' ;
5555
56+ /**
57+ * Resets the compiled pattern cache. Useful for test isolation.
58+ */
59+ public static function reset (): void
60+ {
61+ self ::$ isInitialized = false ;
62+ self ::$ includeRawPatterns = [];
63+ self ::$ excludeRawPatterns = [];
64+ self ::$ baseDir = '' ;
65+ }
66+
5667 /**
5768 * @param array<string, mixed> $config
5869 */
@@ -515,20 +526,32 @@ private static function isApplicationFile(string $path, string|false $resolvedPa
515526 return false ;
516527 }
517528
518- // Unconditionally prevent double-parsing cached files!
519529 $ normalizedCacheDir = rtrim (str_replace ('\\' , '/ ' , self ::$ cacheDir ), '/ ' ) . '/ ' ;
520530 if (str_starts_with ($ normalizedPath , $ normalizedCacheDir )) {
521531 return false ;
522532 }
523533
524- $ longestIncludeMatch = 0 ;
525534 $ isVendorPath = str_contains ($ normalizedPath , '/vendor/ ' );
535+ if ($ isVendorPath ) {
536+ $ hasExplicitVendorWhitelist = false ;
537+ foreach (self ::$ includeRawPatterns as $ pattern => $ regex ) {
538+ if (str_starts_with ($ pattern , 'vendor/ ' ) && preg_match ($ regex , $ normalizedPath ) === 1 ) {
539+ $ hasExplicitVendorWhitelist = true ;
526540
541+ break ;
542+ }
543+ }
544+
545+ if (! $ hasExplicitVendorWhitelist ) {
546+ return false ;
547+ }
548+ }
549+
550+ $ longestIncludeMatch = 0 ;
527551 foreach (self ::$ includeRawPatterns as $ pattern => $ regex ) {
528552 $ isExplicitVendorInclude = str_starts_with ($ pattern , 'vendor/ ' );
529553 $ isWildcard = ($ pattern === '* ' || $ pattern === '** ' );
530554
531- // Application include rules (like src/**, src/Core/**) never match inside vendor directories
532555 if ($ isVendorPath && ! $ isExplicitVendorInclude && ! $ isWildcard ) {
533556 continue ;
534557 }
@@ -661,4 +684,4 @@ private static function extractAndSeedFileMetadata(array $stmts, string $filePat
661684
662685 SpecialTypeResolver::seedFileMetadata ($ filePath , $ namespace , $ imports , $ classTraitUseDocs );
663686 }
664- }
687+ }
0 commit comments