From d6766ec11ed35869a0e734ffa5d95f1447af158e Mon Sep 17 00:00:00 2001 From: mohrt Date: Fri, 24 Jan 2003 15:02:15 +0000 Subject: [PATCH] put objects in own array, add object param format support, change object syntax from foo.bar to foo->bar --- Smarty.class.php | 22 ++++++++++------------ Smarty_Compiler.class.php | 26 ++++++++++++++++---------- libs/Smarty.class.php | 22 ++++++++++------------ libs/Smarty_Compiler.class.php | 26 ++++++++++++++++---------- 4 files changed, 52 insertions(+), 44 deletions(-) diff --git a/Smarty.class.php b/Smarty.class.php index ccd9258f..778c70e4 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -194,7 +194,7 @@ class Smarty var $_cache_info = array(); // info that makes up a cache file var $_file_perms = 0644; // default file permissions var $_dir_perms = 0771; // default dir permissions - var $_object_wrapper = false; // default object params structure + var $_reg_objects = array(); // registered objects var $_plugins = array( // table keeping track of plugins 'modifier' => array(), 'function' => array(), @@ -338,10 +338,10 @@ class Smarty Function: register_object Purpose: Registers object to be used in templates \*======================================================================*/ - function register_object($object, &$object_impl) - { - $this->_plugins['object'][$object] = - array(&$object_impl, null, null, false); + function register_object($object, &$object_impl, $smarty_args = true) + { + $this->_reg_objects[$object] = + array(&$object_impl, $smarty_args); } /*======================================================================*\ @@ -350,7 +350,7 @@ class Smarty \*======================================================================*/ function unregister_object($object) { - unset($this->_plugins['object'][$object]); + unset($this->_reg_objects[$object]); } @@ -1138,6 +1138,7 @@ function _generate_debug_output() { $smarty_compiler->secure_dir = $this->secure_dir; $smarty_compiler->security_settings = $this->security_settings; $smarty_compiler->trusted_dir = $this->trusted_dir; + $smarty_compiler->_reg_objects = &$this->_reg_objects; $smarty_compiler->_plugins = &$this->_plugins; $smarty_compiler->_tpl_vars = &$this->_tpl_vars; $smarty_compiler->default_modifiers = $this->default_modifiers; @@ -1904,13 +1905,10 @@ function _run_insert_handler($args) * whether the dynamically registered plugin function has been * checked for existence yet or not. */ - if (isset($plugin)) { + if (isset($plugin)) { if (!$plugin[3]) { - // no line number, see if it is valid - if ($type == 'function' && !function_exists($plugin[0])) { - $this->_trigger_plugin_error("$type '$name' is not implemented", $tpl_file, $tpl_line, __FILE__, __LINE__); - } elseif ($type == 'object' && !is_object($plugin[0])) { - $this->_trigger_plugin_error("$type '$name' is not an object", $tpl_file, $tpl_line, __FILE__, __LINE__); + if (!function_exists($plugin[0])) { + $this->_trigger_plugin_error("$type '$name' is not implemented", $tpl_file, $tpl_line); } else { $plugin[1] = $tpl_file; $plugin[2] = $tpl_line; diff --git a/Smarty_Compiler.class.php b/Smarty_Compiler.class.php index 49d2cd65..4a154b0c 100644 --- a/Smarty_Compiler.class.php +++ b/Smarty_Compiler.class.php @@ -147,7 +147,7 @@ class Smarty_Compiler extends Smarty { // matches valid registered object: // foo.bar - $this->_reg_obj_regexp = '[a-zA-Z_]\w*\.[a-zA-Z_]\w*'; + $this->_reg_obj_regexp = '[a-zA-Z_]\w*->[a-zA-Z_]\w*'; // matches valid parameter values: // true @@ -647,8 +647,7 @@ class Smarty_Compiler extends Smarty { \*======================================================================*/ function _compile_registered_object_tag($tag_command, $attrs, $tag_modifier) { - list($object, $obj_comp) = explode('.', $tag_command); - $this->_add_plugin('object', $object); + list($object, $obj_comp) = explode('->', $tag_command); $arg_list = array(); if(count($attrs)) { @@ -656,6 +655,7 @@ class Smarty_Compiler extends Smarty { foreach ($attrs as $arg_name => $arg_value) { if($arg_name == 'assign') { $_assign_var = $arg_value; + unset($attrs['assign']); continue; } if (is_bool($arg_value)) @@ -663,15 +663,21 @@ class Smarty_Compiler extends Smarty { $arg_list[] = "'$arg_name' => $arg_value"; } } - - if(!$this->_plugins['object'][$object][0]) { - $this->_trigger_plugin_error("Smarty error: Registered '$object' is not an object"); - } elseif(method_exists($this->_plugins['object'][$object][0], $obj_comp)) { + + if(!$this->_reg_objects[$object][0]) { + $this->trigger_error("Smarty error: registered '$object' is not an object"); + } elseif(method_exists($this->_reg_objects[$object][0], $obj_comp)) { // method - $return = "\$this->_plugins['object']['$object'][0]->$obj_comp(array(".implode(',', (array)$arg_list)."), \$this)"; + if($this->_reg_objects[$object][1]) { + // smarty object argument format + $return = "\$this->_reg_objects['$object'][0]->$obj_comp(array(".implode(',', (array)$arg_list)."), \$this)"; + } else { + // traditional argument format + $return = "\$this->_reg_objects['$object'][0]->$obj_comp(".implode(',', array_values($attrs)).")"; + } } else { // property - $return = "\$this->_plugins['object']['$object'][0]->$obj_comp"; + $return = "\$this->_reg_objects['$object'][0]->$obj_comp"; } if($tag_modifier != '') { @@ -681,7 +687,7 @@ class Smarty_Compiler extends Smarty { if($_assign_var) { return "assign('" . $this->_dequote($_assign_var) ."', $return); ?>\n"; } else { - return '\n"; + return '\n"; } } diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index ccd9258f..778c70e4 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -194,7 +194,7 @@ class Smarty var $_cache_info = array(); // info that makes up a cache file var $_file_perms = 0644; // default file permissions var $_dir_perms = 0771; // default dir permissions - var $_object_wrapper = false; // default object params structure + var $_reg_objects = array(); // registered objects var $_plugins = array( // table keeping track of plugins 'modifier' => array(), 'function' => array(), @@ -338,10 +338,10 @@ class Smarty Function: register_object Purpose: Registers object to be used in templates \*======================================================================*/ - function register_object($object, &$object_impl) - { - $this->_plugins['object'][$object] = - array(&$object_impl, null, null, false); + function register_object($object, &$object_impl, $smarty_args = true) + { + $this->_reg_objects[$object] = + array(&$object_impl, $smarty_args); } /*======================================================================*\ @@ -350,7 +350,7 @@ class Smarty \*======================================================================*/ function unregister_object($object) { - unset($this->_plugins['object'][$object]); + unset($this->_reg_objects[$object]); } @@ -1138,6 +1138,7 @@ function _generate_debug_output() { $smarty_compiler->secure_dir = $this->secure_dir; $smarty_compiler->security_settings = $this->security_settings; $smarty_compiler->trusted_dir = $this->trusted_dir; + $smarty_compiler->_reg_objects = &$this->_reg_objects; $smarty_compiler->_plugins = &$this->_plugins; $smarty_compiler->_tpl_vars = &$this->_tpl_vars; $smarty_compiler->default_modifiers = $this->default_modifiers; @@ -1904,13 +1905,10 @@ function _run_insert_handler($args) * whether the dynamically registered plugin function has been * checked for existence yet or not. */ - if (isset($plugin)) { + if (isset($plugin)) { if (!$plugin[3]) { - // no line number, see if it is valid - if ($type == 'function' && !function_exists($plugin[0])) { - $this->_trigger_plugin_error("$type '$name' is not implemented", $tpl_file, $tpl_line, __FILE__, __LINE__); - } elseif ($type == 'object' && !is_object($plugin[0])) { - $this->_trigger_plugin_error("$type '$name' is not an object", $tpl_file, $tpl_line, __FILE__, __LINE__); + if (!function_exists($plugin[0])) { + $this->_trigger_plugin_error("$type '$name' is not implemented", $tpl_file, $tpl_line); } else { $plugin[1] = $tpl_file; $plugin[2] = $tpl_line; diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index 49d2cd65..4a154b0c 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -147,7 +147,7 @@ class Smarty_Compiler extends Smarty { // matches valid registered object: // foo.bar - $this->_reg_obj_regexp = '[a-zA-Z_]\w*\.[a-zA-Z_]\w*'; + $this->_reg_obj_regexp = '[a-zA-Z_]\w*->[a-zA-Z_]\w*'; // matches valid parameter values: // true @@ -647,8 +647,7 @@ class Smarty_Compiler extends Smarty { \*======================================================================*/ function _compile_registered_object_tag($tag_command, $attrs, $tag_modifier) { - list($object, $obj_comp) = explode('.', $tag_command); - $this->_add_plugin('object', $object); + list($object, $obj_comp) = explode('->', $tag_command); $arg_list = array(); if(count($attrs)) { @@ -656,6 +655,7 @@ class Smarty_Compiler extends Smarty { foreach ($attrs as $arg_name => $arg_value) { if($arg_name == 'assign') { $_assign_var = $arg_value; + unset($attrs['assign']); continue; } if (is_bool($arg_value)) @@ -663,15 +663,21 @@ class Smarty_Compiler extends Smarty { $arg_list[] = "'$arg_name' => $arg_value"; } } - - if(!$this->_plugins['object'][$object][0]) { - $this->_trigger_plugin_error("Smarty error: Registered '$object' is not an object"); - } elseif(method_exists($this->_plugins['object'][$object][0], $obj_comp)) { + + if(!$this->_reg_objects[$object][0]) { + $this->trigger_error("Smarty error: registered '$object' is not an object"); + } elseif(method_exists($this->_reg_objects[$object][0], $obj_comp)) { // method - $return = "\$this->_plugins['object']['$object'][0]->$obj_comp(array(".implode(',', (array)$arg_list)."), \$this)"; + if($this->_reg_objects[$object][1]) { + // smarty object argument format + $return = "\$this->_reg_objects['$object'][0]->$obj_comp(array(".implode(',', (array)$arg_list)."), \$this)"; + } else { + // traditional argument format + $return = "\$this->_reg_objects['$object'][0]->$obj_comp(".implode(',', array_values($attrs)).")"; + } } else { // property - $return = "\$this->_plugins['object']['$object'][0]->$obj_comp"; + $return = "\$this->_reg_objects['$object'][0]->$obj_comp"; } if($tag_modifier != '') { @@ -681,7 +687,7 @@ class Smarty_Compiler extends Smarty { if($_assign_var) { return "assign('" . $this->_dequote($_assign_var) ."', $return); ?>\n"; } else { - return '\n"; + return '\n"; } }