From b1a8e92de7306e0b780c6f406e797d2d21165323 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 31 Mar 2017 15:19:22 +0200 Subject: [PATCH] Removing ROOT_PATH --- Module/InfoManager.php | 15 ++++++++++++++- Module/InstallerAbstract.php | 2 +- Module/ModuleManager.php | 27 ++++++++++----------------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/Module/InfoManager.php b/Module/InfoManager.php index f2b4c0f1a..a548c5c25 100644 --- a/Module/InfoManager.php +++ b/Module/InfoManager.php @@ -62,7 +62,20 @@ class InfoManager */ public function __construct($path) { - $this->path = $path; + $this->path = realpath($path); + } + + /** + * Get info path + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getPath() : string + { + return $this->path; } /** diff --git a/Module/InstallerAbstract.php b/Module/InstallerAbstract.php index ac1ca03e9..2e3d2b4c8 100644 --- a/Module/InstallerAbstract.php +++ b/Module/InstallerAbstract.php @@ -158,7 +158,7 @@ class InstallerAbstract private static function initRoutes(string $routePath, InfoManager $info) /* : void */ { // todo: maybe use static::__DIR__ ? - $directories = new Directory(ROOT_PATH . '/Modules/' . $info->getDirectory() . '/Admin/Routes'); + $directories = new Directory(dirname($info->getPath()) . '/Modules/' . $info->getDirectory() . '/Admin/Routes'); foreach ($directories as $key => $subdir) { if ($subdir instanceof Directory) { diff --git a/Module/ModuleManager.php b/Module/ModuleManager.php index dbb1ca39b..6dc924b4c 100644 --- a/Module/ModuleManager.php +++ b/Module/ModuleManager.php @@ -39,14 +39,6 @@ use phpOMS\System\File\PathException; class ModuleManager { - /** - * Module path. - * - * @var string - * @since 1.0.0 - */ - /* public */ const MODULE_PATH = __DIR__ . '/../../Modules'; - /** * All modules that are running on this uri. * @@ -103,9 +95,10 @@ class ModuleManager * @since 1.0.0 * @author Dennis Eichhorn */ - public function __construct(ApplicationAbstract $app) + public function __construct(ApplicationAbstract $app, string $modulePath = '') { $this->app = $app; + $modulePath = $modulePath; } /** @@ -242,12 +235,12 @@ class ModuleManager public static function getAllModules() : array { if (!isset(self::$all)) { - chdir(self::MODULE_PATH); + chdir($this->modulePath); $files = glob('*', GLOB_ONLYDIR); $c = count($files); for ($i = 0; $i < $c; $i++) { - $path = self::MODULE_PATH . '/' . $files[$i] . '/info.json'; + $path = $this->modulePath . '/' . $files[$i] . '/info.json'; if (!file_exists($path)) { continue; @@ -368,7 +361,7 @@ class ModuleManager throw new \Exception('Module installer does not exist'); } - $class::reInit(ROOT_PATH, $info); + $class::reInit($this->modulePath, $info); } /** @@ -389,7 +382,7 @@ class ModuleManager return false; } - if (!file_exists(self::MODULE_PATH . '/' . $module . '/Admin/Installer.php')) { + if (!file_exists($this->modulePath . '/' . $module . '/Admin/Installer.php')) { // todo download; return false; } @@ -463,7 +456,7 @@ class ModuleManager throw new \Exception('Module installer does not exist'); } - $class::install(ROOT_PATH, $this->app->dbPool, $info); + $class::install($this->modulePath, $this->app->dbPool, $info); } /** @@ -526,7 +519,7 @@ class ModuleManager */ private function loadInfo(string $module) : InfoManager { - $path = realpath($oldPath = self::MODULE_PATH . '/' . $module . '/' . 'info.json'); + $path = realpath($oldPath = $this->modulePath . '/' . $module . '/' . 'info.json'); if ($path === false) { throw new PathException($oldPath); @@ -576,10 +569,10 @@ class ModuleManager */ public function installProviding(string $from, string $for) /* : void */ { - if (file_exists(self::MODULE_PATH . '/' . $from . '/Admin/Install/' . $for . '.php')) { + if (file_exists($this->modulePath . '/' . $from . '/Admin/Install/' . $for . '.php')) { $class = '\\Modules\\' . $from . '\\Admin\\Install\\' . $for; /** @var $class InstallerAbstract */ - $class::install(ROOT_PATH, $this->app->dbPool, null); + $class::install($this->modulePath, $this->app->dbPool, null); } }