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_data.php 1.7KB

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