Beispiel #1
0
 protected function applyDefaults(array &$setting, array &$defaultsDefinitions, $path, $nameOfObjectToApply = 'defaults', $directDefinition = false, $applyToAll = false)
 {
     if ($applyToAll === false) {
         $child = StringTools::ReturnLastBit($path);
         $parent = StringTools::DropLastBit($path);
     } else {
         $parent = $path;
     }
     $parentConfig = ArrayTools::accessArrayElementByPath($setting, $parent);
     if ($directDefinition === false) {
         $thisDefault = ArrayTools::accessArrayElementByPath($defaultsDefinitions, $parent);
     } else {
         $thisDefault =& $defaultsDefinitions;
     }
     if ($nameOfObjectToApply === null) {
         $defaults =& $thisDefault;
     } elseif (!isset($thisDefault[$nameOfObjectToApply])) {
         return false;
     } else {
         $defaults = $thisDefault[$nameOfObjectToApply];
     }
     //var_dump($thisDefault);
     if ($applyToAll === false) {
         $config =& $parentConfig[$child];
         if (is_numeric($child)) {
             LogCLI::MessageResult('Applying defaults to object ' . LogCLI::GREEN . $parent . '/' . LogCLI::YELLOW . $child . LogCLI::RESET, 6, LogCLI::INFO);
             // this will not override any configs, only merge in the ones that were not set
             $config = ArrayTools::MergeArrays($defaults, $config);
         }
     } else {
         foreach ($parentConfig as $child => &$config) {
             if (is_numeric($child)) {
                 LogCLI::MessageResult('Applying defaults to object ' . LogCLI::GREEN . $parent . '/' . LogCLI::YELLOW . $child . LogCLI::RESET, 6, LogCLI::INFO);
                 // this will not override any configs, only merge in the ones that were not set
                 $config = ArrayTools::MergeArrays($defaults, $config);
             }
         }
     }
     // finally replace the array element
     ArrayTools::replaceArrayElementByPath($this->DB, $parent, $parentConfig);
 }