Gdn_ConfigurationSource::set PHP Method

set() public method

public set ( $Name, null $Value = null, boolean $Overwrite = true )
$Name
$Value null
$Overwrite boolean
    public function set($Name, $Value = null, $Overwrite = true)
    {
        // Make sure this source' config settings are in the right format
        if (!is_array($this->Settings)) {
            $this->Settings = 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 = val(0, $Keys);
                if ($FirstKey == $this->Group) {
                    $Keys = array(array_shift($Keys), implode('.', $Keys));
                } else {
                    $Keys = array($Name);
                }
            }
            $KeyCount = count($Keys);
            $Settings =& $this->Settings;
            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) {
                        $OldVal = val($Key, $Settings, null);
                        $SetVal = $Value;
                        $Settings[$Key] = $SetVal;
                        if (!$KeyExists || $SetVal != $OldVal) {
                            $this->Dirty = true;
                        }
                    }
                } else {
                    // Build the array as we loop over the key.
                    if ($KeyExists === false) {
                        $Settings[$Key] = array();
                    }
                    // Advance the pointer
                    $Settings =& $Settings[$Key];
                }
            }
        }
    }