You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

smarty_internal_data.php 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Data
  4. * This file contains the basic classes and methods for template and variable creation
  5. *
  6. * @package Smarty
  7. * @subpackage Template
  8. * @author Uwe Tews
  9. */
  10. /**
  11. * Base class with template and variable methods
  12. *
  13. * @package Smarty
  14. * @subpackage Template
  15. *
  16. * @method mixed getConfigVars(string $varName = null, bool $searchParents = true)
  17. * @method mixed getStreamVariable(string $variable)
  18. * @method Smarty_Internal_Data clearAssign(mixed $tpl_var)
  19. * @method Smarty_Internal_Data clearAllAssign()
  20. * @method Smarty_Internal_Data clearConfig(string $varName = null)
  21. * @method Smarty_Internal_Data configLoad(string $config_file, mixed $sections = null, string $scope = 'local')
  22. * @property int $scope
  23. */
  24. class Smarty_Internal_Data
  25. {
  26. /**
  27. * This object type (Smarty = 1, template = 2, data = 4)
  28. *
  29. * @var int
  30. */
  31. public $_objType = 4;
  32. /**
  33. * name of class used for templates
  34. *
  35. * @var string
  36. */
  37. public $template_class = 'Smarty_Internal_Template';
  38. /**
  39. * template variables
  40. *
  41. * @var Smarty_Variable[]
  42. */
  43. public $tpl_vars = array();
  44. /**
  45. * parent template (if any)
  46. *
  47. * @var Smarty|Smarty_Internal_Template|Smarty_Internal_Data
  48. */
  49. public $parent = null;
  50. /**
  51. * configuration settings
  52. *
  53. * @var string[]
  54. */
  55. public $config_vars = array();
  56. /**
  57. * extension handler
  58. *
  59. * @var Smarty_Internal_Extension_Handler
  60. */
  61. public $ext = null;
  62. /**
  63. * Smarty_Internal_Data constructor.
  64. *
  65. * Install extension handler
  66. */
  67. public function __construct()
  68. {
  69. $this->ext = new Smarty_Internal_Extension_Handler();
  70. $this->ext->objType = $this->_objType;
  71. }
  72. /**
  73. * assigns a Smarty variable
  74. *
  75. * @param array|string $tpl_var the template variable name(s)
  76. * @param mixed $value the value to assign
  77. * @param boolean $nocache if true any output of this variable will be not cached
  78. *
  79. * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for
  80. * chaining
  81. */
  82. public function assign($tpl_var, $value = null, $nocache = false)
  83. {
  84. if (is_array($tpl_var)) {
  85. foreach ($tpl_var as $_key => $_val) {
  86. if ($_key != '') {
  87. $this->tpl_vars[$_key] = new Smarty_Variable($_val, $nocache);
  88. if ($this->_objType == 2 && $this->scope) {
  89. $this->ext->_updateScope->updateScope($this, $_key);
  90. }
  91. }
  92. }
  93. } else {
  94. if ($tpl_var != '') {
  95. $this->tpl_vars[$tpl_var] = new Smarty_Variable($value, $nocache);
  96. if ($this->_objType == 2 && $this->scope) {
  97. $this->ext->_updateScope->updateScope($this, $tpl_var);
  98. }
  99. }
  100. }
  101. return $this;
  102. }
  103. /**
  104. * appends values to template variables
  105. *
  106. * @api Smarty::append()
  107. * @link http://www.smarty.net/docs/en/api.append.tpl
  108. *
  109. * @param array|string $tpl_var the template variable name(s)
  110. * @param mixed $value the value to append
  111. * @param bool $merge flag if array elements shall be merged
  112. * @param bool $nocache if true any output of this variable will
  113. * be not cached
  114. *
  115. * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
  116. */
  117. public function append($tpl_var, $value = null, $merge = false, $nocache = false)
  118. {
  119. return $this->ext->append->append($this, $tpl_var, $value, $merge, $nocache);
  120. }
  121. /**
  122. * assigns a global Smarty variable
  123. *
  124. * @param string $varName the global variable name
  125. * @param mixed $value the value to assign
  126. * @param boolean $nocache if true any output of this variable will be not cached
  127. *
  128. * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
  129. */
  130. public function assignGlobal($varName, $value = null, $nocache = false)
  131. {
  132. return $this->ext->assignGlobal->assignGlobal($this, $varName, $value, $nocache);
  133. }
  134. /**
  135. * appends values to template variables by reference
  136. *
  137. * @param string $tpl_var the template variable name
  138. * @param mixed &$value the referenced value to append
  139. * @param boolean $merge flag if array elements shall be merged
  140. *
  141. * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
  142. */
  143. public function appendByRef($tpl_var, &$value, $merge = false)
  144. {
  145. return $this->ext->appendByRef->appendByRef($this, $tpl_var, $value, $merge);
  146. }
  147. /**
  148. * assigns values to template variables by reference
  149. *
  150. * @param string $tpl_var the template variable name
  151. * @param $value
  152. * @param boolean $nocache if true any output of this variable will be not cached
  153. *
  154. * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
  155. */
  156. public function assignByRef($tpl_var, &$value, $nocache = false)
  157. {
  158. return $this->ext->assignByRef->assignByRef($this, $tpl_var, $value, $nocache);
  159. }
  160. /**
  161. * Returns a single or all template variables
  162. *
  163. * @api Smarty::getTemplateVars()
  164. * @link http://www.smarty.net/docs/en/api.get.template.vars.tpl
  165. *
  166. * @param string $varName variable name or null
  167. * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object
  168. * @param bool $searchParents include parent templates?
  169. *
  170. * @return mixed variable value or or array of variables
  171. */
  172. public function getTemplateVars($varName = null, Smarty_Internal_Data $_ptr = null, $searchParents = true)
  173. {
  174. return $this->ext->getTemplateVars->getTemplateVars($this, $varName, $_ptr, $searchParents);
  175. }
  176. /**
  177. * gets the object of a Smarty variable
  178. *
  179. * @param string $variable the name of the Smarty variable
  180. * @param Smarty_Internal_Data $_ptr optional pointer to data object
  181. * @param boolean $searchParents search also in parent data
  182. * @param bool $error_enable
  183. *
  184. * @return Smarty_Variable|Smarty_Undefined_Variable the object of the variable
  185. * @deprecated since 3.1.28 please use Smarty_Internal_Data::getTemplateVars() instead.
  186. */
  187. public function getVariable($variable = null, Smarty_Internal_Data $_ptr = null, $searchParents = true, $error_enable = true){
  188. return $this->ext->getTemplateVars->_getVariable($this, $variable, $_ptr, $searchParents, $error_enable);
  189. }
  190. /**
  191. * Follow the parent chain an merge template and config variables
  192. *
  193. * @param \Smarty_Internal_Data|null $data
  194. */
  195. public function _mergeVars(Smarty_Internal_Data $data = null)
  196. {
  197. if (isset($data)) {
  198. if (!empty($this->tpl_vars)) {
  199. $data->tpl_vars = array_merge($this->tpl_vars, $data->tpl_vars);
  200. }
  201. if (!empty($this->config_vars)) {
  202. $data->config_vars = array_merge($this->config_vars, $data->config_vars);
  203. }
  204. } else {
  205. $data = $this;
  206. }
  207. if (isset($this->parent)) {
  208. $this->parent->_mergeVars($data);
  209. }
  210. }
  211. /**
  212. * Handle unknown class methods
  213. *
  214. * @param string $name unknown method-name
  215. * @param array $args argument array
  216. *
  217. * @return mixed
  218. * @throws SmartyException
  219. */
  220. public function __call($name, $args)
  221. {
  222. return $this->ext->_callExternalMethod($this, $name, $args);
  223. }
  224. }