Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 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
/**
12
 * Base class with template and variable methods
13
 *
14
 * @package    Smarty
15
 * @subpackage Template
16
 *
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
21
 *
22
 * @method mixed _getConfigVariable(string $varName, bool $errorEnable = true)
23
 * @method mixed getConfigVariable(string $varName, bool $errorEnable = true)
24
 * @method mixed getConfigVars(string $varName = null, bool $searchParents = true)
25
 * @method mixed getGlobal(string $varName = null)
26
 * @method mixed getStreamVariable(string $variable)
27
 * @method Smarty_Internal_Data clearAssign(mixed $tpl_var)
28
 * @method Smarty_Internal_Data clearAllAssign()
29
 * @method Smarty_Internal_Data clearConfig(string $varName = null)
30
 * @method Smarty_Internal_Data configLoad(string $config_file, mixed $sections = null, string $scope = 'local')
31
 */
32
abstract class Smarty_Internal_Data
33
{
34
    /**
35
     * This object type (Smarty = 1, template = 2, data = 4)
36
     *
37
     * @var int
38
     */
39
    public $_objType = 4;
40
 
41
    /**
42
     * name of class used for templates
43
     *
44
     * @var string
45
     */
46
    public $template_class = 'Smarty_Internal_Template';
47
 
48
    /**
49
     * template variables
50
     *
51
     * @var Smarty_Variable[]
52
     */
53
    public $tpl_vars = array();
54
 
55
    /**
56
     * parent template (if any)
57
     *
58
     * @var Smarty|Smarty_Internal_Template|Smarty_Data
59
     */
60
    public $parent = null;
61
 
62
    /**
63
     * configuration settings
64
     *
65
     * @var string[]
66
     */
67
    public $config_vars = array();
68
 
69
    /**
70
     * extension handler
71
     *
72
     * @var Smarty_Internal_Extension_Handler
73
     */
74
    public $ext = null;
75
 
76
    /**
77
     * Smarty_Internal_Data constructor.
78
     *
79
     * Install extension handler
80
     */
81
    public function __construct()
82
    {
83
        $this->ext = new Smarty_Internal_Extension_Handler();
84
        $this->ext->objType = $this->_objType;
85
    }
86
 
87
    /**
88
     * assigns a Smarty variable
89
     *
90
     * @param array|string $tpl_var the template variable name(s)
91
     * @param mixed        $value   the value to assign
92
     * @param boolean      $nocache if true any output of this variable will be not cached
93
     *
94
     * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for
95
     *                              chaining
96
     */
97
    public function assign($tpl_var, $value = null, $nocache = false)
98
    {
99
        if (is_array($tpl_var)) {
100
            foreach ($tpl_var as $_key => $_val) {
101
                $this->assign($_key, $_val, $nocache);
102
            }
103
        } else {
104
            if ($tpl_var !== '') {
105
                if ($this->_objType === 2) {
106
                    /**
107
                     *
108
                     *
109
                     * @var Smarty_Internal_Template $this
110
                     */
111
                    $this->_assignInScope($tpl_var, $value, $nocache);
112
                } else {
113
                    $this->tpl_vars[ $tpl_var ] = new Smarty_Variable($value, $nocache);
114
                }
115
            }
116
        }
117
        return $this;
118
    }
119
 
120
    /**
121
     * appends values to template variables
122
     *
123
     * @api  Smarty::append()
124
     * @link https://www.smarty.net/docs/en/api.append.tpl
125
     *
126
     * @param array|string $tpl_var the template variable name(s)
127
     * @param mixed        $value   the value to append
128
     * @param bool         $merge   flag if array elements shall be merged
129
     * @param bool         $nocache if true any output of this variable will
130
     *                              be not cached
131
     *
132
     * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
133
     */
134
    public function append($tpl_var, $value = null, $merge = false, $nocache = false)
135
    {
136
        return $this->ext->append->append($this, $tpl_var, $value, $merge, $nocache);
137
    }
138
 
139
    /**
140
     * assigns a global Smarty variable
141
     *
142
     * @param string  $varName the global variable name
143
     * @param mixed   $value   the value to assign
144
     * @param boolean $nocache if true any output of this variable will be not cached
145
     *
146
     * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
147
     */
148
    public function assignGlobal($varName, $value = null, $nocache = false)
149
    {
150
        return $this->ext->assignGlobal->assignGlobal($this, $varName, $value, $nocache);
151
    }
152
 
153
    /**
154
     * appends values to template variables by reference
155
     *
156
     * @param string  $tpl_var the template variable name
157
     * @param mixed   &$value  the referenced value to append
158
     * @param boolean $merge   flag if array elements shall be merged
159
     *
160
     * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
161
     */
162
    public function appendByRef($tpl_var, &$value, $merge = false)
163
    {
164
        return $this->ext->appendByRef->appendByRef($this, $tpl_var, $value, $merge);
165
    }
166
 
167
    /**
168
     * assigns values to template variables by reference
169
     *
170
     * @param string  $tpl_var the template variable name
171
     * @param         $value
172
     * @param boolean $nocache if true any output of this variable will be not cached
173
     *
174
     * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
175
     */
176
    public function assignByRef($tpl_var, &$value, $nocache = false)
177
    {
178
        return $this->ext->assignByRef->assignByRef($this, $tpl_var, $value, $nocache);
179
    }
180
 
181
    /**
182
     * Returns a single or all template variables
183
     *
184
     * @api  Smarty::getTemplateVars()
185
     * @link https://www.smarty.net/docs/en/api.get.template.vars.tpl
186
     *
187
     * @param string                                                  $varName       variable name or null
188
     * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr          optional pointer to data object
189
     * @param bool                                                    $searchParents include parent templates?
190
     *
191
     * @return mixed variable value or or array of variables
192
     */
193
    public function getTemplateVars($varName = null, Smarty_Internal_Data $_ptr = null, $searchParents = true)
194
    {
195
        return $this->ext->getTemplateVars->getTemplateVars($this, $varName, $_ptr, $searchParents);
196
    }
197
 
198
    /**
199
     * Follow the parent chain an merge template and config variables
200
     *
201
     * @param \Smarty_Internal_Data|null $data
202
     */
203
    public function _mergeVars(Smarty_Internal_Data $data = null)
204
    {
205
        if (isset($data)) {
206
            if (!empty($this->tpl_vars)) {
207
                $data->tpl_vars = array_merge($this->tpl_vars, $data->tpl_vars);
208
            }
209
            if (!empty($this->config_vars)) {
210
                $data->config_vars = array_merge($this->config_vars, $data->config_vars);
211
            }
212
        } else {
213
            $data = $this;
214
        }
215
        if (isset($this->parent)) {
216
            $this->parent->_mergeVars($data);
217
        }
218
    }
219
 
220
    /**
221
     * Return true if this instance is a Data obj
222
     *
223
     * @return bool
224
     */
225
    public function _isDataObj()
226
    {
227
        return $this->_objType === 4;
228
    }
229
 
230
    /**
231
     * Return true if this instance is a template obj
232
     *
233
     * @return bool
234
     */
235
    public function _isTplObj()
236
    {
237
        return $this->_objType === 2;
238
    }
239
 
240
    /**
241
     * Return true if this instance is a Smarty obj
242
     *
243
     * @return bool
244
     */
245
    public function _isSmartyObj()
246
    {
247
        return $this->_objType === 1;
248
    }
249
 
250
    /**
251
     * Get Smarty object
252
     *
253
     * @return Smarty
254
     */
255
    public function _getSmartyObj()
256
    {
257
        return $this->smarty;
258
    }
259
 
260
    /**
261
     * Handle unknown class methods
262
     *
263
     * @param string $name unknown method-name
264
     * @param array  $args argument array
265
     *
266
     * @return mixed
267
     */
268
    public function __call($name, $args)
269
    {
270
        return $this->ext->_callExternalMethod($this, $name, $args);
271
    }
272
}