Exemplo n.º 1
0
 /**
  * Assigns a setting to the configuration array.
  *
  * @param string $Name The name of the configuration setting to assign. If the setting is
  *   contained within an associative array, use dot denomination to get the
  *   setting. ie. $this->Set('Database.Host', $Value) would set
  *   $Configuration[$Group]['Database']['Host'] = $Value
  * @param mixed $Value The value of the configuration setting.
  * @param boolean $Overwrite If the setting already exists, should it's value be overwritten? Defaults to true.
  * @param boolean $AddToSave Whether or not to queue the value up for the next call to Gdn_Config::Save().
  */
 public function Set($Name, $Value, $Overwrite = TRUE, $Save = TRUE)
 {
     // Make sure the config settings are in the right format
     if (!is_array($this->Data)) {
         $this->Data = array();
     }
     if (!is_array($Name)) {
         $Name = array($Name => $Value);
     } else {
         $Overwrite = $Value;
     }
     $Data = $Name;
     foreach ($Data as $Name => $Value) {
         $Keys = explode('.', $Name);
         // If splitting is off, HANDLE IT
         if (!$this->Splitting) {
             $FirstKey = GetValue(0, $Keys);
             if ($FirstKey == $this->DefaultGroup) {
                 $Keys = array(array_shift($Keys), implode('.', $Keys));
             } else {
                 $Keys = array($Name);
             }
         }
         $KeyCount = count($Keys);
         $Settings =& $this->Data;
         for ($i = 0; $i < $KeyCount; ++$i) {
             $Key = $Keys[$i];
             if (!is_array($Settings)) {
                 $Settings = array();
             }
             $KeyExists = array_key_exists($Key, $Settings);
             if ($i == $KeyCount - 1) {
                 // If we are on the last iteration of the key, then set the value.
                 if ($KeyExists === FALSE || $Overwrite === TRUE) {
                     $Settings[$Key] = $Value;
                 }
             } else {
                 // Build the array as we loop over the key. Doucement.
                 if ($KeyExists === FALSE) {
                     $Settings[$Key] = array();
                 }
                 // Advance the pointer
                 $Settings =& $Settings[$Key];
             }
         }
     }
     if ($Save) {
         $this->Dynamic->Set($Name, $Value, $Overwrite);
     }
 }