$success = false; } if ($success) { echo "Success! Identifier: {$ret->getIdentifier()}\n"; } else { echo "Failure...\n"; } unset($ret); echo " Add To Module Identity Path (path5, subModule4) -- \n"; $success = true; $granchild2 = null; try { echo " Instantiate subModule4 -> "; $grandchild2 = new Loader\Module('path/to/last/module', 'subModule4'); echo "Success!\n"; echo " Add to Path (firstModule/subModule2) -> "; Loader\Module::addToModuleIdentityPath($top, 'firstModule/subModule2', $grandchild2, $grandchild2->getIdentifier()); } catch (\Exception $e) { $success = false; } if ($success) { echo "Success!\n\n"; } else { echo "Failure...\n\n"; } $paths = Loader\Module::getModuleIdentityPaths($top); echo "Identity Paths: \n"; foreach ($paths as $path) { echo " {$path}\n"; } echo "\n";
/** * Removes Module identifier ONLY if it's a terminating leaf * * This removes a Module identifier (not path) only if the Module * is the last Module in a given path from the root leaf * * @param string $module The Module identifier * @param string|Falcraft\Data\Components\File\Resource\DirectoryInterface * $library The library to start at, defaults to internal library * * @return boolean True on succcess * */ public function removeLibraryModule($module, $library = '') { if ($library instanceof ModuleInterface) { $haystack = Loader\Module::getModuleIdentityPaths($library); } else { if (is_string($library)) { $library = $haystack = Loader\Module::getFromModuleIdentityPath($library); if (!$haystack instanceof Types\Null) { $haystack = Loader\Module::getModuleIdentityPaths($haystack); } else { return false; } } else { $haystack = Loader\Module::getModuleIdentityPaths($this->libraries); $library = $this->libraries; } } if ($haystack instanceof Types\Null) { return false; } $path = ''; foreach ($haystack as $needle) { $needleParts = explode('/', $needle); if ($needleParts[count($needleParts) - 1] == $module) { $path = $needle; } } if ($path) { $module = Loader\Module::getFromModuleIdentityPath($library, $path); $path = explode('/', $path); $path = array_pop($path); $module->removeModule($path); return true; } return false; }