smarty_data.php (1655B)
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 */ 18 class Smarty_Data extends Smarty_Internal_Data 19 { 20 /** 21 * Counter 22 * 23 * @var int 24 */ 25 static $count = 0; 26 27 /** 28 * Data block name 29 * 30 * @var string 31 */ 32 public $dataObjectName = ''; 33 /** 34 * Smarty object 35 * 36 * @var Smarty 37 */ 38 public $smarty = null; 39 40 /** 41 * create Smarty data object 42 * 43 * @param Smarty|array $_parent parent template 44 * @param Smarty|Smarty_Internal_Template $smarty global smarty instance 45 * @param string $name optional data block name 46 * 47 * @throws SmartyException 48 */ 49 public function __construct($_parent = null, $smarty = null, $name = null) 50 { 51 self::$count ++; 52 $this->dataObjectName = 'Data_object ' . (isset($name) ? "'{$name}'" : self::$count); 53 $this->smarty = $smarty; 54 if (is_object($_parent)) { 55 // when object set up back pointer 56 $this->parent = $_parent; 57 } elseif (is_array($_parent)) { 58 // set up variable values 59 foreach ($_parent as $_key => $_val) { 60 $this->tpl_vars[$_key] = new Smarty_Variable($_val); 61 } 62 } elseif ($_parent != null) { 63 throw new SmartyException("Wrong type for template variables"); 64 } 65 } 66 }