3 * Smarty Internal Plugin Data
4 * This file contains the basic classes and methods for template and variable creation
12 * Base class with template and variable methods
15 * @subpackage Template
17 * @property int $scope
18 * @property Smarty $smarty
19 * The following methods will be dynamically loaded by the extension handler when they are called.
20 * They are located in a corresponding Smarty_Internal_Method_xxxx class
22 * @method mixed getConfigVariable(string $varName, bool $errorEnable = true)
23 * @method mixed getConfigVars(string $varName = null, bool $searchParents = true)
24 * @method mixed getGlobal(string $varName = null)
25 * @method mixed getStreamVariable(string $variable)
26 * @method Smarty_Internal_Data clearAssign(mixed $tpl_var)
27 * @method Smarty_Internal_Data clearAllAssign()
28 * @method Smarty_Internal_Data clearConfig(string $varName = null)
29 * @method Smarty_Internal_Data configLoad(string $config_file, mixed $sections = null, string $scope = 'local')
31 class Smarty_Internal_Data
34 * This object type (Smarty = 1, template = 2, data = 4)
41 * name of class used for templates
45 public $template_class = 'Smarty_Internal_Template';
50 * @var Smarty_Variable[]
52 public $tpl_vars = array();
55 * parent template (if any)
57 * @var Smarty|Smarty_Internal_Template|Smarty_Internal_Data
59 public $parent = null;
62 * configuration settings
66 public $config_vars = array();
71 * @var Smarty_Internal_Extension_Handler
76 * Smarty_Internal_Data constructor.
78 * Install extension handler
80 public function __construct()
82 $this->ext = new Smarty_Internal_Extension_Handler();
83 $this->ext->objType = $this->_objType;
87 * assigns a Smarty variable
89 * @param array|string $tpl_var the template variable name(s)
90 * @param mixed $value the value to assign
91 * @param boolean $nocache if true any output of this variable will be not cached
93 * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for
96 public function assign($tpl_var, $value = null, $nocache = false)
98 if (is_array($tpl_var)) {
99 foreach ($tpl_var as $_key => $_val) {
100 $this->assign($_key, $_val, $nocache);
103 if ($tpl_var != '') {
104 if ($this->_objType === 2) {
105 /** @var Smarty_Internal_Template $this */
106 $this->_assignInScope($tpl_var, $value, $nocache);
108 $this->tpl_vars[ $tpl_var ] = new Smarty_Variable($value, $nocache);
116 * appends values to template variables
118 * @api Smarty::append()
119 * @link http://www.smarty.net/docs/en/api.append.tpl
121 * @param array|string $tpl_var the template variable name(s)
122 * @param mixed $value the value to append
123 * @param bool $merge flag if array elements shall be merged
124 * @param bool $nocache if true any output of this variable will
127 * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
129 public function append($tpl_var, $value = null, $merge = false, $nocache = false)
131 return $this->ext->append->append($this, $tpl_var, $value, $merge, $nocache);
135 * assigns a global Smarty variable
137 * @param string $varName the global variable name
138 * @param mixed $value the value to assign
139 * @param boolean $nocache if true any output of this variable will be not cached
141 * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
143 public function assignGlobal($varName, $value = null, $nocache = false)
145 return $this->ext->assignGlobal->assignGlobal($this, $varName, $value, $nocache);
149 * appends values to template variables by reference
151 * @param string $tpl_var the template variable name
152 * @param mixed &$value the referenced value to append
153 * @param boolean $merge flag if array elements shall be merged
155 * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
157 public function appendByRef($tpl_var, &$value, $merge = false)
159 return $this->ext->appendByRef->appendByRef($this, $tpl_var, $value, $merge);
163 * assigns values to template variables by reference
165 * @param string $tpl_var the template variable name
167 * @param boolean $nocache if true any output of this variable will be not cached
169 * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
171 public function assignByRef($tpl_var, &$value, $nocache = false)
173 return $this->ext->assignByRef->assignByRef($this, $tpl_var, $value, $nocache);
177 * Returns a single or all template variables
179 * @api Smarty::getTemplateVars()
180 * @link http://www.smarty.net/docs/en/api.get.template.vars.tpl
182 * @param string $varName variable name or null
183 * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object
184 * @param bool $searchParents include parent templates?
186 * @return mixed variable value or or array of variables
188 public function getTemplateVars($varName = null, Smarty_Internal_Data $_ptr = null, $searchParents = true)
190 return $this->ext->getTemplateVars->getTemplateVars($this, $varName, $_ptr, $searchParents);
194 * gets the object of a Smarty variable
196 * @param string $variable the name of the Smarty variable
197 * @param Smarty_Internal_Data $_ptr optional pointer to data object
198 * @param boolean $searchParents search also in parent data
199 * @param bool $error_enable
201 * @return Smarty_Variable|Smarty_Undefined_Variable the object of the variable
202 * @deprecated since 3.1.28 please use Smarty_Internal_Data::getTemplateVars() instead.
204 public function getVariable($variable = null, Smarty_Internal_Data $_ptr = null, $searchParents = true,
205 $error_enable = true)
207 return $this->ext->getTemplateVars->_getVariable($this, $variable, $_ptr, $searchParents, $error_enable);
211 * Follow the parent chain an merge template and config variables
213 * @param \Smarty_Internal_Data|null $data
215 public function _mergeVars(Smarty_Internal_Data $data = null)
218 if (!empty($this->tpl_vars)) {
219 $data->tpl_vars = array_merge($this->tpl_vars, $data->tpl_vars);
221 if (!empty($this->config_vars)) {
222 $data->config_vars = array_merge($this->config_vars, $data->config_vars);
227 if (isset($this->parent)) {
228 $this->parent->_mergeVars($data);
233 * Return true if this instance is a Data obj
237 public function _isDataObj()
239 return $this->_objType === 4;
243 * Return true if this instance is a template obj
247 public function _isTplObj()
249 return $this->_objType === 2;
253 * Return true if this instance is a Smarty obj
257 public function _isSmartyObj()
259 return $this->_objType === 1;
267 public function _getSmartyObj()
269 return $this->smarty;
273 * Handle unknown class methods
275 * @param string $name unknown method-name
276 * @param array $args argument array
279 * @throws SmartyException
281 public function __call($name, $args)
283 return $this->ext->_callExternalMethod($this, $name, $args);