Toolbox::writeConfig PHP Méthode

writeConfig() static public méthode

Save a configuration file
static public writeConfig ( $name, $content ) : boolean
$name string config file name
$content string config file content
Résultat boolean
    static function writeConfig($name, $content)
    {
        $name = GLPI_CONFIG_DIR . '/' . $name;
        $fp = fopen($name, 'wt');
        if ($fp) {
            $fw = fwrite($fp, $content);
            fclose($fp);
            if (function_exists('opcache_invalidate')) {
                /* Invalidate Zend OPcache to ensure saved version used */
                opcache_invalidate($name, true);
            }
            return $fw > 0;
        }
        return false;
    }

Usage Example

Exemple #1
0
 /**
  * Create slave DB configuration file
  *
  * @param host       the slave DB host(s)
  * @param user       the slave DB user
  * @param password   the slave DB password
  * @param DBname     the name of the slave DB
  *
  * @return boolean for success
  **/
 static function createSlaveConnectionFile($host, $user, $password, $DBname)
 {
     $DB_str = "<?php \n class DBSlave extends DBmysql { \n var \$slave = true; \n var \$dbhost = ";
     $host = trim($host);
     if (strpos($host, ' ')) {
         $hosts = explode(' ', $host);
         $first = true;
         foreach ($hosts as $host) {
             if (!empty($host)) {
                 $DB_str .= ($first ? "array('" : ",'") . $host . "'";
                 $first = false;
             }
         }
         if ($first) {
             // no host configured
             return false;
         }
         $DB_str .= ");\n";
     } else {
         $DB_str .= "'{$host}';\n";
     }
     $DB_str .= " var \$dbuser = '******'; \n var \$dbpassword= '******'; \n var \$dbdefault = '" . $DBname . "'; \n } \n ?>";
     return Toolbox::writeConfig('config_db_slave.php', $DB_str);
 }
All Usage Examples Of Toolbox::writeConfig