@@ -38,12 +38,13 @@ public function __construct(
3838 */
3939 public function load (mixed $ resource , ?string $ type = null ): ?RouteCollection
4040 {
41+ $ excluded = $ resource ['_excluded ' ] ?? [];
4142 $ path = $ this ->locator ->locate ($ resource ['path ' ], $ this ->currentDirectory );
4243 if (!is_dir ($ path )) {
4344 return new RouteCollection ();
4445 }
4546
46- return $ this ->loadFromDirectory ($ path , trim ($ resource ['namespace ' ], '\\' ));
47+ return $ this ->loadFromDirectory ($ path , trim ($ resource ['namespace ' ], '\\' ), $ excluded );
4748 }
4849
4950 public function supports (mixed $ resource , ?string $ type = null ): bool
@@ -59,7 +60,7 @@ public function forDirectory(string $currentDirectory): static
5960 return $ loader ;
6061 }
6162
62- private function loadFromDirectory (string $ directory , string $ psr4Prefix ): RouteCollection
63+ private function loadFromDirectory (string $ directory , string $ psr4Prefix, array $ excluded = [] ): RouteCollection
6364 {
6465 $ collection = new RouteCollection ();
6566 $ collection ->addResource (new DirectoryResource ($ directory , '/\.php$/ ' ));
@@ -74,8 +75,13 @@ private function loadFromDirectory(string $directory, string $psr4Prefix): Route
7475
7576 /** @var \SplFileInfo $file */
7677 foreach ($ files as $ file ) {
78+ $ normalizedPath = rtrim (str_replace ('\\' , '/ ' , $ file ->getPathname ()), '/ ' );
79+ if (isset ($ excluded [$ normalizedPath ])) {
80+ continue ;
81+ }
82+
7783 if ($ file ->isDir ()) {
78- $ collection ->addCollection ($ this ->loadFromDirectory ($ file ->getPathname (), $ psr4Prefix .'\\' .$ file ->getFilename ()));
84+ $ collection ->addCollection ($ this ->loadFromDirectory ($ file ->getPathname (), $ psr4Prefix .'\\' .$ file ->getFilename (), $ excluded ));
7985
8086 continue ;
8187 }
0 commit comments