diff --git a/src/RouteFetcher.php b/src/RouteFetcher.php index 4ebc7f6..bb4f4a9 100644 --- a/src/RouteFetcher.php +++ b/src/RouteFetcher.php @@ -46,16 +46,23 @@ class RouteFetcher { $this->folderList = $list; } - public function scan() : Generator + public function scan(? array $folders = null) : Generator { - foreach($this->folderList as $namespace => $folder) { + foreach($folders ?: $this->folderList as $namespace => $folder) { if ( ! file_exists($folder) ) { throw new RuntimeException(sprintf("Folder `%s` can not be found or scanned", $folder)); } foreach (new DirectoryIterator($folder) as $fileinfo) { if ( ! $fileinfo->isDot() ) { - yield $namespace => $fileinfo; + if ( $fileinfo->isDir() ) { + foreach($this->scan([ "{$namespace}\\" . $fileinfo->getBasename() => $fileinfo->getPathname() ]) as $ns2 => $fi2) { + yield $ns2 => $fi2; + } + } + else { + yield $namespace => $fileinfo; + } } } } @@ -64,6 +71,10 @@ class RouteFetcher { public function compile() : Generator { foreach($this->scan() as $namespace => $file) { + if ( $file->getExtension() !== "php" ) { + continue; + } + $base = ""; $class = $this->generateClassname($file->getBasename(".php"), $namespace); $methods = $this->defaultMethods; @@ -80,6 +91,7 @@ class RouteFetcher { } $routeList = $objectResolver->getAnnotationListFromClassname( $this->annotations['method'] ); + foreach($routeList as $func => $routes) { foreach($routes as $route) { $route->base = $base;