diff --git a/src/Classes/FileHasher/ChangedEntry.php b/src/Classes/FileHasher/ChangedEntry.php index 545c3cd7..cecf86a2 100644 --- a/src/Classes/FileHasher/ChangedEntry.php +++ b/src/Classes/FileHasher/ChangedEntry.php @@ -52,4 +52,19 @@ public function clone(): ChangedEntry $changedEntry->type = $this->type; return $changedEntry; } + + public static function typeToString(int $type): string + { + if ($type === self::TYPE_UNCHANGED) { + return 'unchanged'; + } elseif ($type === self::TYPE_NEW) { + return 'new'; + } elseif ($type === self::TYPE_DELETED) { + return 'deleted'; + } elseif ($type === self::TYPE_CHANGED) { + return 'changed'; + } + + return 'unkown type'; + } } diff --git a/src/Classes/Helpers/FileHelper.php b/src/Classes/Helpers/FileHelper.php index ed7cdcce..9d66f8c3 100644 --- a/src/Classes/Helpers/FileHelper.php +++ b/src/Classes/Helpers/FileHelper.php @@ -155,4 +155,29 @@ public static function containsAllFiles($files, $baseDirectory): bool } return true; } + + public static function deletePathIsEmpty(string $path): void + { + if (file_exists($path) && !is_dir($path)) { + return; + } + + if (file_exists($path) && is_dir($path) && !self::isDirEmpty($path)) { + return; + } + + if (file_exists($path) && is_dir($path) && self::isDirEmpty($path)) { + rmdir($path); + } + + self::deletePathIsEmpty(dirname($path)); + } + + public static function isDirEmpty(string $path): bool + { + if (!is_readable($path)) { + return false; + } + return (count(scandir($path)) === 2); + } } diff --git a/src/Classes/Module.php b/src/Classes/Module.php index 2ea81aa1..915ccb2d 100644 --- a/src/Classes/Module.php +++ b/src/Classes/Module.php @@ -71,6 +71,11 @@ class Module extends ModuleInfo */ private array $srcFilePaths; + /** + * @var string[] + */ + private array $srcMmlcFilePaths; + /** * @var bool */ @@ -235,7 +240,7 @@ public function setReadmePath(string $readmePath): void } /** - * Liefert ein Array mit Dateienpfaden, die sich in 'new_files' + * Liefert ein Array mit Dateienpfaden, die sich in 'src' * befinden. * * Beispiel: [ @@ -254,6 +259,20 @@ public function setSrcFilePaths(array $value): void $this->srcFilePaths = $value; } + /** + * Liefert ein Array mit Dateienpfaden, die sich in 'src-mmlc' + * befinden. + */ + public function getSrcMmlcFilePaths(): array + { + return $this->srcMmlcFilePaths; + } + + public function setSrcMmlcFilePaths(array $value): void + { + $this->srcMmlcFilePaths = $value; + } + /** * Liefert true, wenn es sich um ein Remote Modul handelt. */ @@ -296,13 +315,23 @@ public function getUrlOrLocalRootPath(): string /** * HIER FEHLT EINE BESCHREIBUNG * - * /Modules/{VENDOR-NAME}/{MODULE-NAME}/new_files + * /Modules/{VENDOR-NAME}/{MODULE-NAME}/src */ public function getSrcRootPath(): string { return $this->getModulePath() . '/' . $this->getSourceDir(); } + /** + * HIER FEHLT EINE BESCHREIBUNG + * + * /Modules/{VENDOR-NAME}/{MODULE-NAME}/src-mmlc + */ + public function getSrcMmlcRootPath(): string + { + return $this->getModulePath() . '/' . $this->getSourceMmlcDir(); + } + /** * HIER FEHLT EINE BESCHREIBUNG * diff --git a/src/Classes/ModuleChangeManager.php b/src/Classes/ModuleChangeManager.php index d5a62870..9bd14f92 100644 --- a/src/Classes/ModuleChangeManager.php +++ b/src/Classes/ModuleChangeManager.php @@ -30,6 +30,10 @@ class ModuleChangeManager */ public static function getChangedFiles(Module $module): ChangedEntryCollection { + if ($module->getArchiveName() === 'robinthehood/modified-std-module') { + $a = 1; + } + $hashFileLoader = new HashFileLoader(); $hashFileLoader->setDefaultScope(ModuleHasher::SCOPE_SHOP_ROOT); $hashFile = $hashFileLoader->load($module->getHashPath()); @@ -96,15 +100,22 @@ public static function getFileChanges(Module $module, ChangedEntry $changedEntry $changedEntry->hashEntryA->scope === ModuleHasher::SCOPE_SHOP_ROOT || $changedEntry->hashEntryA->scope === ModuleHasher::SCOPE_MODULE_SRC ) { - $moduleSrcFilePath = $module->getLocalRootPath() . $module->getSrcRootPath() . '/' . $changedEntry->hashEntryA->file; - $installedFilePath = App::getShopRoot() . '/' . ModulePathMapper::mmlcToShop($changedEntry->hashEntryA->file); + $moduleSrcFilePath = + $module->getLocalRootPath() . $module->getSrcRootPath() . '/' . $changedEntry->hashEntryA->file; + $installedFilePath = + App::getShopRoot() . '/' . ModulePathMapper::moduleSrcToShopRoot($changedEntry->hashEntryA->file); } elseif ( $changedEntry->hashEntryA->scope === ModuleHasher::SCOPE_SHOP_VENDOR_MMLC || $changedEntry->hashEntryA->scope === ModuleHasher::SCOPE_MODULE_SRC_MMLC ) { // TODO - $moduleSrcFilePath = ''; - $installedFilePath = ''; + $moduleSrcFilePath = + $module->getLocalRootPath() . $module->getSrcMmlcRootPath() . '/' . $changedEntry->hashEntryA->file; + $installedFilePath = + App::getShopRoot() . '/' . ModulePathMapper::moduleSrcMmlcToShopVendorMmlc( + $changedEntry->hashEntryA->file, + $module->getArchiveName() + ); } diff --git a/src/Classes/ModuleConverter.php b/src/Classes/ModuleConverter.php index 504e2289..48f42988 100644 --- a/src/Classes/ModuleConverter.php +++ b/src/Classes/ModuleConverter.php @@ -23,6 +23,7 @@ public static function convertToArray(Module $module): array 'name' => $module->getName(), 'archiveName' => $module->getArchiveName(), 'sourceDir' => $module->getSourceDir(), + 'sourceMmlcDir' => $module->getSourceMmlcDir(), 'version' => $module->getVersion(), 'shortDescription' => $module->getShortDescription(), 'description' => $module->getDescription(), @@ -50,6 +51,7 @@ public static function convertToArray(Module $module): array 'changelogPath' => $module->getChangelogPath(), 'readmePath' => $module->getReadmePath(), 'srcFilePaths' => $module->getSrcFilePaths(), + 'srcMmlcFilePaths' => $module->getSrcMmlcFilePaths(), 'isRemote' => $module->isRemote(), 'isLoadable' => $module->isLoadable() ]; diff --git a/src/Classes/ModuleCreator.php b/src/Classes/ModuleCreator.php index 6dd68a51..217a9128 100644 --- a/src/Classes/ModuleCreator.php +++ b/src/Classes/ModuleCreator.php @@ -50,32 +50,30 @@ public function createFolders($archiveName, $fileName, $vendorName, $moduleNameC file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/docs/usage.md', ''); file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/changelog.md', ''); - @mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files'); - @mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/admin'); - @mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/admin/includes'); - @mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/admin/includes/extra'); - @mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/admin/includes/modules'); - @mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/admin/includes/modules/system'); - file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/new_files/admin/includes/modules/system/' . $fileName, ''); - - @mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/includes'); - @mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/includes/extra'); - - @mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/lang'); - @mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/lang/german'); - @mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/lang/german/modules'); - @mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/lang/german/modules/system'); - file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/new_files/lang/german/modules/system/' . $fileName, ''); - - @mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/lang/english'); - @mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/lang/english/modules'); - @mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/lang/english/modules/system'); - file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/new_files/lang/english/modules/system/' . $fileName, ''); - - @mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/vendor-no-composer'); - @mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/vendor-no-composer/' . $vendorName); - @mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/vendor-no-composer/' . $vendorName . '/' . $moduleNameCamelCase); - @mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/vendor-no-composer/' . $vendorName . '/' . $moduleNameCamelCase . '/Classes'); + @mkdir(App::getModulesRoot() . '/' . $archiveName . '/src'); + @mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/admin'); + @mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/admin/includes'); + @mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/admin/includes/extra'); + @mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/admin/includes/modules'); + @mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/admin/includes/modules/system'); + file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/src/admin/includes/modules/system/' . $fileName, ''); + + @mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/includes'); + @mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/includes/extra'); + + @mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/lang'); + @mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/lang/german'); + @mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/lang/german/modules'); + @mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/lang/german/modules/system'); + file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/src/lang/german/modules/system/' . $fileName, ''); + + @mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/lang/english'); + @mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/lang/english/modules'); + @mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/lang/english/modules/system'); + file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/src/lang/english/modules/system/' . $fileName, ''); + + @mkdir(App::getModulesRoot() . '/' . $archiveName . '/src-mmlc/vendor-no-composer'); + @mkdir(App::getModulesRoot() . '/' . $archiveName . '/src-mmlc/Classes'); } public function createModuleInfoJsonFile($archiveName, $moduleName) @@ -83,7 +81,7 @@ public function createModuleInfoJsonFile($archiveName, $moduleName) $info = [ 'name' => $moduleName, 'archiveName' => $archiveName, - 'sourceDir' => 'new_files', + 'sourceDir' => 'src', 'version' => 'auto', 'shortDescription' => 'Kurzbeschreibung für ' . $moduleName, @@ -104,6 +102,15 @@ public function createModuleInfoJsonFile($archiveName, $moduleName) 'modifiedCompatibility' => [ '2.0.4.2' + ], + + "mmlc" => [ + "version" => "^1.21.0" + ], + + "php" => [ + "version" => "^7.4 || ^8.0", + "ext" => [] ] ]; @@ -145,7 +152,7 @@ public function remove() } '; - \file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/new_files/admin/includes/modules/system/' . $fileName, $content); + \file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/src/admin/includes/modules/system/' . $fileName, $content); } public function createSystemModuleLanguageDeFile($archiveName, $fileName, $moduleConstName, $vendorName) @@ -158,7 +165,7 @@ public function createSystemModuleLanguageDeFile($archiveName, $fileName, $modul define(\'' . $moduleConstName . '_STATUS_DESC\', \'\'); '; - \file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/new_files/lang/german/modules/system/' . $fileName, $content); + \file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/src/lang/german/modules/system/' . $fileName, $content); } public function createSystemModuleLanguageEnFile($archiveName, $fileName, $moduleConstName, $vendorName) @@ -171,6 +178,6 @@ public function createSystemModuleLanguageEnFile($archiveName, $fileName, $modul define(\'' . $moduleConstName . '_STATUS_DESC\', \'\'); '; - \file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/new_files/lang/english/modules/system/' . $fileName, $content); + \file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/src/lang/english/modules/system/' . $fileName, $content); } } diff --git a/src/Classes/ModuleFactory.php b/src/Classes/ModuleFactory.php index cc749e48..632b63b3 100644 --- a/src/Classes/ModuleFactory.php +++ b/src/Classes/ModuleFactory.php @@ -20,6 +20,9 @@ class ModuleFactory { + private const DIR_MODULE_SRC = 'src'; + private const DIR_MODULE_SRC_MMLC = "src-mmlc"; + public static function createFromPath(string $path): Module { $moduleInfoJsonPath = $path . '/moduleinfo.json'; @@ -35,10 +38,14 @@ public static function createFromPath(string $path): Module throw new \RuntimeException('Can not parse ' . $moduleInfoJsonPath); } + $sourceDir = $array['sourceDir'] ?? self::DIR_MODULE_SRC; + $sourceMmlcDir = $array['sourceMmlcDir'] ?? self::DIR_MODULE_SRC_MMLC; + $modulePath = FileHelper::stripBasePath(App::getRoot(), $path); $category = $array['category'] ?? ''; $localRootPath = App::getRoot(); - $absSrcRootPath = $localRootPath . $modulePath . '/' . $array['sourceDir']; + $absSrcRootPath = $localRootPath . $modulePath . '/' . $sourceDir; + $absSrcMmlcRootPath = $localRootPath . $modulePath . '/' . $sourceMmlcDir; $array['localRootPath'] = $localRootPath; $array['urlRootPath'] = ServerHelper::getUri(); @@ -49,6 +56,7 @@ public static function createFromPath(string $path): Module $array['changelogPath'] = self::createChangelogPath($modulePath, $path); $array['readmePath'] = self::createReadmePath($modulePath, $path); $array['srcFilePaths'] = self::createSrcFilePaths($absSrcRootPath); + $array['srcMmlcFilePaths'] = self::createSrcFilePaths($absSrcMmlcRootPath); $array['isRemote'] = false; $module = self::createFromArray($array); @@ -68,7 +76,8 @@ public static function createFromArray(array $array): Module // ModuleInfo $module->setName($array['name'] ?? ''); $module->setArchiveName($array['archiveName'] ?? ''); - $module->setSourceDir($array['sourceDir'] ?? 'new_files'); + $module->setSourceDir($array['sourceDir'] ?? self::DIR_MODULE_SRC); + $module->setSourceMmlcDir($array['sourceMmlcDir'] ?? self::DIR_MODULE_SRC_MMLC); $module->setVersion($array['version'] ?? 'auto'); $module->setShortDescription($array['shortDescription'] ?? ''); $module->setDescription($array['description'] ?? ''); @@ -95,6 +104,7 @@ public static function createFromArray(array $array): Module $module->setChangelogPath($array['changelogPath'] ?? ''); $module->setReadmePath($array['readmePath'] ?? ''); $module->setSrcFilePaths($array['srcFilePaths'] ?? []); + $module->setSrcMmlcFilePaths($array['srcMmlcFilePaths'] ?? []); $module->setRemote($array['isRemote'] ?? false); $module->setLoadable($array['isLoadable'] ?? false); diff --git a/src/Classes/ModuleHasher/ModuleHasher.php b/src/Classes/ModuleHasher/ModuleHasher.php index 74bd55c6..ef6f0603 100644 --- a/src/Classes/ModuleHasher/ModuleHasher.php +++ b/src/Classes/ModuleHasher/ModuleHasher.php @@ -35,7 +35,7 @@ public function __construct(FileHasherInterface $fileHasher) } /** - * /Module////... + * /..//Module////... */ public function createModuleSrcHashes(Module $module): HashEntryCollection { @@ -45,41 +45,33 @@ public function createModuleSrcHashes(Module $module): HashEntryCollection } /** - * /Module////... + * /..//Module////... */ public function createModuleSrcMmlcHashes(Module $module): HashEntryCollection { - return new HashEntryCollection([]); - - // TODO: Warte auf feat/vendor-mmlc - // $files = $module->getSrcMmlcFilePaths(); - // $root = $module->getLocalRootPath() . $module->getSrcMmlcRootPath() . '/'; - // return $this->fileHasher->createHashes($files, $root, self::SCOPE_MODULE_SRC_MMLC); + $files = $module->getSrcMmlcFilePaths(); + $root = $module->getLocalRootPath() . $module->getSrcMmlcRootPath() . '/'; + return $this->fileHasher->createHashes($files, $root, self::SCOPE_MODULE_SRC_MMLC); } /** - * /... + * /...//... */ public function createShopRootHashes(Module $module): HashEntryCollection { $files = $module->getSrcFilePaths(); $root = App::getShopRoot(); - $files = ModulePathMapper::mmlcPathsToShopPaths($files); - //$files = ModulePathMapper::srcPathsToShopPaths($files); + $files = ModulePathMapper::allModuleSrcToShopRoot($files); return $this->fileHasher->createHashes($files, $root, self::SCOPE_SHOP_ROOT); } /** - * /vendor-mmlc///... + * /...//vendor-mmlc///... */ public function createShopVendorMmlcHashes(Module $module): HashEntryCollection { - return new HashEntryCollection([]); - - // TODO: Warte auf feat/vendor-mmlc - // $files = $module->getSrcMmlcFilePaths(); - // $root = App::getShopRoot(); - // $files = ModulePathMapper::srcMmlcPathsToVendorMmlcPaths($files); - // return $this->fileHasher->createHashes($files, $root, self::SCOPE_SHOP_VENDOR_MMLC); + $files = $module->getSrcMmlcFilePaths(); + $root = App::getShopRoot() . '/' . ModulePathMapper::moduleSrcMmlcToShopVendorMmlc('/', $module->getArchiveName()); + return $this->fileHasher->createHashes($files, $root, self::SCOPE_SHOP_VENDOR_MMLC); } } diff --git a/src/Classes/ModuleInfo.php b/src/Classes/ModuleInfo.php index 8ba796fa..064e5b07 100644 --- a/src/Classes/ModuleInfo.php +++ b/src/Classes/ModuleInfo.php @@ -39,12 +39,22 @@ class ModuleInfo * Das Verzeichnis, in dem sich die Quellcode Dateien des Moduls befinden, * die in den Shop kopiert/verlinkt werden sollen. * - * Beispiel: new_fieles + * Beispiel: src * * @var string */ protected $sourceDir; + /** + * Das Verzeichnis, in dem sich die Quellcode Dateien des Moduls befinden, + * die in den Shop kopiert/verlinkt werden sollen. + * + * Beispiel: src-mmlc + * + * @var string + */ + protected $sourceMmlcDir; + /** * Die Version des Moduls. Die Version muss der Sermver konvention folgen. * Der Wert darf auch 'auto' sein. In diesem Fall wird versucht, sich die @@ -195,6 +205,16 @@ public function setSourceDir(string $value): void $this->sourceDir = $value; } + public function getSourceMmlcDir(): string + { + return $this->sourceMmlcDir; + } + + public function setSourceMmlcDir(string $value): void + { + $this->sourceMmlcDir = $value; + } + public function getVersion(): string { return $this->version; diff --git a/src/Classes/ModuleInstaller.php b/src/Classes/ModuleInstaller.php index 7a650e78..d8724dd6 100644 --- a/src/Classes/ModuleInstaller.php +++ b/src/Classes/ModuleInstaller.php @@ -88,6 +88,7 @@ public function install(Module $module, $force = false): void $dependencyManager->canBeInstalled($module); } + // Install Source Files to Shop Root $files = $module->getSrcFilePaths(); foreach ($files as $file) { @@ -100,13 +101,22 @@ public function install(Module $module, $force = false): void $overwrite = true; } - $file = ModulePathMapper::mmlcToShop($file); + $file = ModulePathMapper::moduleSrcToShopRoot($file); $dest = App::getShopRoot() . $file; $this->installFile($src, $dest, $overwrite); } } + // Install Source Mmlc Files to shop vendor-mmlc + $files = $module->getSrcMmlcFilePaths(); + foreach ($files as $file) { + $src = $module->getLocalRootPath() . $module->getSrcMmlcRootPath() . '/' . $file; + $file = ModulePathMapper::moduleSrcMmlcToShopVendorMmlc($file, $module->getArchiveName()); + $dest = App::getShopRoot() . '/' . $file; + $this->installFile($src, $dest, true); + } + $moduleHashFileCreator = new ModuleHashFileCreator(); $moduleHashFile = $moduleHashFileCreator->createHashFile($module); $moduleHashFile->writeTo($module->getHashPath()); @@ -174,6 +184,7 @@ public function createAutoloadFile(): void } foreach ($autoload['psr-4'] as $namespace => $path) { + $path = str_replace($module->getSourceMmlcDir(), 'vendor-mmlc/' . $module->getArchiveName(), $path); $namespaceEntrys[] = '$loader->setPsr4(\'' . $namespace . '\\\', DIR_FS_DOCUMENT_ROOT . \'' . $path . '\');'; } @@ -185,8 +196,15 @@ public function createAutoloadFile(): void $template = \file_get_contents(App::getTemplatesRoot() . '/autoload.php.tmpl'); $template = \str_replace('{VENDOR_PSR4_NAMESPACE_MAPPINGS}', $namespaceMapping, $template); - @mkdir(App::getShopRoot() . '/vendor-no-composer'); + if (!file_exists(App::getShopRoot() . '/vendor-no-composer')) { + mkdir(App::getShopRoot() . '/vendor-no-composer'); + } \file_put_contents(App::getShopRoot() . '/vendor-no-composer/autoload.php', $template); + + if (!file_exists(App::getShopRoot() . '/vendor-mmlc')) { + mkdir(App::getShopRoot() . '/vendor-mmlc'); + } + \file_put_contents(App::getShopRoot() . '/vendor-mmlc/autoload.php', $template); } //TODO: Better return void type an thorw exception at error @@ -201,12 +219,21 @@ public function uninstall(?Module $module): bool return false; } + // Uninstall from shop-root $files = $module->getSrcFilePaths(); + foreach ($files as $file) { + $file = ModulePathMapper::moduleSrcToShopRoot($file); + $dest = App::getShopRoot() . $file; + $this->uninstallFile($dest); + } + // Uninstall from shop-vendor-mmlc + $files = $module->getSrcMmlcFilePaths(); foreach ($files as $file) { - $file = ModulePathMapper::mmlcToShop($file); + $file = ModulePathMapper::moduleSrcMmlcToShopVendorMmlc($file, $module->getArchiveName()); $dest = App::getShopRoot() . $file; $this->uninstallFile($dest); + FileHelper::deletePathIsEmpty($dest); } if (file_exists($module->getHashPath())) { diff --git a/src/Classes/ModulePathMapper.php b/src/Classes/ModulePathMapper.php index 451436fb..15b6845d 100644 --- a/src/Classes/ModulePathMapper.php +++ b/src/Classes/ModulePathMapper.php @@ -18,8 +18,17 @@ class ModulePathMapper { private const DEFAULT_ADMIN_DIR = 'admin'; + private const DEFAULT_SHOP_VENDOR_MMLC_DIR = 'vendor-mmlc'; - public static function mmlcToShop(string $mmlcPath): string + /** + * FromBase: Modules//src + * From: /... + * ToBase: + * To: /... + * + * Its converts the name of the admin dir too. + */ + public static function moduleSrcToShopRoot(string $mmlcPath): string { $adminDir = ShopInfo::getAdminDir(); // Replace string that starts with "/DEFAULT_ADMIN_DIR/" @@ -27,7 +36,15 @@ public static function mmlcToShop(string $mmlcPath): string return $shopPath; } - public static function shopToMmlc(string $shopPath): string + /** + * FromBase: + * From: /... + * ToBase: Modules//src + * To: /... + * + * Its converts the name of the admin dir too. + */ + public static function shopRootToModuleSrc(string $shopPath): string { $adminDir = ShopInfo::getAdminDir(); // Replace string that starts with "/$adminDir/" @@ -36,33 +53,85 @@ public static function shopToMmlc(string $shopPath): string } /** - * Converts multible mmlc-paths to shop-paths. For example this method + * FromBase: Modules//src-mmlc + * From: /... + * ToBase: + * To: /vendor-mmlc//... + */ + public static function moduleSrcMmlcToShopVendorMmlc(string $path, string $archiveName): string + { + return '/' . self::DEFAULT_SHOP_VENDOR_MMLC_DIR . '/' . $archiveName . '/' . $path; + } + + /** + * FromBase: + * From: /vendor-mmlc//... + * ToBase: Modules//src-mmlc + * To: /... + */ + public static function shopVendorMmlcToModuleSrcMmlc(string $vendorMmlcPath, string $archiveName): string + { + $string = '/' . self::DEFAULT_SHOP_VENDOR_MMLC_DIR . '/' . $archiveName . '/'; + $replace = str_replace('/', '\/', $string); + $srcMmlcPath = preg_replace('/^' . $replace . '/', '/', $vendorMmlcPath); + return $srcMmlcPath; + } + + /** + * Map multible + * + * FromBase: Modules//src-mmlc + * From: /... + * ToBase: + * To: /vendor-mmlc//... + */ + public static function allModuleSrcMmlcToShopVendorMmlc(array $paths, string $archiveName): array + { + $resultPaths = []; + foreach ($paths as $path) { + $resultPaths[] = self::moduleSrcMmlcToShopVendorMmlc($path, $archiveName); + } + return $resultPaths; + } + + /** + * Converts multible module src paths to shop root . For example this method * renames all custome admin-directory-names like admin to admin_123456. * + * FromBase: Modules//src + * From: /... + * ToBase: + * To: /... + * * @param string[] $shopPaths A Array of path in shop-path-scope * @return string[] Returns a array of mapped strings */ - public static function mmlcPathsToShopPaths(array $mmlcPaths): array + public static function allModuleSrcToShopRoot(array $mmlcPaths): array { $shopPaths = []; foreach ($mmlcPaths as $path) { - $shopPaths[] = self::mmlcToShop($path); + $shopPaths[] = self::moduleSrcToShopRoot($path); } return $shopPaths; } /** - * Converts multible shop-paths to mmlc-paths. For example this method + * Converts multible shop root paths to module src paths. For example this method * renames all custome admin-directory-names like admin_123456 to admin. * + * FromBase: + * From: /... + * ToBase: Modules//src + * To: /... + * * @param string[] $shopPaths A Array of path in shop-path-scope * @return string[] Returns a array of mapped strings */ - public static function shopPathsToMmlcPaths(array $shopPaths): array + public static function allShopRootToModuleSrc(array $shopPaths): array { $mmlcPaths = []; foreach ($shopPaths as $path) { - $mmlcPaths[] = self::mmlcToShop($path); + $mmlcPaths[] = self::moduleSrcToShopRoot($path); } return $mmlcPaths; } diff --git a/src/Templates/ModuleInfo.tmpl.php b/src/Templates/ModuleInfo.tmpl.php index fa3c827d..04d3e7b0 100644 --- a/src/Templates/ModuleInfo.tmpl.php +++ b/src/Templates/ModuleInfo.tmpl.php @@ -5,6 +5,7 @@ use RobinTheHood\ModifiedModuleLoaderClient\LazyLoader; use RobinTheHood\ModifiedModuleLoaderClient\ShopInfo; use RobinTheHood\ModifiedModuleLoaderClient\Config; +use RobinTheHood\ModifiedModuleLoaderClient\FileHasher\ChangedEntry; use RobinTheHood\ModifiedModuleLoaderClient\ModuleChangeManager; use RobinTheHood\ModifiedModuleLoaderClient\ViewModels\NotificationViewModel; use RobinTheHood\ModifiedModuleLoaderClient\ViewModels\ModuleViewModel; @@ -366,7 +367,7 @@ isInstalled() && $moduleView->isChanged()) { ?> getChancedFiles()->changedEntries as $changedEntry) { ?> -
hashEntryA->file ?>: type ?>
+
(hashEntryA->scope ?>) hashEntryA->file ?>: type) ?>
diff --git a/src/Templates/autoload.php.tmpl b/src/Templates/autoload.php.tmpl index b7ff36d7..ba1309c6 100644 --- a/src/Templates/autoload.php.tmpl +++ b/src/Templates/autoload.php.tmpl @@ -1,5 +1,10 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace RobinTheHood\ModifiedModuleLoaderClient\Tests\Unit\ModuleHahserTests; + +use PHPUnit\Framework\TestCase; + +class ModulePathMapperTest +{ + public function testmoduleSrcToShopRoot() + { + // TODO: write test + } + + public function testshopRootToModuleSrc() + { + // TODO: write test + } + + public function testmoduleSrcMmlcToShopVendorMmlc() + { + // TODO: write test + } + + public function testshopVendorMmlcToModuleSrcMmlc() + { + // TODO: write test + } + + public function testallModuleSrcMmlcToShopVendorMmlc() + { + // TODO: write test + } + + public function testallModuleSrcToShopRoot() + { + // TODO: write test + } + + public function testallShopRootToModuleSrc() + { + // TODO: write test + } +}