- Added recursion to RouteFetching

This commit is contained in:
Dave M. 2021-03-10 00:53:50 +00:00
parent 56a5c45588
commit 6fcfd20aed
1 changed files with 15 additions and 3 deletions

View File

@ -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;