/** * 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(); }
/** * 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(); }