public function loadConfiguration(&$configuration, $path = null, $iterativeScope = null) { if (!is_array($configuration)) { $configuration = (array) $configuration; } if (!empty($configuration)) { LogCLI::MessageResult("Mapping configuration to: " . LogCLI::BLUE . "{$path}" . LogCLI::RESET, LogCLI::INFO); $this->configuration = empty($path) ? $configuration : ArrayTools::accessArrayElementByPath($configuration, $path); /* if(!empty($iterativeScope) && !ArrayTools::isIterativeScope($this->configuration)) { LogCLI::MessageResult('Non-iterative format, translating...', LogCLI::INFO); $this->configuration = ArrayTools::translateToIterativeScope($iterativeScope, $this->configuration); } */ if (!empty($this->foreignSettings)) { foreach ($this->foreignSettings as $foreignSetting) { $foreignPath = StringTools::DropLastBit($path, $foreignSetting[0]); //.'/'.$foreignSetting[1] $foreignValue = ArrayTools::accessArrayElementByPath($configuration, $foreignPath . '/' . $foreignSetting[1]); $this->configuration[$foreignSetting[2]] = $foreignValue; } } return $this->configuration; } return false; //return $this->configuration = self::makeConfiguration(&$configuration, $path, $iterativeScope); }
public static function findPathForSetting(&$settings, $settingPath, $basicScope = false) { $searchResults = ArrayTools::TraverseTreeWithPath($settings, $settingPath); if (empty($searchResults)) { LogCLI::MessageResult(LogCLI::YELLOW . 'Sorry, no settings found for: ' . LogCLI::BLUE . $settingPath . LogCLI::RESET, 0, LogCLI::INFO); return false; } else { if (count($searchResults['all']) > 1) { LogCLI::MessageResult(LogCLI::YELLOW . 'Multiple settings found for: ' . LogCLI::BLUE . $settingPath . LogCLI::RESET, 4, LogCLI::INFO); } LogCLI::MessageResult(LogCLI::GREEN . 'Best match: ' . LogCLI::BLUE . $searchResults['best'] . LogCLI::RESET, 0, LogCLI::INFO); $path = $searchResults['best']; if ($basicScope !== false) { if (($pos = strpos($path, $basicScope)) !== false && $pos === 0) { $path = StringTools::DropLastBit($path, -1); } } $parent = ArrayTools::accessArrayElementByPath($settings, StringTools::DropLastBit($searchResults['best'])); if (isset($parent['iterative'])) { $path = StringTools::DropLastBit($path, -1); } LogCLI::MessageResult('Fixed path: ' . LogCLI::YELLOW . $searchResults['best'] . ' => ' . LogCLI::BLUE . $path . LogCLI::RESET, 6, LogCLI::INFO); return $path; } }