getPath()) . '/Admin/Routes'); /** @var Directory|File $child */ foreach ($directories as $child) { if ($child instanceof Directory) { foreach ($child as $file) { if (!\is_dir(__DIR__ . '/../../' . $child->getName() . '/' . \basename($file->getName(), '.php')) || ($appInfo !== null && \basename($file->getName(), '.php') !== $appInfo->getInternalName()) ) { continue; } self::installRoutesHooks(__DIR__ . '/../../' . $child->getName() . '/' . \basename($file->getName(), '.php') . '/Routes.php', $file->getPath()); } } elseif ($child instanceof File) { if (!\is_dir(__DIR__ . '/../../' . $child->getName()) || ($appInfo !== null && \basename($child->getName(), '.php') !== $appInfo->getInternalName()) ) { continue; } self::installRoutesHooks(__DIR__ . '/../../' . $child->getName() . '/Routes.php', $child->getPath()); } } } /** * Install routes. * * @param string $destRoutePath Destination route path * @param string $srcRoutePath Source route path * * @return void * * @throws PermissionException * * @since 1.0.0 */ protected static function installRoutesHooks(string $destRoutePath, string $srcRoutePath) : void { if (!\is_file($destRoutePath)) { \file_put_contents($destRoutePath, 'getPath()) . '/Admin/Hooks'); /** @var Directory|File $child */ foreach ($directories as $child) { if ($child instanceof Directory) { foreach ($child as $file) { if (!\is_dir(__DIR__ . '/../../' . $child->getName() . '/' . \basename($file->getName(), '.php')) || ($appInfo !== null && \basename($file->getName(), '.php') !== $appInfo->getInternalName()) ) { continue; } self::installRoutesHooks(__DIR__ . '/../../' . $child->getName() . '/' . \basename($file->getName(), '.php') . '/Hooks.php', $file->getPath()); } } elseif ($child instanceof File) { if (!\is_dir(__DIR__ . '/../../' . $child->getName()) || ($appInfo !== null && \basename($child->getName(), '.php') !== $appInfo->getInternalName()) ) { continue; } self::installRoutesHooks(__DIR__ . '/../../' . $child->getName() . '/Hooks.php', $child->getPath()); } } } /** * Deactivate module. * * @param DatabasePool $dbPool Database instance * @param ModuleInfo $info Module info * * @return void * * @since 1.0.0 */ public static function deactivate(DatabasePool $dbPool, ModuleInfo $info) : void { self::deactivateRoutes($info); self::deactivateHooks($info); } /** * Deactivate routes. * * @param ModuleInfo $info Module info * @param null|ApplicationInfo $appInfo Application info * * @return void * * @since 1.0.0 */ public static function deactivateRoutes(ModuleInfo $info, ApplicationInfo $appInfo = null) : void { $directories = new Directory(\dirname($info->getPath()) . '/Admin/Routes'); /** @var Directory|File $child */ foreach ($directories as $child) { if ($child instanceof Directory) { foreach ($child as $file) { if (!\is_dir(__DIR__ . '/../../' . $child->getName() . '/' . \basename($file->getName(), '.php')) || ($appInfo !== null && \basename($file->getName(), '.php') !== $appInfo->getInternalName()) ) { continue; } self::uninstallRoutesHooks(__DIR__ . '/../../' . $child->getName() . '/' . \basename($file->getName(), '.php') . '/Routes.php', $file->getPath()); } } elseif ($child instanceof File) { if (!\is_dir(__DIR__ . '/../../' . $child->getName()) || ($appInfo !== null && \basename($child->getName(), '.php') !== $appInfo->getInternalName()) ) { continue; } self::uninstallRoutesHooks(__DIR__ . '/../../' . $child->getName() . '/Routes.php', $child->getPath()); } } } /** * Uninstall routes. * * @param string $destRoutePath Destination route path * @param string $srcRoutePath Source route path * * @return void * * @throws PermissionException * * @since 1.0.0 */ public static function uninstallRoutesHooks(string $destRoutePath, string $srcRoutePath) : void { if (!\is_file($destRoutePath) || !\is_file($srcRoutePath) ) { return; } if (!\is_file($destRoutePath)) { throw new PathException($destRoutePath); } if (!\is_writable($destRoutePath)) { throw new PermissionException($destRoutePath); } /** @noinspection PhpIncludeInspection */ $appRoutes = include $destRoutePath; /** @noinspection PhpIncludeInspection */ $moduleRoutes = include $srcRoutePath; $appRoutes = ArrayUtils::array_diff_assoc_recursive($appRoutes, $moduleRoutes); \file_put_contents($destRoutePath, 'getPath()) . '/Admin/Hooks'); /** @var Directory|File $child */ foreach ($directories as $child) { if ($child instanceof Directory) { foreach ($child as $file) { if (!\is_dir(__DIR__ . '/../../' . $child->getName() . '/' . \basename($file->getName(), '.php')) || ($appInfo !== null && \basename($file->getName(), '.php') !== $appInfo->getInternalName()) ) { continue; } self::uninstallRoutesHooks(__DIR__ . '/../../' . $child->getName() . '/' . \basename($file->getName(), '.php') . '/Hooks.php', $file->getPath()); } } elseif ($child instanceof File) { if (!\is_dir(__DIR__ . '/../../' . $child->getName()) || ($appInfo !== null && \basename($child->getName(), '.php') !== $appInfo->getInternalName()) ) { continue; } self::uninstallRoutesHooks(__DIR__ . '/../../' . $child->getName() . '/Hooks.php', $child->getPath()); } } } }