move getTemplateVars() into data object

This commit is contained in:
monte.ohrt
2010-02-08 17:31:15 +00:00
parent 5be6130f0c
commit 0c2b18c727
3 changed files with 40 additions and 40 deletions

2
README
View File

@@ -54,6 +54,7 @@ $smarty->getConfigVariable($variable)
$smarty->getStreamVariable($variable)
$smarty->getConfigVars($varname = null)
$smarty->clearConfig($varname = null)
$smarty->getTemplateVars($varname = null, $_ptr = null, $search_parents = true)
// some API calls are moved into their own objects:
@@ -87,7 +88,6 @@ $smarty->unregister->variableFilter($function_name)
$smarty->utility->compileAllTemplates($extention = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null)
$smarty->utility->clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null)
$smarty->utility->getTemplateVars($varname = null, $_ptr = null, $search_parents = true)
$smarty->utility->testInstall()
// then all the getters/setters, available for all properties. Here are a few:

View File

@@ -158,6 +158,45 @@ class Smarty_Internal_Data {
}
}
/**
* Returns a single or all template variables
*
* @param string $varname variable name or null
* @return string variable value or or array of variables
*/
function getTemplateVars($varname = null, $_ptr = null, $search_parents = true)
{
if (isset($varname)) {
$_var = $this->getVariable($varname, $_ptr, $search_parents);
if (is_object($_var)) {
return $_var->value;
} else {
return null;
}
} else {
$_result = array();
if ($_ptr === null) {
$_ptr = $this;
} while ($_ptr !== null) {
foreach ($_ptr->tpl_vars AS $key => $var) {
$_result[$key] = $var->value;
}
// not found, try at parent
if ($search_parents) {
$_ptr = $_ptr->parent;
} else {
$_ptr = null;
}
}
if ($search_parents) {
foreach ($this->global_tpl_vars AS $key => $var) {
$_result[$key] = $var->value;
}
}
return $_result;
}
}
/**
* clear the given assigned template variable.
*

View File

@@ -154,45 +154,6 @@ class Smarty_Internal_Utility {
return $_count;
}
/**
* Returns a single or all template variables
*
* @param string $varname variable name or null
* @return string variable value or or array of variables
*/
function getTemplateVars($varname = null, $_ptr = null, $search_parents = true)
{
if (isset($varname)) {
$_var = $this->smarty->getVariable($varname, $_ptr, $search_parents);
if (is_object($_var)) {
return $_var->value;
} else {
return null;
}
} else {
$_result = array();
if ($_ptr === null) {
$_ptr = $this->smarty;
} while ($_ptr !== null) {
foreach ($_ptr->tpl_vars AS $key => $var) {
$_result[$key] = $var->value;
}
// not found, try at parent
if ($search_parents) {
$_ptr = $_ptr->parent;
} else {
$_ptr = null;
}
}
if ($search_parents) {
foreach ($this->smarty->global_tpl_vars AS $key => $var) {
$_result[$key] = $var->value;
}
}
return $_result;
}
}
function testInstall()
{
echo "<PRE>\n";