Habari\InstallHandler::write_config_file PHP Метод

write_config_file() приватный Метод

Writes the configuration file with the variables needed for initialization of the application
private write_config_file ( Bool $ignore_registry = false ) : boolean
$ignore_registry Bool skip the configuration registry check (used in config rewrite)
Результат boolean Did the file get written?
    private function write_config_file($ignore_registry = false)
    {
        // first, check if a config.php file exists
        if (file_exists(Site::get_dir('config_file'))) {
            // set the defaults for comparison
            $db_host = $this->handler_vars['db_host'];
            $db_file = $this->handler_vars['db_file'];
            $db_type = $this->handler_vars['db_type'];
            $db_schema = $this->handler_vars['db_schema'];
            $db_user = $this->handler_vars['db_user'];
            $db_pass = $this->handler_vars['db_pass'];
            $table_prefix = $this->handler_vars['table_prefix'];
            // set the connection string
            switch ($db_type) {
                case 'mysql':
                    $connection_string = "{$db_type}:host={$db_host};dbname={$db_schema}";
                    break;
                case 'pgsql':
                    $connection_string = "{$db_type}:host={$db_host} dbname={$db_schema}";
                    break;
                case 'sqlite':
                    $connection_string = "{$db_type}:{$db_file}";
                    break;
            }
            // load the config.php file
            include Site::get_dir('config_file');
            // and now we compare the values defined there to
            // the values POSTed to the installer
            if (!$ignore_registry && Config::exists('db_connection') && Config::get('db_connection')->connection_string == $connection_string && Config::get('db_connection')->username == $db_user && Config::get('db_connection')->password == $db_pass && Config::get('db_connection')->prefix == $table_prefix) {
                // the values are the same, so don't bother
                // trying to write to config.php
                return true;
            }
        }
        if (!($file_contents = file_get_contents(HABARI_PATH . "/system/schema/" . $this->handler_vars['db_type'] . "/config.php"))) {
            return false;
        }
        if ($file_contents = html_entity_decode($this->get_config_file())) {
            if ($file = @fopen(Site::get_dir('config_file'), 'w')) {
                if (fwrite($file, $file_contents, strlen($file_contents))) {
                    fclose($file);
                    return true;
                }
            }
            $this->handler_vars['config_file'] = Site::get_dir('config_file');
            $this->handler_vars['file_contents'] = Utils::htmlspecialchars($file_contents);
            $this->display('config');
            return false;
        }
        return false;
        // Only happens when config.php template does not exist.
    }