private static function visit(&$ordering, &$tempMarked, $nodes, $curNode)
 {
     // if $curNode is not in $nodes then it is not a package we care about.
     if (!isset($nodes[$curNode])) {
         $tempMarked[$curNode] = false;
         return;
     }
     if (isset($tempMarked[$curNode]) && $tempMarked[$curNode]) {
         throw new \UnexpectedValueException('Cycle in the dependencies of the project');
     }
     if (!isset($tempMarked[$curNode])) {
         $tempMarked[$curNode] = true;
         foreach ($nodes[$curNode] as $node) {
             TopologicalSort::visit($ordering, $tempMarked, $nodes, $node);
         }
         $tempMarked[$curNode] = false;
         $ordering[] = $curNode;
     }
 }
Exemple #2
0
 /**
  * Gets an ordered list of parameters to process.
  * 
  * @since 0.4
  * 
  * @param array $initialParamSet
  * @param array $resultingParamSet
  */
 protected function getParamsToProcess(array $initialParamSet, array $resultingParamSet)
 {
     if ($initialParamSet === array()) {
         $this->paramsToHandle = array_keys($resultingParamSet);
     } else {
         if (!is_array($this->paramsToHandle)) {
             $this->paramsToHandle = array();
         }
         foreach ($resultingParamSet as $paramName => $parameter) {
             if (!array_key_exists($paramName, $initialParamSet)) {
                 $this->paramsToHandle[] = $paramName;
             }
         }
     }
     $dependencyList = array();
     // Loop over the parameters to handle to create a dependency list.
     foreach ($this->paramsToHandle as $paramName) {
         $dependencies = array();
         // Only include dependencies that are in the list of parameters to handle.
         foreach ($this->paramDefinitions[$paramName]->getDependencies() as $dependency) {
             if (in_array($dependency, $this->paramsToHandle)) {
                 $dependencies[] = $dependency;
             }
         }
         $dependencyList[$paramName] = $dependencies;
     }
     $sorter = new TopologicalSort($dependencyList, true);
     $this->paramsToHandle = $sorter->doSort();
 }
Exemple #3
0
 /**
  * Gets an ordered list of parameters to process.
  * 
  * @since 0.4
  * 
  * @param array $initialParamSet
  * @param array $resultingParamSet
  *
  * @throws \UnexpectedValueException
  */
 private function getParamsToProcess(array $initialParamSet, array $resultingParamSet)
 {
     if ($initialParamSet === array()) {
         $this->paramsToHandle = array_keys($resultingParamSet);
     } else {
         if (!is_array($this->paramsToHandle)) {
             $this->paramsToHandle = array();
         }
         foreach ($resultingParamSet as $paramName => $parameter) {
             if (!array_key_exists($paramName, $initialParamSet)) {
                 $this->paramsToHandle[] = $paramName;
             }
         }
     }
     $dependencyList = array();
     // Loop over the parameters to handle to create a dependency list.
     foreach ($this->paramsToHandle as $paramName) {
         $dependencies = array();
         if (!array_key_exists($paramName, $this->paramDefinitions)) {
             throw new \UnexpectedValueException('Unexpected parameter name "' . $paramName . '"');
         }
         if (!is_object($this->paramDefinitions[$paramName]) || !$this->paramDefinitions[$paramName] instanceof IParamDefinition) {
             throw new \UnexpectedValueException('Parameter "' . $paramName . '" is not a IParamDefinition');
         }
         // Only include dependencies that are in the list of parameters to handle.
         foreach ($this->paramDefinitions[$paramName]->getDependencies() as $dependency) {
             if (in_array($dependency, $this->paramsToHandle)) {
                 $dependencies[] = $dependency;
             }
         }
         $dependencyList[$paramName] = $dependencies;
     }
     $sorter = new TopologicalSort($dependencyList, true);
     $this->paramsToHandle = $sorter->doSort();
 }