示例#1
0
 /**
  * Expand modules dependencies from chain
  *
  * @param string $vertex
  * @param array $path nesting path
  * @return void
  */
 protected function expandDependencies($vertex, $path = [])
 {
     if (!$this->dependencies[$vertex]) {
         return;
     }
     $path[] = $vertex;
     foreach ($this->dependencies[$vertex] as $dependency) {
         if (!isset($this->dependencies[$dependency])) {
             // dependency vertex is not described in basic definition
             continue;
         }
         $relations = $this->graph->getRelations();
         if (isset($relations[$vertex][$dependency])) {
             continue;
         }
         $this->graph->addRelation($vertex, $dependency);
         $searchResult = array_search($dependency, $path);
         if (false !== $searchResult) {
             $this->buildCircular(array_slice($path, $searchResult));
             break;
         } else {
             $this->expandDependencies($dependency, $path);
         }
     }
 }
 /**
  * Check the dependency graph
  *
  * @param bool $isEnable
  * @param string[] $moduleNames list of modules to be enabled/disabled
  * @param string[] $enabledModules list of enabled modules assuming enable/disable succeeds
  * @return array
  */
 private function checkDependencyGraph($isEnable, $moduleNames, $enabledModules)
 {
     $dependenciesMissingAll = [];
     $graphMode = $isEnable ? Graph::DIRECTIONAL : Graph::INVERSE;
     foreach ($moduleNames as $moduleName) {
         $dependenciesMissing = [];
         $paths = $this->graph->findPathsToReachableNodes($moduleName, $graphMode);
         foreach (array_keys($this->fullModuleList) as $module) {
             if (isset($paths[$module])) {
                 if ($isEnable && !in_array($module, $enabledModules)) {
                     $dependenciesMissing[$module] = $paths[$module];
                 } else {
                     if (!$isEnable && in_array($module, $enabledModules)) {
                         $dependenciesMissing[$module] = array_reverse($paths[$module]);
                     }
                 }
             }
         }
         $dependenciesMissingAll[$moduleName] = $dependenciesMissing;
     }
     return $dependenciesMissingAll;
 }