/**
  * Adds a module to the collection.
  *
  * @param Module $module The added module.
  */
 public function add(Module $module)
 {
     $this->modules[$module->getName()] = $module;
     if ($module instanceof RootModule) {
         $this->rootModule = $module;
     }
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function rollback()
 {
     if (!$this->mapping->isLoaded()) {
         return;
     }
     $moduleName = $this->containingModule->getName();
     $this->mappings->remove($this->mapping->getRepositoryPath(), $moduleName);
     foreach ($this->mapping->listRepositoryPaths() as $repositoryPath) {
         $this->mappingsByResource->remove($repositoryPath, $moduleName);
         $this->conflictDetector->release($repositoryPath, $moduleName);
     }
     // Unload after iterating, otherwise the paths are gone
     $this->mapping->unload();
 }
 /**
  * {@inheritdoc}
  */
 public function rollback()
 {
     // sanity check
     if (!$this->typeDescriptor->isLoaded()) {
         return;
     }
     $typeName = $this->typeDescriptor->getTypeName();
     // never fails with the check before
     $this->typeDescriptor->unload();
     if ($this->previousDescriptor && $this->previousDescriptor->isLoaded()) {
         // never fails
         $this->typeDescriptors->add($this->previousDescriptor);
     } else {
         // never fails
         $this->typeDescriptors->remove($typeName, $this->containingModule->getName());
     }
 }
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     // sanity check
     if (!$this->typeDescriptor->isLoaded()) {
         return;
     }
     // never fails with the check before
     $this->containingModule = $this->typeDescriptor->getContainingModule();
     $typeName = $this->typeDescriptor->getTypeName();
     $moduleName = $this->containingModule->getName();
     // never fails with the check before
     $this->typeDescriptor->unload();
     if ($this->typeDescriptors->contains($typeName, $moduleName) && $this->typeDescriptor === $this->typeDescriptors->get($typeName, $moduleName)) {
         // never fails
         $this->typeDescriptors->remove($typeName, $moduleName);
         $this->wasRemoved = true;
     }
 }
 private function refreshState()
 {
     if (null === $this->typeDescriptor || !$this->typeDescriptor->isLoaded()) {
         $this->state = BindingState::TYPE_NOT_FOUND;
     } elseif (!$this->typeDescriptor->isEnabled()) {
         $this->state = BindingState::TYPE_NOT_ENABLED;
     } elseif (count($this->loadErrors) > 0) {
         $this->state = BindingState::INVALID;
     } elseif ($this->containingModule instanceof RootModule) {
         $this->state = BindingState::ENABLED;
     } elseif ($this->containingModule->getInstallInfo()->hasDisabledBindingUuid($this->binding->getUuid())) {
         $this->state = BindingState::DISABLED;
     } else {
         $this->state = BindingState::ENABLED;
     }
 }
Beispiel #6
0
 /**
  * {@inheritdoc}
  */
 public function rollback()
 {
     if ($this->mapping->isLoaded() || !$this->containingModule) {
         return;
     }
     $this->mapping->load($this->containingModule, $this->modules);
     $moduleName = $this->containingModule->getName();
     foreach ($this->mapping->listRepositoryPaths() as $repositoryPath) {
         $this->mappings->add($this->mapping);
         $this->conflictDetector->claim($repositoryPath, $moduleName);
     }
     // Restore conflicts
     foreach ($this->conflicts as $repositoryPath => $conflict) {
         $conflict->addMappings($this->conflictingMappings[$repositoryPath]);
     }
 }
 private function loadInstallers(Module $module)
 {
     foreach (self::$builtinInstallers as $name => $installerData) {
         $installer = $this->dataToInstaller($name, (object) $installerData);
         $this->installerDescriptors[$name] = $installer;
     }
     $moduleFile = $module->getModuleFile();
     if (null === $moduleFile) {
         return;
     }
     $moduleName = $module->getName();
     $installersData = $moduleFile->getExtraKey(self::INSTALLERS_KEY);
     if (!$installersData) {
         return;
     }
     $jsonValidator = new JsonValidator();
     $errors = $jsonValidator->validate($installersData, __DIR__ . '/../../res/schema/installers-schema-1.0.json');
     if (count($errors) > 0) {
         throw new ValidationFailedException(sprintf("The extra key \"%s\" of module \"%s\" is invalid:\n%s", self::INSTALLERS_KEY, $moduleName, implode("\n", $errors)));
     }
     foreach ($installersData as $name => $installerData) {
         $installer = $this->dataToInstaller($name, $installerData);
         $this->installerDescriptors[$name] = $installer;
         if ($module instanceof RootModule) {
             $this->rootInstallerDescriptors[$name] = $installer;
         }
     }
 }
Beispiel #8
0
 private function assertFileExists($absolutePath, $relativePath, Module $containingModule)
 {
     if (!file_exists($absolutePath)) {
         throw new FileNotFoundException(sprintf('The path %s mapped to %s by module "%s" does not exist.', $relativePath, $this->repositoryPath, $containingModule->getName()));
     }
 }
 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()));
 }