function MergeArrays($Arr1, $Arr2) { foreach ($Arr2 as $key => $Value) { if (array_key_exists($key, $Arr1) && is_array($Value) && is_array($Arr1[$key])) { $Arr1[$key] = MergeArrays($Arr1[$key], $Arr2[$key]); } else { $Arr1[$key] = $Value; } } return $Arr1; }
/** * Merge two associative arrays into a single array. * * @param array The "dominant" array, who's values will be chosen over those of the subservient. * @param array The "subservient" array, who's values will be disregarded over those of the dominant. */ function MergeArrays(&$Dominant, $Subservient) { foreach ($Subservient as $Key => $Value) { if (!array_key_exists($Key, $Dominant)) { // Add the key from the subservient array if it doesn't exist in the // dominant array. $Dominant[$Key] = $Value; } else { // If the key already exists in the dominant array, only continue if // both values are also arrays - because we don't want to overwrite // values in the dominant array with ones from the subservient array. if (is_array($Dominant[$Key]) && is_array($Value)) { $Dominant[$Key] = MergeArrays($Dominant[$Key], $Value); } } } return $Dominant; }
/** * Assign the statistics values of a data center to the overall statistics * $dcStats * * @param array $dcStats * @param DataCenter $dc * @param array $Stats */ function assignStatsVal(&$dcStats, $dc, $Stats) { $arr = array(); $tmp =& $arr; $dcContainerList = $dc->getContainerList(); $dcContainerList[] = $dc->Name; foreach ($dcContainerList as $level) { $tmp[$level] = array(); $tmp =& $tmp[$level]; } $tmp = $Stats; // $dcStats = array_merge_recursive($dcStats, $arr); $dcStats = MergeArrays($dcStats, $arr); }
/** * Takes a set of form data ($Form->_PostValues), validates them, and * inserts or updates them to the configuration file. * * @param array $FormPostValues An associative array of $Field => $Value pairs that represent data posted * from the form in the $_POST or $_GET collection. */ public function Save($FormPostValues) { // Fudge your way through the schema application. This will allow me to // force the validation object to expect the fieldnames contained in // $this->Data. $this->Validation->ApplySchema($this->Data); // Validate the form posted values if ($this->Validation->Validate($FormPostValues)) { // Merge the validation fields and the forced settings into a single array $Settings = $this->Validation->ValidationFields(); if (is_array($this->_ForceSettings)) { $Settings = MergeArrays($Settings, $this->_ForceSettings); } return SaveToConfig($Settings); } else { return FALSE; } }
/** * Takes a set of form data ($Form->_PostValues), validates them, and * inserts or updates them to the configuration file. * * @param array $FormPostValues An associative array of $Field => $Value pairs that represent data posted * from the form in the $_POST or $_GET collection. */ public function Save($FormPostValues, $Live = FALSE) { // Fudge your way through the schema application. This will allow me to // force the validation object to expect the fieldnames contained in // $this->Data. $this->Validation->ApplySchema($this->Data); // Validate the form posted values if ($this->Validation->Validate($FormPostValues)) { // Merge the validation fields and the forced settings into a single array $Settings = $this->Validation->ValidationFields(); if (is_array($this->_ForceSettings)) { $Settings = MergeArrays($Settings, $this->_ForceSettings); } $SaveResults = SaveToConfig($Settings); // If the Live flag is true, set these in memory too if ($SaveResults && $Live) { Gdn::Config()->Set($Settings, TRUE); } return $SaveResults; } else { return FALSE; } }
/** * Takes a set of form data ($Form->_PostValues), validates them, and * inserts or updates them to the configuration file. * * @param array $FormPostValues An associative array of $Field => $Value pairs that represent data posted * from the form in the $_POST or $_GET collection. */ public function Save($FormPostValues) { if (isset($this->_ConfigurationFile) === FALSE) { trigger_error(ErrorMessage('You must define the file where the configuration settings will be saved.', 'ConfigurationModel', 'Save'), E_USER_ERROR); } // Fudge your way through the schema application. This will allow me to // force the validation object to expect the fieldnames contained in // $this->Data. $this->Validation->ApplySchema($this->Data); // Validate the form posted values if ($this->Validation->Validate($FormPostValues)) { $Config = Gdn::Factory(Gdn::AliasConfig); $Config->Load($this->_ConfigurationFile, 'Save', $this->Name); // Merge the validation fields and the forced settings into a single array $Settings = $this->Validation->ValidationFields(); if (is_array($this->_ForceSettings)) { $Settings = MergeArrays($Settings, $this->_ForceSettings); } foreach ($Settings as $Setting => $Value) { $Config->Set($Setting, $Value, TRUE); } // And save them to the conf file return $Config->Save(); } else { return FALSE; } }