From 592bd52667b041094cc892046f9f1e8ed1ea09dd Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 1 Apr 2018 18:54:13 +0200 Subject: [PATCH] Implement hook support --- Module/InstallerAbstract.php | 100 ++++++++++++++++++++++++++++------- 1 file changed, 82 insertions(+), 18 deletions(-) diff --git a/Module/InstallerAbstract.php b/Module/InstallerAbstract.php index 2844a3c5e..927651664 100644 --- a/Module/InstallerAbstract.php +++ b/Module/InstallerAbstract.php @@ -100,6 +100,7 @@ class InstallerAbstract { self::registerInDatabase($dbPool, $info); self::initRoutes($modulePath, $info); + self::initHooks($modulePath, $info); self::activate($dbPool, $info); } @@ -133,6 +134,7 @@ class InstallerAbstract public static function reInit(string $modulePath, InfoManager $info) : void { self::initRoutes($modulePath, $info); + self::initHooks($modulePath, $info); } /** @@ -149,7 +151,6 @@ class InstallerAbstract */ private static function initRoutes(string $modulePath, InfoManager $info) : void { - // todo: maybe use static::__DIR__ ? $directories = new Directory($modulePath . '/Admin/Routes'); foreach ($directories as $key => $subdir) { @@ -179,27 +180,90 @@ class InstallerAbstract file_put_contents($destRoutePath, ' $subdir) { + if ($subdir instanceof Directory) { + foreach ($subdir as $key2 => $file) { + self::installHooks(__DIR__ . '/../../' . $subdir->getName() . '/' . basename($file->getName(), '.php') . '/Hooks.php', $file->getPath()); + } } } } + + /** + * Install hooks. + * + * @param string $destHookPath Destination hook path + * @param string $srcHookPath Source hook path + * + * @return void + * + * @throws PermissionException + * + * @since 1.0.0 + */ + private static function installHooks(string $destHookPath, string $srcHookPath) : void + { + if (!file_exists($destHookPath)) { + file_put_contents($destHookPath, '