Horde_Config::writePHPConfig PHP Метод

writePHPConfig() публичный Метод

Generates and writes the content of the application's configuration file.
public writePHPConfig ( Horde_Variables $formvars, string &$php = null ) : boolean
$formvars Horde_Variables The processed configuration form data.
$php string The content of the generated configuration file.
Результат boolean True if the configuration file could be written immediately to the file system.
    public function writePHPConfig($formvars, &$php = null)
    {
        $php = $this->generatePHPConfig($formvars);
        $path = $GLOBALS['registry']->get('fileroot', $this->_app) . '/config';
        $configFile = $this->configFile();
        if (file_exists($configFile)) {
            if (@copy($configFile, $path . '/conf.bak.php')) {
                $GLOBALS['notification']->push(sprintf(Horde_Core_Translation::t("Successfully saved the backup configuration file %s."), Horde_Util::realPath($path . '/conf.bak.php')), 'horde.success');
            } else {
                $GLOBALS['notification']->push(sprintf(Horde_Core_Translation::t("Could not save the backup configuration file %s."), Horde_Util::realPath($path . '/conf.bak.php')), 'horde.warning');
            }
        }
        if ($fp = @fopen($configFile, 'w')) {
            /* Can write, so output to file. */
            fwrite($fp, $php);
            fclose($fp);
            $GLOBALS['registry']->rebuild();
            $GLOBALS['notification']->push(sprintf(Horde_Core_Translation::t("Successfully wrote %s"), Horde_Util::realPath($configFile)), 'horde.success');
            return true;
        }
        /* Cannot write. Save to session. */
        $GLOBALS['session']->set('horde', 'config/' . $this->_app, $php);
        return false;
    }

Usage Example

Пример #1
0
 /**
  * Creates default configuration files for all installed applications.
  *
  * @throws Horde_Exception
  */
 public function writeAllConfigs()
 {
     foreach ($GLOBALS['registry']->listAllApps() as $app) {
         if ($app == 'horde' || !file_exists($GLOBALS['registry']->get('fileroot', $app) . '/config/conf.xml')) {
             continue;
         }
         $config = new Horde_Config($app);
         $configFile = $config->configFile();
         if (!$config->writePHPConfig(new Horde_Variables())) {
             throw new Horde_Exception('Cannot write configuration file ' . Horde_Util::realPath($configFile));
         }
     }
 }
All Usage Examples Of Horde_Config::writePHPConfig