From 49d54c0c3199fb8e380ce68f8fb08a308ddf56a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Eduardo?= Date: Mon, 25 Dec 2017 16:58:41 -0500 Subject: =?UTF-8?q?migraci=C3=B3n=20mayor=20a=20smarty=20PHP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smarty_internal_extension_handler.php | 147 +++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 smarty/sysplugins/smarty_internal_extension_handler.php (limited to 'smarty/sysplugins/smarty_internal_extension_handler.php') diff --git a/smarty/sysplugins/smarty_internal_extension_handler.php b/smarty/sysplugins/smarty_internal_extension_handler.php new file mode 100644 index 0000000..edeb395 --- /dev/null +++ b/smarty/sysplugins/smarty_internal_extension_handler.php @@ -0,0 +1,147 @@ + 0, 'DefaultModifiers' => 0, 'ConfigVars' => 0, + 'DebugTemplate' => 0, 'RegisteredObject' => 0, 'StreamVariable' => 0, + 'TemplateVars' => 0,);# + + private $resolvedProperties = array(); + + /** + * Call external Method + * + * @param \Smarty_Internal_Data $data + * @param string $name external method names + * @param array $args argument array + * + * @return mixed + * @throws SmartyException + */ + public function _callExternalMethod(Smarty_Internal_Data $data, $name, $args) + { + /* @var Smarty $data ->smarty */ + $smarty = isset($data->smarty) ? $data->smarty : $data; + if (!isset($smarty->ext->$name)) { + $class = 'Smarty_Internal_Method_' . ucfirst($name); + if (preg_match('/^(set|get)([A-Z].*)$/', $name, $match)) { + if (!isset($this->_property_info[ $prop = $match[ 2 ] ])) { + // convert camel case to underscored name + $this->resolvedProperties[ $prop ] = $pn = strtolower(join('_', + preg_split('/([A-Z][^A-Z]*)/', $prop, + - 1, PREG_SPLIT_NO_EMPTY | + PREG_SPLIT_DELIM_CAPTURE))); + $this->_property_info[ $prop ] = property_exists($data, $pn) ? 1 : + ($data->_objType == 2 && property_exists($smarty, $pn) ? 2 : 0); + } + if ($this->_property_info[ $prop ]) { + $pn = $this->resolvedProperties[ $prop ]; + if ($match[ 1 ] == 'get') { + return $this->_property_info[ $prop ] == 1 ? $data->$pn : $data->smarty->$pn; + } else { + return $this->_property_info[ $prop ] == 1 ? $data->$pn = $args[ 0 ] : + $data->smarty->$pn = $args[ 0 ]; + } + } elseif (!class_exists($class)) { + throw new SmartyException("property '$pn' does not exist."); + } + } + if (class_exists($class)) { + $callback = array($smarty->ext->$name = new $class(), $name); + } + } else { + $callback = array($smarty->ext->$name, $name); + } + array_unshift($args, $data); + if (isset($callback) && $callback[ 0 ]->objMap | $data->_objType) { + return call_user_func_array($callback, $args); + } + return call_user_func_array(array(new Smarty_Internal_Undefined(), $name), $args); + } + + /** + * set extension property + * + * @param string $property_name property name + * @param mixed $value value + * + * @throws SmartyException + */ + public function __set($property_name, $value) + { + $this->$property_name = $value; + } + + /** + * get extension object + * + * @param string $property_name property name + * + * @return mixed|Smarty_Template_Cached + * @throws SmartyException + */ + public function __get($property_name) + { + // object properties of runtime template extensions will start with '_' + if ($property_name[ 0 ] == '_') { + $class = 'Smarty_Internal_Runtime_' . ucfirst(substr($property_name, 1)); + } else { + $class = 'Smarty_Internal_Method_' . ucfirst($property_name); + } + return $this->$property_name = new $class(); + } + + /** + * Call error handler for undefined method + * + * @param string $name unknown method-name + * @param array $args argument array + * + * @return mixed + * @throws SmartyException + */ + public function __call($name, $args) + { + return call_user_func_array(array(new Smarty_Internal_Undefined(), $name), array($this)); + } + +} \ No newline at end of file -- cgit v1.2.3