Added support for hidden config vars.

This commit is contained in:
andrey
2001-10-09 16:29:10 +00:00
parent 76c862f4c0
commit fb7161d4ee
6 changed files with 47 additions and 4 deletions

View File

@@ -46,6 +46,7 @@ class Config_File extends PEAR {
* @access public * @access public
*/ */
var $overwrite = true; var $overwrite = true;
/** /**
* Controls whether config values of on/true/yes and off/false/no get * Controls whether config values of on/true/yes and off/false/no get
* converted to boolean values automatically. * converted to boolean values automatically.
@@ -54,6 +55,13 @@ class Config_File extends PEAR {
*/ */
var $booleanize = true; var $booleanize = true;
/**
* Controls whether hidden config sections/vars are read from the file.
*
* @access public
*/
var $read_hidden = true;
/* Private variables */ /* Private variables */
var $_config_path = ""; var $_config_path = "";
var $_config_data = array(); var $_config_data = array();
@@ -247,7 +255,11 @@ class Config_File extends PEAR {
$config_data["sections"] = array(); $config_data["sections"] = array();
preg_match_all("/^\[(.*?)\]/m", $contents, $match); preg_match_all("/^\[(.*?)\]/m", $contents, $match);
foreach ($match[1] as $section) { foreach ($match[1] as $section) {
if ($section{0} == '.' && !$this->read_hidden)
continue;
if (preg_match("/\[".preg_quote($section)."\](.*?)(\n\[|\Z)/s", $contents, $match)) if (preg_match("/\[".preg_quote($section)."\](.*?)(\n\[|\Z)/s", $contents, $match))
if ($section{0} == '.')
$section = substr($section, 1);
$config_data["sections"][$section]["vars"] = $this->_parse_config_block($match[1]); $config_data["sections"][$section]["vars"] = $this->_parse_config_block($match[1]);
} }
@@ -271,7 +283,7 @@ class Config_File extends PEAR {
$config_lines = preg_split("/\n+/", $config_block); $config_lines = preg_split("/\n+/", $config_block);
foreach ($config_lines as $line) { foreach ($config_lines as $line) {
if (preg_match("/^\s*(\w+)\s*=(.*)/", $line, $match)) { if (preg_match("/^\s*(\.?\w+)\s*=(.*)/", $line, $match)) {
$var_value = preg_replace('/^([\'"])(.*)\1$/', '\2', trim($match[2])); $var_value = preg_replace('/^([\'"])(.*)\1$/', '\2', trim($match[2]));
$this->_set_config_var($vars, trim($match[1]), $var_value, $this->booleanize); $this->_set_config_var($vars, trim($match[1]), $var_value, $this->booleanize);
} }
@@ -282,6 +294,13 @@ class Config_File extends PEAR {
function _set_config_var(&$container, $var_name, $var_value, $booleanize) function _set_config_var(&$container, $var_name, $var_value, $booleanize)
{ {
if ($var_name{0} == '.') {
if (!$this->read_hidden)
return;
else
$var_name = substr($var_name, 1);
}
if (!preg_match("/^[a-zA-Z_]\w*$/", $var_name)) if (!preg_match("/^[a-zA-Z_]\w*$/", $var_name))
return new Config_File_Error("Bad variable name '$var_name'"); return new Config_File_Error("Bad variable name '$var_name'");

6
NEWS
View File

@@ -1,5 +1,7 @@
- added execution time to DEBUG console (Monte) - added support for hidden config variables that cannot be read by
- fixed bug where DEBUG console would not appear with cached content (Monte) templates. (Andrei)
- added execution time to DEBUG console. (Monte)
- fixed bug where DEBUG console would not appear with cached content. (Monte)
- added support for postfilter functions that are applied to compiled - added support for postfilter functions that are applied to compiled
template right after compilation. (Andrei) template right after compilation. (Andrei)
- fixed the name of clear_compile_tpl() API function to clear_compiled_tpl. - fixed the name of clear_compile_tpl() API function to clear_compiled_tpl.

View File

@@ -548,6 +548,7 @@ class Smarty
if (!class_exists('Config_File')) if (!class_exists('Config_File'))
include_once SMARTY_DIR.'Config_File.class.php'; include_once SMARTY_DIR.'Config_File.class.php';
$this->_conf_obj = new Config_File($this->config_dir); $this->_conf_obj = new Config_File($this->config_dir);
$this->_conf_obj->read_hidden = false;
} else } else
$this->_conf_obj->set_path($this->config_dir); $this->_conf_obj->set_path($this->config_dir);

1
TODO
View File

@@ -13,3 +13,4 @@
* allow {custom} .. {/custom} style of custom functions * allow {custom} .. {/custom} style of custom functions
* ability to concatenate values/strings together * ability to concatenate values/strings together
* don't load globals more than once from the same config file * don't load globals more than once from the same config file
* fix all E_NOTICE warnings

View File

@@ -46,6 +46,7 @@ class Config_File extends PEAR {
* @access public * @access public
*/ */
var $overwrite = true; var $overwrite = true;
/** /**
* Controls whether config values of on/true/yes and off/false/no get * Controls whether config values of on/true/yes and off/false/no get
* converted to boolean values automatically. * converted to boolean values automatically.
@@ -54,6 +55,13 @@ class Config_File extends PEAR {
*/ */
var $booleanize = true; var $booleanize = true;
/**
* Controls whether hidden config sections/vars are read from the file.
*
* @access public
*/
var $read_hidden = true;
/* Private variables */ /* Private variables */
var $_config_path = ""; var $_config_path = "";
var $_config_data = array(); var $_config_data = array();
@@ -247,7 +255,11 @@ class Config_File extends PEAR {
$config_data["sections"] = array(); $config_data["sections"] = array();
preg_match_all("/^\[(.*?)\]/m", $contents, $match); preg_match_all("/^\[(.*?)\]/m", $contents, $match);
foreach ($match[1] as $section) { foreach ($match[1] as $section) {
if ($section{0} == '.' && !$this->read_hidden)
continue;
if (preg_match("/\[".preg_quote($section)."\](.*?)(\n\[|\Z)/s", $contents, $match)) if (preg_match("/\[".preg_quote($section)."\](.*?)(\n\[|\Z)/s", $contents, $match))
if ($section{0} == '.')
$section = substr($section, 1);
$config_data["sections"][$section]["vars"] = $this->_parse_config_block($match[1]); $config_data["sections"][$section]["vars"] = $this->_parse_config_block($match[1]);
} }
@@ -271,7 +283,7 @@ class Config_File extends PEAR {
$config_lines = preg_split("/\n+/", $config_block); $config_lines = preg_split("/\n+/", $config_block);
foreach ($config_lines as $line) { foreach ($config_lines as $line) {
if (preg_match("/^\s*(\w+)\s*=(.*)/", $line, $match)) { if (preg_match("/^\s*(\.?\w+)\s*=(.*)/", $line, $match)) {
$var_value = preg_replace('/^([\'"])(.*)\1$/', '\2', trim($match[2])); $var_value = preg_replace('/^([\'"])(.*)\1$/', '\2', trim($match[2]));
$this->_set_config_var($vars, trim($match[1]), $var_value, $this->booleanize); $this->_set_config_var($vars, trim($match[1]), $var_value, $this->booleanize);
} }
@@ -282,6 +294,13 @@ class Config_File extends PEAR {
function _set_config_var(&$container, $var_name, $var_value, $booleanize) function _set_config_var(&$container, $var_name, $var_value, $booleanize)
{ {
if ($var_name{0} == '.') {
if (!$this->read_hidden)
return;
else
$var_name = substr($var_name, 1);
}
if (!preg_match("/^[a-zA-Z_]\w*$/", $var_name)) if (!preg_match("/^[a-zA-Z_]\w*$/", $var_name))
return new Config_File_Error("Bad variable name '$var_name'"); return new Config_File_Error("Bad variable name '$var_name'");

View File

@@ -548,6 +548,7 @@ class Smarty
if (!class_exists('Config_File')) if (!class_exists('Config_File'))
include_once SMARTY_DIR.'Config_File.class.php'; include_once SMARTY_DIR.'Config_File.class.php';
$this->_conf_obj = new Config_File($this->config_dir); $this->_conf_obj = new Config_File($this->config_dir);
$this->_conf_obj->read_hidden = false;
} else } else
$this->_conf_obj->set_path($this->config_dir); $this->_conf_obj->set_path($this->config_dir);