예제 #1
0
파일: Solver.php 프로젝트: svobodni/web
 /**
  * @param IModule $module
  * @param Problem $problem
  * @throws InvalidArgumentException
  */
 public function testUpgrade(IModule $module, Problem $problem = NULL)
 {
     $installedModules =& $this->installedModules;
     $modules =& $this->modules;
     foreach ($module->getRequire() as $name => $require) {
         $requires = VersionHelpers::normalizeRequire($require);
         if (!isset($installedModules[$name])) {
             if ($problem && isset($modules[$name])) {
                 try {
                     $solver = $this->createSolver();
                     $solver->testInstall($modules[$name], $problem);
                 } catch (InvalidArgumentException $e) {
                     throw new InvalidArgumentException("Module '{$module->getName()}' depend on '{$name}' which is not installed.");
                 }
                 $job = new Job(Job::ACTION_INSTALL, $modules[$name]);
                 if (!$problem->hasSolution($job)) {
                     $problem->addSolution($job);
                 }
                 $installedModules[$name] = $modules[$name];
                 $tr = array($this->libsDir => '%libsDir%', $this->modulesDir => '%modulesDir%');
                 $this->modulesConfig[$name] = array(ModuleManager::MODULE_STATUS => ModuleManager::STATUS_INSTALLED, ModuleManager::MODULE_ACTION => ModuleManager::ACTION_NONE, ModuleManager::MODULE_CLASS => $module->getClassName(), ModuleManager::MODULE_VERSION => $module->getVersion(), ModuleManager::MODULE_PATH => str_replace(array_keys($tr), array_merge($tr), $module->getPath()), ModuleManager::MODULE_AUTOLOAD => str_replace(array_keys($tr), array_merge($tr), $module->getAutoload()), ModuleManager::MODULE_REQUIRE => $module->getRequire());
             } else {
                 throw new InvalidArgumentException("Module '{$module->getName()}' depend on '{$name}' which is not installed.");
             }
         }
         foreach ($requires as $items) {
             foreach ($items as $operator => $version) {
                 $dVersion = $this->modulesConfig[$name][ModuleManager::MODULE_VERSION];
                 if (!version_compare($dVersion, $version, $operator)) {
                     if (!version_compare($installedModules[$name]->getVersion(), $version, $operator)) {
                         throw new InvalidArgumentException("Module '{$module->getName()}' depend on '{$name}' with version '{$require}'. Current version is '{$dVersion}'.");
                     }
                     // dependency must be upgraded
                     if ($problem && isset($modules[$name])) {
                         try {
                             $solver = $this->createSolver();
                             $solver->testUpgrade($modules[$name], $problem);
                         } catch (InvalidArgumentException $e) {
                             throw new InvalidArgumentException("Module '{$module->getName()}' depend on '{$name}' with version '{$require}'. Current version is '{$dVersion}'.");
                         }
                         $job = new Job(Job::ACTION_UPGRADE, $modules[$name]);
                         if (!$problem->hasSolution($job)) {
                             $problem->addSolution($job);
                         }
                         $this->modulesConfig[$name][ModuleManager::MODULE_VERSION] = $modules[$name]->getVersion();
                     } else {
                         throw new InvalidArgumentException("Module '{$module->getName()}' depend on '{$name}' with version '{$require}'. Current version is '{$dVersion}'.");
                     }
                 }
             }
         }
     }
 }
예제 #2
0
 /**
  * @param IModules[] $modules
  * @param IModule $module
  * @throws InvalidArgumentException
  */
 public function matchModulesWithModule($modules, IModule $module)
 {
     foreach ($modules as $sourceModule) {
         foreach ($sourceModule->getRequire() as $name => $require) {
             if ($name !== $module->getName()) {
                 continue;
             }
             $requires = VersionHelpers::normalizeRequire($require);
             foreach ($requires as $items) {
                 foreach ($items as $operator => $version) {
                     if (!version_compare($module->getVersion(), $version, $operator)) {
                         throw new InvalidArgumentException("Module '{$sourceModule->getName()}' depend on '{$module->getName()}' with version '{$require}'. Current version is '{$module->getVersion()}'.");
                     }
                 }
             }
         }
     }
 }