1<?php
2/**
3 * Smarty Plugin Data
4 * This file contains the data object
5 *
6 * @package    Smarty
7 * @subpackage Template
8 * @author     Uwe Tews
9 */
10
11/**
12 * class for the Smarty data object
13 * The Smarty data object will hold Smarty variables in the current scope
14 *
15 * @package    Smarty
16 * @subpackage Template
17 */
18class Smarty_Data extends Smarty_Internal_Data
19{
20    /**
21     * Counter
22     *
23     * @var int
24     */
25    public static $count = 0;
26
27    /**
28     * Data block name
29     *
30     * @var string
31     */
32    public $dataObjectName = '';
33
34    /**
35     * Smarty object
36     *
37     * @var Smarty
38     */
39    public $smarty = null;
40
41    /**
42     * create Smarty data object
43     *
44     * @param Smarty|array                    $_parent parent template
45     * @param Smarty|Smarty_Internal_Template $smarty  global smarty instance
46     * @param string                          $name    optional data block name
47     *
48     * @throws SmartyException
49     */
50    public function __construct($_parent = null, $smarty = null, $name = null)
51    {
52        parent::__construct();
53        self::$count++;
54        $this->dataObjectName = 'Data_object ' . (isset($name) ? "'{$name}'" : self::$count);
55        $this->smarty = $smarty;
56        if (is_object($_parent)) {
57            // when object set up back pointer
58            $this->parent = $_parent;
59        } elseif (is_array($_parent)) {
60            // set up variable values
61            foreach ($_parent as $_key => $_val) {
62                $this->tpl_vars[ $_key ] = new Smarty_Variable($_val);
63            }
64        } elseif ($_parent !== null) {
65            throw new SmartyException('Wrong type for template variables');
66        }
67    }
68}
69