mirror of
https://github.com/smarty-php/smarty.git
synced 2025-10-09 02:30:55 +02:00
71 lines
2.3 KiB
PHP
71 lines
2.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Smarty Method GetTemplateVars
|
|
*
|
|
* Smarty::getTemplateVars() method
|
|
*
|
|
* @package Smarty
|
|
* @subpackage PluginsInternal
|
|
* @author Uwe Tews
|
|
*/
|
|
class Smarty_Internal_Method_GetTemplateVars
|
|
{
|
|
/**
|
|
* Valid for all objects
|
|
*
|
|
* @var int
|
|
*/
|
|
public $objMap = 7;
|
|
|
|
/**
|
|
* Returns a single or all template variables
|
|
*
|
|
* @api Smarty::getTemplateVars()
|
|
* @link http://www.smarty.net/docs/en/api.get.template.vars.tpl
|
|
*
|
|
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
|
|
* @param string $varname variable name or null
|
|
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object
|
|
* @param bool $search_parents include parent templates?
|
|
*
|
|
* @return mixed variable value or or array of variables
|
|
*/
|
|
public function getTemplateVars(Smarty_Internal_Data $data, $varname = null, Smarty_Internal_Data $_ptr = null, $search_parents = true)
|
|
{
|
|
if (isset($varname)) {
|
|
$_var = $data->_getVariable($varname, $_ptr, $search_parents, false);
|
|
if (is_object($_var)) {
|
|
return $_var->value;
|
|
} else {
|
|
return null;
|
|
}
|
|
} else {
|
|
$_result = array();
|
|
if ($_ptr === null) {
|
|
$_ptr = $data;
|
|
}
|
|
while ($_ptr !== null) {
|
|
foreach ($_ptr->tpl_vars AS $key => $var) {
|
|
if (!array_key_exists($key, $_result)) {
|
|
$_result[$key] = $var->value;
|
|
}
|
|
}
|
|
// not found, try at parent
|
|
if ($search_parents) {
|
|
$_ptr = $_ptr->parent;
|
|
} else {
|
|
$_ptr = null;
|
|
}
|
|
}
|
|
if ($search_parents && isset(Smarty::$global_tpl_vars)) {
|
|
foreach (Smarty::$global_tpl_vars AS $key => $var) {
|
|
if (!array_key_exists($key, $_result)) {
|
|
$_result[$key] = $var->value;
|
|
}
|
|
}
|
|
}
|
|
return $_result;
|
|
}
|
|
}
|
|
} |