Inheritance: extends Gdn_Pluggable
コード例 #1
0
 /**
  * Saves all settings in $Group to $File.
  *
  * @param string $File The full path to the file where the Settings should be saved.
  * @param string $Group The name of the settings group to be saved to the $File.
  * @return boolean
  */
 public function Save($File = NULL, $Group = NULL)
 {
     // Plain calls to Gdn::Config()->Save() simply save the dynamic config and return
     if (is_null($File)) {
         return $this->Dynamic->Save();
     }
     // ... otherwise we're trying to extract some of the config for some reason
     if ($File == '') {
         trigger_error(ErrorMessage('You must specify a file path to be saved.', $Group, 'Save'), E_USER_ERROR);
     }
     if (!is_writable($File)) {
         throw new Exception(sprintf(T("Unable to write to config file '%s' when saving."), $File));
     }
     if (empty($Group)) {
         $Group = $this->DefaultGroup;
     }
     $Data =& $this->Data;
     ksort($Data);
     // Check for the case when the configuration is the group.
     if (is_array($Data) && count($Data) == 1 && array_key_exists($Group, $Data)) {
         $Data = $Data[$Group];
     }
     // Do a sanity check on the config save.
     if ($File == $this->DefaultPath()) {
         if (!isset($Data['Database'])) {
             if ($Pm = Gdn::PluginManager()) {
                 $Pm->EventArguments['Data'] = $Data;
                 $Pm->EventArguments['Backtrace'] = debug_backtrace();
                 $Pm->FireEvent('ConfigError');
             }
             return FALSE;
         }
     }
     // Build string
     $FileContents = $this->Format($Data, array('VariableName' => $Group, 'Headers' => TRUE, 'ByLine' => TRUE, 'WrapPHP' => TRUE));
     if ($FileContents === FALSE) {
         trigger_error(ErrorMessage('Failed to define configuration file contents.', $Group, 'Save'), E_USER_ERROR);
     }
     $FileKey = sprintf(Gdn_Configuration::CONFIG_FILE_CACHE_KEY, $File);
     if ($this->Caching() && Gdn::Cache()->Type() == Gdn_Cache::CACHE_TYPE_MEMORY && Gdn::Cache()->ActiveEnabled()) {
         Gdn::Cache()->Store($FileKey, $Data, array(Gdn_Cache::FEATURE_NOPREFIX => TRUE, Gdn_Cache::FEATURE_EXPIRY => 3600));
     }
     // Infrastructure deployment. Use old method.
     $TmpFile = tempnam(PATH_CONF, 'config');
     $Result = FALSE;
     if (file_put_contents($TmpFile, $FileContents) !== FALSE) {
         chmod($TmpFile, 0775);
         $Result = rename($TmpFile, $File);
     }
     if ($Result && function_exists('apc_delete_file')) {
         // This fixes a bug with some configurations of apc.
         @apc_delete_file($File);
     }
     return $Result;
 }
コード例 #2
0
ファイル: class.configuration.php プロジェクト: R-J/vanilla
 /**
  * Loads settings from an array into the object with the specified name;
  *
  * This array should be a hierarchical Vanilla config.
  *
  * @param string $ConfigData An array containing the configuration data
  * @param string $Tag A string descriptor of this config set
  * @param string $Name The name of the variable and initial group settings.
  *   Note: When $Name is 'Configuration' then the data will be set to the root of the config.
  * @param boolean $Dynamic Optional, whether to treat this as the request's "dynamic" config, and
  *   to save config changes here. These settings will also be re-applied later when "OverlayDynamic"
  *   is called after all defaults are loaded.
  * @return boolean
  */
 public function loadArray($ConfigData, $Tag, $Name = 'Configuration', $Dynamic = true, $SaveCallback = null, $CallbackOptions = null)
 {
     $ConfigurationSource = Gdn_ConfigurationSource::fromArray($this, $ConfigData, $Tag, $Name);
     if (!$ConfigurationSource) {
         return false;
     }
     $UseSplitting = $this->splitting;
     $ConfigurationSource->splitting($UseSplitting);
     $SourceTag = "array:{$Tag}";
     $this->sources[$SourceTag] = $ConfigurationSource;
     if ($Dynamic) {
         $this->dynamic = $ConfigurationSource;
     }
     if (!$UseSplitting) {
         $this->massImport($ConfigurationSource->export());
     } else {
         self::mergeConfig($this->Data, $ConfigurationSource->export());
     }
     // Callback for saving
     if (!is_null($SaveCallback)) {
         $ConfigurationSource->assignCallback($SaveCallback, $CallbackOptions);
     }
 }