/** * Creates a new module. * * @param ModuleFile|null $moduleFile The module file or `null` if the * module file could not be loaded. * @param string $installPath The absolute install path. * @param InstallInfo|null $installInfo The install info of this module. * @param Exception[] $loadErrors The errors that happened during * loading of the module, if any. */ public function __construct(ModuleFile $moduleFile = null, $installPath, InstallInfo $installInfo = null, array $loadErrors = array()) { Assert::absoluteSystemPath($installPath); Assert::allIsInstanceOf($loadErrors, 'Exception'); // If a module name was set during installation, that name wins over // the predefined name in the puli.json file (if any) $this->name = $installInfo && null !== $installInfo->getModuleName() ? $installInfo->getModuleName() : ($moduleFile ? $moduleFile->getModuleName() : null); if (null === $this->name) { $this->name = $this->getDefaultName(); } // The path is stored both here and in the install info. While the // install info contains the path as it is stored in the install file // (i.e. relative or absolute), the install path of the module is // always an absolute path. $this->installPath = $installPath; $this->installInfo = $installInfo; $this->moduleFile = $moduleFile; $this->loadErrors = $loadErrors; if (!file_exists($installPath)) { $this->state = ModuleState::NOT_FOUND; } elseif (count($loadErrors) > 0) { $this->state = ModuleState::NOT_LOADABLE; } else { $this->state = ModuleState::ENABLED; } }
/** * Adds install info for an installed module. * * @param InstallInfo $installInfo The install info. */ public function addInstallInfo(InstallInfo $installInfo) { $this->installInfos[$installInfo->getModuleName()] = $installInfo; }
/** * {@inheritdoc} */ public function rollback() { if (!$this->wasDisabled) { $this->installInfo->removeDisabledBindingUuid($this->uuid); } }
private function renameNonRootModule(Module $module, $newName) { $previousInstallInfo = $module->getInstallInfo(); $installInfo = new InstallInfo($newName, $previousInstallInfo->getInstallPath()); $installInfo->setInstallerName($previousInstallInfo->getInstallerName()); foreach ($previousInstallInfo->getDisabledBindingUuids() as $uuid) { $installInfo->addDisabledBindingUuid($uuid); } $this->rootModuleFile->removeInstallInfo($module->getName()); $this->rootModuleFile->addInstallInfo($installInfo); try { $this->moduleFileStorage->saveRootModuleFile($this->rootModuleFile); } catch (Exception $e) { $this->rootModuleFile->removeInstallInfo($newName); $this->rootModuleFile->addInstallInfo($previousInstallInfo); throw $e; } $this->modules->remove($module->getName()); $this->modules->add(new Module($module->getModuleFile(), $module->getInstallPath(), $installInfo, $module->getLoadErrors())); }
protected function addJsonToRootModuleFile(stdClass $jsonData, RootModuleFile $moduleFile) { if (isset($jsonData->order)) { $moduleFile->setModuleOrder((array) $jsonData->order); } if (isset($jsonData->plugins)) { $moduleFile->setPluginClasses($jsonData->plugins); } if (isset($jsonData->config)) { $config = $moduleFile->getConfig(); foreach ($this->objectsToArrays($jsonData->config) as $key => $value) { $config->set($key, $value); } } if (isset($jsonData->modules)) { foreach ($jsonData->modules as $moduleName => $moduleData) { $installInfo = new InstallInfo($moduleName, $moduleData->{'install-path'}); if (isset($moduleData->env)) { $installInfo->setEnvironment($moduleData->env); } if (isset($moduleData->installer)) { $installInfo->setInstallerName($moduleData->installer); } if (isset($moduleData->{'disabled-bindings'})) { foreach ($moduleData->{'disabled-bindings'} as $uuid) { $installInfo->addDisabledBindingUuid(Uuid::fromString($uuid)); } } $moduleFile->addInstallInfo($installInfo); } } }