mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
Added support for hidden config vars.
This commit is contained in:
@@ -46,6 +46,7 @@ class Config_File extends PEAR {
|
||||
* @access public
|
||||
*/
|
||||
var $overwrite = true;
|
||||
|
||||
/**
|
||||
* Controls whether config values of on/true/yes and off/false/no get
|
||||
* converted to boolean values automatically.
|
||||
@@ -54,6 +55,13 @@ class Config_File extends PEAR {
|
||||
*/
|
||||
var $booleanize = true;
|
||||
|
||||
/**
|
||||
* Controls whether hidden config sections/vars are read from the file.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
var $read_hidden = true;
|
||||
|
||||
/* Private variables */
|
||||
var $_config_path = "";
|
||||
var $_config_data = array();
|
||||
@@ -247,7 +255,11 @@ class Config_File extends PEAR {
|
||||
$config_data["sections"] = array();
|
||||
preg_match_all("/^\[(.*?)\]/m", $contents, $match);
|
||||
foreach ($match[1] as $section) {
|
||||
if ($section{0} == '.' && !$this->read_hidden)
|
||||
continue;
|
||||
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]);
|
||||
}
|
||||
|
||||
@@ -271,7 +283,7 @@ class Config_File extends PEAR {
|
||||
$config_lines = preg_split("/\n+/", $config_block);
|
||||
|
||||
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]));
|
||||
$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)
|
||||
{
|
||||
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))
|
||||
return new Config_File_Error("Bad variable name '$var_name'");
|
||||
|
||||
|
6
NEWS
6
NEWS
@@ -1,5 +1,7 @@
|
||||
- added execution time to DEBUG console (Monte)
|
||||
- fixed bug where DEBUG console would not appear with cached content (Monte)
|
||||
- added support for hidden config variables that cannot be read by
|
||||
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
|
||||
template right after compilation. (Andrei)
|
||||
- fixed the name of clear_compile_tpl() API function to clear_compiled_tpl.
|
||||
|
@@ -548,6 +548,7 @@ class Smarty
|
||||
if (!class_exists('Config_File'))
|
||||
include_once SMARTY_DIR.'Config_File.class.php';
|
||||
$this->_conf_obj = new Config_File($this->config_dir);
|
||||
$this->_conf_obj->read_hidden = false;
|
||||
} else
|
||||
$this->_conf_obj->set_path($this->config_dir);
|
||||
|
||||
|
1
TODO
1
TODO
@@ -13,3 +13,4 @@
|
||||
* allow {custom} .. {/custom} style of custom functions
|
||||
* ability to concatenate values/strings together
|
||||
* don't load globals more than once from the same config file
|
||||
* fix all E_NOTICE warnings
|
||||
|
@@ -46,6 +46,7 @@ class Config_File extends PEAR {
|
||||
* @access public
|
||||
*/
|
||||
var $overwrite = true;
|
||||
|
||||
/**
|
||||
* Controls whether config values of on/true/yes and off/false/no get
|
||||
* converted to boolean values automatically.
|
||||
@@ -54,6 +55,13 @@ class Config_File extends PEAR {
|
||||
*/
|
||||
var $booleanize = true;
|
||||
|
||||
/**
|
||||
* Controls whether hidden config sections/vars are read from the file.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
var $read_hidden = true;
|
||||
|
||||
/* Private variables */
|
||||
var $_config_path = "";
|
||||
var $_config_data = array();
|
||||
@@ -247,7 +255,11 @@ class Config_File extends PEAR {
|
||||
$config_data["sections"] = array();
|
||||
preg_match_all("/^\[(.*?)\]/m", $contents, $match);
|
||||
foreach ($match[1] as $section) {
|
||||
if ($section{0} == '.' && !$this->read_hidden)
|
||||
continue;
|
||||
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]);
|
||||
}
|
||||
|
||||
@@ -271,7 +283,7 @@ class Config_File extends PEAR {
|
||||
$config_lines = preg_split("/\n+/", $config_block);
|
||||
|
||||
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]));
|
||||
$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)
|
||||
{
|
||||
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))
|
||||
return new Config_File_Error("Bad variable name '$var_name'");
|
||||
|
||||
|
@@ -548,6 +548,7 @@ class Smarty
|
||||
if (!class_exists('Config_File'))
|
||||
include_once SMARTY_DIR.'Config_File.class.php';
|
||||
$this->_conf_obj = new Config_File($this->config_dir);
|
||||
$this->_conf_obj->read_hidden = false;
|
||||
} else
|
||||
$this->_conf_obj->set_path($this->config_dir);
|
||||
|
||||
|
Reference in New Issue
Block a user