![]() |
Documentación GVHIDRA 3.1.5
|
Métodos públicos | |
Config_File ($config_path=NULL) | |
set_path ($config_path) | |
get ($file_name, $section_name=NULL, $var_name=NULL) | |
& | get_key ($config_key) |
get_file_names () | |
get_section_names ($file_name) | |
get_var_names ($file_name, $section=NULL) | |
clear ($file_name=NULL) | |
load_file ($file_name, $prepend_path=true) | |
set_file_contents ($config_file, $contents) | |
parse_contents ($contents) | |
_set_config_var (&$container, $var_name, $var_value, $booleanize) | |
_trigger_error_msg ($error_msg, $error_type=E_USER_WARNING) | |
Campos de datos | |
$overwrite = true | |
$booleanize = true | |
$read_hidden = true | |
$fix_newlines = true | |
$_config_path = "" | |
$_config_data = array() |
Definición en la línea 34 del archivo Config_File.class.php.
_set_config_var | ( | &$ | container, |
$ | var_name, | ||
$ | var_value, | ||
$ | booleanize | ||
) |
#@+ private
array | &$container | |
string | $var_name | |
mixed | $var_value | |
boolean | $booleanize | determines whether $var_value is converted to to true/false |
Definición en la línea 348 del archivo Config_File.class.php.
{ if (substr($var_name, 0, 1) == '.') { if (!$this->read_hidden) return; else $var_name = substr($var_name, 1); } if (!preg_match("/^[a-zA-Z_]\w*$/", $var_name)) { $this->_trigger_error_msg("Bad variable name '$var_name'"); return; } if ($booleanize) { if (preg_match("/^(on|true|yes)$/i", $var_value)) $var_value = true; else if (preg_match("/^(off|false|no)$/i", $var_value)) $var_value = false; } if (!isset($container[$var_name]) || $this->overwrite) $container[$var_name] = $var_value; else { settype($container[$var_name], 'array'); $container[$var_name][] = $var_value; } }
_trigger_error_msg | ( | $ | error_msg, |
$ | error_type = E_USER_WARNING |
||
) |
trigger_error() creates a PHP warning/error
string | $error_msg | |
integer | $error_type | one of |
Definición en la línea 382 del archivo Config_File.class.php.
{
trigger_error("Config_File error: $error_msg", $error_type);
}
clear | ( | $ | file_name = NULL | ) |
Clear loaded config data for a certain file or all files.
string | $file_name | file to clear config data for |
Definición en la línea 213 del archivo Config_File.class.php.
{ if ($file_name === NULL) $this->_config_data = array(); else if (isset($this->_config_data[$file_name])) $this->_config_data[$file_name] = array(); }
Config_File | ( | $ | config_path = NULL | ) |
#@- Constructs a new config file class.
string | $config_path | (optional) path to the config files |
Definición en la línea 72 del archivo Config_File.class.php.
{ if (isset($config_path)) $this->set_path($config_path); }
get | ( | $ | file_name, |
$ | section_name = NULL , |
||
$ | var_name = NULL |
||
) |
Retrieves config info based on the file, section, and variable name.
string | $file_name | config file to get info for |
string | $section_name | (optional) section to get info for |
string | $var_name | (optional) variable to get info for |
Definición en la línea 108 del archivo Config_File.class.php.
{ if (empty($file_name)) { $this->_trigger_error_msg('Empty config file name'); return; } else { $file_name = $this->_config_path . $file_name; if (!isset($this->_config_data[$file_name])) $this->load_file($file_name, false); } if (!empty($var_name)) { if (empty($section_name)) { return $this->_config_data[$file_name]["vars"][$var_name]; } else { if(isset($this->_config_data[$file_name]["sections"][$section_name]["vars"][$var_name])) return $this->_config_data[$file_name]["sections"][$section_name]["vars"][$var_name]; else return array(); } } else { if (empty($section_name)) { return (array)$this->_config_data[$file_name]["vars"]; } else { if(isset($this->_config_data[$file_name]["sections"][$section_name]["vars"])) return (array)$this->_config_data[$file_name]["sections"][$section_name]["vars"]; else return array(); } } }
get_file_names | ( | ) |
Get all loaded config file names.
Definición en la línea 160 del archivo Config_File.class.php.
{
return array_keys($this->_config_data);
}
& get_key | ( | $ | config_key | ) |
Retrieves config info based on the key.
$file_name | string config key (filename/section/var) |
Definición en la línea 148 del archivo Config_File.class.php.
{ list($file_name, $section_name, $var_name) = explode('/', $config_key, 3); $result = &$this->get($file_name, $section_name, $var_name); return $result; }
get_section_names | ( | $ | file_name | ) |
Get all section names from a loaded file.
string | $file_name | config file to get section names from |
Definición en la línea 172 del archivo Config_File.class.php.
{ $file_name = $this->_config_path . $file_name; if (!isset($this->_config_data[$file_name])) { $this->_trigger_error_msg("Unknown config file '$file_name'"); return; } return array_keys($this->_config_data[$file_name]["sections"]); }
get_var_names | ( | $ | file_name, |
$ | section = NULL |
||
) |
Get all global or section variable names.
string | $file_name | config file to get info for |
string | $section_name | (optional) section to get info for |
Definición en la línea 191 del archivo Config_File.class.php.
{ if (empty($file_name)) { $this->_trigger_error_msg('Empty config file name'); return; } else if (!isset($this->_config_data[$file_name])) { $this->_trigger_error_msg("Unknown config file '$file_name'"); return; } if (empty($section)) return array_keys($this->_config_data[$file_name]["vars"]); else return array_keys($this->_config_data[$file_name]["sections"][$section]["vars"]); }
load_file | ( | $ | file_name, |
$ | prepend_path = true |
||
) |
Load a configuration file manually.
string | $file_name | file name to load |
boolean | $prepend_path | whether current config path should be prepended to the filename |
Definición en la línea 229 del archivo Config_File.class.php.
{ if ($prepend_path && $this->_config_path != "") $config_file = $this->_config_path . $file_name; else $config_file = $file_name; ini_set('track_errors', true); $fp = @fopen($config_file, "r"); if (!is_resource($fp)) { $this->_trigger_error_msg("Could not open config file '$config_file'"); return false; } $contents = ($size = filesize($config_file)) ? fread($fp, $size) : ''; fclose($fp); $this->_config_data[$config_file] = $this->parse_contents($contents); return true; }
parse_contents | ( | $ | contents | ) |
parse the source of a configuration file manually.
string | $contents | the file-contents to parse |
Definición en la línea 267 del archivo Config_File.class.php.
{ if($this->fix_newlines) { // fix mac/dos formatted newlines $contents = preg_replace('!\r\n?!', "\n", $contents); } $config_data = array(); $config_data['sections'] = array(); $config_data['vars'] = array(); /* reference to fill with data */ $vars =& $config_data['vars']; /* parse file line by line */ preg_match_all('!^.*\r?\n?!m', $contents, $match); $lines = $match[0]; for ($i=0, $count=count($lines); $i<$count; $i++) { $line = $lines[$i]; if (empty($line)) continue; if ( substr($line, 0, 1) == '[' && preg_match('!^\[(.*?)\]!', $line, $match) ) { /* section found */ if (substr($match[1], 0, 1) == '.') { /* hidden section */ if ($this->read_hidden) { $section_name = substr($match[1], 1); } else { /* break reference to $vars to ignore hidden section */ unset($vars); $vars = array(); continue; } } else { $section_name = $match[1]; } if (!isset($config_data['sections'][$section_name])) $config_data['sections'][$section_name] = array('vars' => array()); $vars =& $config_data['sections'][$section_name]['vars']; continue; } if (preg_match('/^\s*(\.?\w+)\s*=\s*(.*)/s', $line, $match)) { /* variable found */ $var_name = rtrim($match[1]); if (strpos($match[2], '"""') === 0) { /* handle multiline-value */ $lines[$i] = substr($match[2], 3); $var_value = ''; while ($i<$count) { if (($pos = strpos($lines[$i], '"""')) === false) { $var_value .= $lines[$i++]; } else { /* end of multiline-value */ $var_value .= substr($lines[$i], 0, $pos); break; } } $booleanize = false; } else { /* handle simple value */ $var_value = preg_replace('/^([\'"])(.*)\1$/', '\2', rtrim($match[2])); $booleanize = $this->booleanize; } $this->_set_config_var($vars, $var_name, $var_value, $booleanize); } /* else unparsable line / means it is a comment / means ignore it */ } return $config_data; }
set_file_contents | ( | $ | config_file, |
$ | contents | ||
) |
Store the contents of a file manually.
string | $config_file | file name of the related contents |
string | $contents | the file-contents to parse |
Definición en la línea 256 del archivo Config_File.class.php.
{ $this->_config_data[$config_file] = $this->parse_contents($contents); return true; }
set_path | ( | $ | config_path | ) |
Set the path where configuration files can be found.
string | $config_path | path to the config files |
Definición en la línea 84 del archivo Config_File.class.php.
{ if (!empty($config_path)) { if (!is_string($config_path) || !file_exists($config_path) || !is_dir($config_path)) { $this->_trigger_error_msg("Bad config file path '$config_path'"); return; } if(substr($config_path, -1) != DIRECTORY_SEPARATOR) { $config_path .= DIRECTORY_SEPARATOR; } $this->_config_path = $config_path; } }
$_config_data = array() |
Definición en la línea 64 del archivo Config_File.class.php.
$_config_path = "" |
#@- private
Definición en la línea 63 del archivo Config_File.class.php.
$booleanize = true |
Controls whether config values of on/true/yes and off/false/no get converted to boolean values automatically.
Definición en la línea 48 del archivo Config_File.class.php.
$fix_newlines = true |
Controls whether or not to fix mac or dos formatted newlines. If set to true, or
will be changed to
.
Definición en la línea 59 del archivo Config_File.class.php.
$overwrite = true |
Controls whether variables with the same name overwrite each other.
Definición en la línea 42 del archivo Config_File.class.php.
$read_hidden = true |
Controls whether hidden config sections/vars are read from the file.
Definición en la línea 53 del archivo Config_File.class.php.