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_method_literals.php 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Smarty Method GetLiterals
  4. *
  5. * Smarty::getLiterals() method
  6. *
  7. * @package Smarty
  8. * @subpackage PluginsInternal
  9. * @author Uwe Tews
  10. */
  11. class Smarty_Internal_Method_Literals
  12. {
  13. /**
  14. * Valid for Smarty and template object
  15. *
  16. * @var int
  17. */
  18. public $objMap = 3;
  19. /**
  20. * Get literals
  21. *
  22. * @api Smarty::getLiterals()
  23. *
  24. * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
  25. *
  26. * @return array list of literals
  27. */
  28. public function getLiterals(Smarty_Internal_TemplateBase $obj)
  29. {
  30. $smarty = $obj->_getSmartyObj();
  31. return (array)$smarty->literals;
  32. }
  33. /**
  34. * Add literals
  35. *
  36. * @api Smarty::addLiterals()
  37. *
  38. * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
  39. * @param array|string $literals literal or list of literals
  40. * to add
  41. *
  42. * @return \Smarty|\Smarty_Internal_Template
  43. * @throws \SmartyException
  44. */
  45. public function addLiterals(Smarty_Internal_TemplateBase $obj, $literals = null)
  46. {
  47. if (isset($literals)) {
  48. $this->set($obj->_getSmartyObj(), (array)$literals);
  49. }
  50. return $obj;
  51. }
  52. /**
  53. * Set literals
  54. *
  55. * @api Smarty::setLiterals()
  56. *
  57. * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
  58. * @param array|string $literals literal or list of literals
  59. * to set
  60. *
  61. * @return \Smarty|\Smarty_Internal_Template
  62. * @throws \SmartyException
  63. */
  64. public function setLiterals(Smarty_Internal_TemplateBase $obj, $literals = null)
  65. {
  66. $smarty = $obj->_getSmartyObj();
  67. $smarty->literals = array();
  68. if (!empty($literals)) {
  69. $this->set($smarty, (array)$literals);
  70. }
  71. return $obj;
  72. }
  73. /**
  74. * common setter for literals for easier handling of duplicates the
  75. * Smarty::$literals array gets filled with identical key values
  76. *
  77. * @param \Smarty $smarty
  78. * @param array $literals
  79. *
  80. * @throws \SmartyException
  81. */
  82. private function set(Smarty $smarty, $literals)
  83. {
  84. $literals = array_combine($literals, $literals);
  85. $error = isset($literals[ $smarty->left_delimiter ]) ? array($smarty->left_delimiter) : array();
  86. $error = isset($literals[ $smarty->right_delimiter ]) ? $error[] = $smarty->right_delimiter : $error;
  87. if (!empty($error)) {
  88. throw new SmartyException('User defined literal(s) "' . $error .
  89. '" may not be identical with left or right delimiter');
  90. }
  91. $smarty->literals = array_merge((array)$smarty->literals, (array)$literals);
  92. }
  93. }