From 6c961ea58e701239ace094a89e387338aed00547 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 19 Jul 2016 17:54:11 +0200 Subject: [PATCH] Creating application routing --- Module/InstallerAbstract.php | 16 +++++++++++++--- System/File/Directory.php | 12 ++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Module/InstallerAbstract.php b/Module/InstallerAbstract.php index 42612a3a6..a38e48ac9 100644 --- a/Module/InstallerAbstract.php +++ b/Module/InstallerAbstract.php @@ -150,9 +150,15 @@ class InstallerAbstract */ private static function initRoutes(InfoManager $info) { - self::installRoutes(ROOT_PATH . '/Web/Routes.php', ROOT_PATH . '/Modules/' . $info->getDirectory() . '/Admin/Routes/http.php'); - self::installRoutes(ROOT_PATH . '/Socket/Routes.php', ROOT_PATH . '/Modules/' . $info->getDirectory() . '/Admin/Routes/socket.php'); - self::installRoutes(ROOT_PATH . '/Console/Routes.php', ROOT_PATH . '/Modules/' . $info->getDirectory() . '/Admin/Routes/console.php'); + $directories = new Directory(ROOT_PATH . '/Modules/' . $info->getDirectory() . '/Admin/Routes'); + + foreach($directories as $key => $subdir) { + if($subdir instanceOf Directory) { + foreach($subdir as $key2 => $file) { + self::installRoutes(ROOT_PATH . '/' . $subdir->getName() . '/' . $file->getName() . '/Routes.php', $file->getPath()); + } + } + } } /** @@ -170,6 +176,10 @@ class InstallerAbstract */ private static function installRoutes(string $destRoutePath, string $srcRoutePath) { + if(!file_exists($destRoutePath)) { + mkdir($destRoutePath); + } + if (file_exists($destRoutePath) && file_exists($srcRoutePath)) { /** @noinspection PhpIncludeInspection */ $appRoutes = include $destRoutePath; diff --git a/System/File/Directory.php b/System/File/Directory.php index 5b36d9c6d..e25913afd 100644 --- a/System/File/Directory.php +++ b/System/File/Directory.php @@ -80,15 +80,11 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess parent::index(); foreach (glob($this->path . DIRECTORY_SEPARATOR . $this->filter) as $filename) { - // todo: handle . and ..???!!! - if (is_dir($filename)) { - $file = new Directory($filename); - $file->index(); - } else { - $file = new File($filename); - } + if(strpos($filename, '.') === false) { + $file = is_dir($filename) ? new self($filename) : new File($filename); - $this->add($file); + $this->add($file); + } } }