From ab5d8d4e07bb3c8230d0285ef8902ef1979fce51 Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 18 Oct 2018 02:39:34 +0200 Subject: Updating Smarty --- .../sysplugins/smarty_internal_method_literals.php | 100 +++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 lib/smarty/sysplugins/smarty_internal_method_literals.php (limited to 'lib/smarty/sysplugins/smarty_internal_method_literals.php') diff --git a/lib/smarty/sysplugins/smarty_internal_method_literals.php b/lib/smarty/sysplugins/smarty_internal_method_literals.php new file mode 100644 index 0000000..bfa3f58 --- /dev/null +++ b/lib/smarty/sysplugins/smarty_internal_method_literals.php @@ -0,0 +1,100 @@ +_getSmartyObj(); + return (array)$smarty->literals; + } + + /** + * Add literals + * + * @api Smarty::addLiterals() + * + * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj + * @param array|string $literals literal or list of literals + * to addto add + * + * @return \Smarty|\Smarty_Internal_Template + * @throws \SmartyException + */ + public function addLiterals(Smarty_Internal_TemplateBase $obj, $literals = null) + { + if (isset($literals)) { + $this->set($obj->_getSmartyObj(), (array)$literals); + } + return $obj; + } + + /** + * Set literals + * + * @api Smarty::setLiterals() + * + * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj + * @param array|string $literals literal or list of literals + * to setto set + * + * @return \Smarty|\Smarty_Internal_Template + * @throws \SmartyException + */ + public function setLiterals(Smarty_Internal_TemplateBase $obj, $literals = null) + { + $smarty = $obj->_getSmartyObj(); + $smarty->literals = array(); + if (!empty($literals)) { + $this->set($smarty, (array)$literals); + } + return $obj; + } + + /** + * common setter for literals for easier handling of duplicates the + * Smarty::$literals array gets filled with identical key values + * + * @param \Smarty $smarty + * @param array $literals + * + * @throws \SmartyException + */ + private function set(Smarty $smarty, $literals) + { + $literals = array_combine($literals, $literals); + $error = isset($literals[ $smarty->left_delimiter ]) ? array($smarty->left_delimiter) : array(); + $error = isset($literals[ $smarty->right_delimiter ]) ? $error[] = $smarty->right_delimiter : $error; + if (!empty($error)) { + throw new SmartyException( + 'User defined literal(s) "' . $error . + '" may not be identical with left or right delimiter' + ); + } + $smarty->literals = array_merge((array)$smarty->literals, (array)$literals); + } +} -- cgit v1.2.3