put objects in own array, add object param format support, change

object syntax from foo.bar to foo->bar
This commit is contained in:
mohrt
2003-01-24 15:02:15 +00:00
parent 95d6a268aa
commit d6766ec11e
4 changed files with 52 additions and 44 deletions

View File

@@ -194,7 +194,7 @@ class Smarty
var $_cache_info = array(); // info that makes up a cache file var $_cache_info = array(); // info that makes up a cache file
var $_file_perms = 0644; // default file permissions var $_file_perms = 0644; // default file permissions
var $_dir_perms = 0771; // default dir 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 var $_plugins = array( // table keeping track of plugins
'modifier' => array(), 'modifier' => array(),
'function' => array(), 'function' => array(),
@@ -338,10 +338,10 @@ class Smarty
Function: register_object Function: register_object
Purpose: Registers object to be used in templates Purpose: Registers object to be used in templates
\*======================================================================*/ \*======================================================================*/
function register_object($object, &$object_impl) function register_object($object, &$object_impl, $smarty_args = true)
{ {
$this->_plugins['object'][$object] = $this->_reg_objects[$object] =
array(&$object_impl, null, null, false); array(&$object_impl, $smarty_args);
} }
/*======================================================================*\ /*======================================================================*\
@@ -350,7 +350,7 @@ class Smarty
\*======================================================================*/ \*======================================================================*/
function unregister_object($object) 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->secure_dir = $this->secure_dir;
$smarty_compiler->security_settings = $this->security_settings; $smarty_compiler->security_settings = $this->security_settings;
$smarty_compiler->trusted_dir = $this->trusted_dir; $smarty_compiler->trusted_dir = $this->trusted_dir;
$smarty_compiler->_reg_objects = &$this->_reg_objects;
$smarty_compiler->_plugins = &$this->_plugins; $smarty_compiler->_plugins = &$this->_plugins;
$smarty_compiler->_tpl_vars = &$this->_tpl_vars; $smarty_compiler->_tpl_vars = &$this->_tpl_vars;
$smarty_compiler->default_modifiers = $this->default_modifiers; $smarty_compiler->default_modifiers = $this->default_modifiers;
@@ -1906,11 +1907,8 @@ function _run_insert_handler($args)
*/ */
if (isset($plugin)) { if (isset($plugin)) {
if (!$plugin[3]) { if (!$plugin[3]) {
// no line number, see if it is valid if (!function_exists($plugin[0])) {
if ($type == 'function' && !function_exists($plugin[0])) { $this->_trigger_plugin_error("$type '$name' is not implemented", $tpl_file, $tpl_line);
$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__);
} else { } else {
$plugin[1] = $tpl_file; $plugin[1] = $tpl_file;
$plugin[2] = $tpl_line; $plugin[2] = $tpl_line;

View File

@@ -147,7 +147,7 @@ class Smarty_Compiler extends Smarty {
// matches valid registered object: // matches valid registered object:
// foo.bar // 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: // matches valid parameter values:
// true // true
@@ -647,8 +647,7 @@ class Smarty_Compiler extends Smarty {
\*======================================================================*/ \*======================================================================*/
function _compile_registered_object_tag($tag_command, $attrs, $tag_modifier) function _compile_registered_object_tag($tag_command, $attrs, $tag_modifier)
{ {
list($object, $obj_comp) = explode('.', $tag_command); list($object, $obj_comp) = explode('->', $tag_command);
$this->_add_plugin('object', $object);
$arg_list = array(); $arg_list = array();
if(count($attrs)) { if(count($attrs)) {
@@ -656,6 +655,7 @@ class Smarty_Compiler extends Smarty {
foreach ($attrs as $arg_name => $arg_value) { foreach ($attrs as $arg_name => $arg_value) {
if($arg_name == 'assign') { if($arg_name == 'assign') {
$_assign_var = $arg_value; $_assign_var = $arg_value;
unset($attrs['assign']);
continue; continue;
} }
if (is_bool($arg_value)) if (is_bool($arg_value))
@@ -664,14 +664,20 @@ class Smarty_Compiler extends Smarty {
} }
} }
if(!$this->_plugins['object'][$object][0]) { if(!$this->_reg_objects[$object][0]) {
$this->_trigger_plugin_error("Smarty error: Registered '$object' is not an object"); $this->trigger_error("Smarty error: registered '$object' is not an object");
} elseif(method_exists($this->_plugins['object'][$object][0], $obj_comp)) { } elseif(method_exists($this->_reg_objects[$object][0], $obj_comp)) {
// method // 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 { } else {
// property // property
$return = "\$this->_plugins['object']['$object'][0]->$obj_comp"; $return = "\$this->_reg_objects['$object'][0]->$obj_comp";
} }
if($tag_modifier != '') { if($tag_modifier != '') {

View File

@@ -194,7 +194,7 @@ class Smarty
var $_cache_info = array(); // info that makes up a cache file var $_cache_info = array(); // info that makes up a cache file
var $_file_perms = 0644; // default file permissions var $_file_perms = 0644; // default file permissions
var $_dir_perms = 0771; // default dir 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 var $_plugins = array( // table keeping track of plugins
'modifier' => array(), 'modifier' => array(),
'function' => array(), 'function' => array(),
@@ -338,10 +338,10 @@ class Smarty
Function: register_object Function: register_object
Purpose: Registers object to be used in templates Purpose: Registers object to be used in templates
\*======================================================================*/ \*======================================================================*/
function register_object($object, &$object_impl) function register_object($object, &$object_impl, $smarty_args = true)
{ {
$this->_plugins['object'][$object] = $this->_reg_objects[$object] =
array(&$object_impl, null, null, false); array(&$object_impl, $smarty_args);
} }
/*======================================================================*\ /*======================================================================*\
@@ -350,7 +350,7 @@ class Smarty
\*======================================================================*/ \*======================================================================*/
function unregister_object($object) 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->secure_dir = $this->secure_dir;
$smarty_compiler->security_settings = $this->security_settings; $smarty_compiler->security_settings = $this->security_settings;
$smarty_compiler->trusted_dir = $this->trusted_dir; $smarty_compiler->trusted_dir = $this->trusted_dir;
$smarty_compiler->_reg_objects = &$this->_reg_objects;
$smarty_compiler->_plugins = &$this->_plugins; $smarty_compiler->_plugins = &$this->_plugins;
$smarty_compiler->_tpl_vars = &$this->_tpl_vars; $smarty_compiler->_tpl_vars = &$this->_tpl_vars;
$smarty_compiler->default_modifiers = $this->default_modifiers; $smarty_compiler->default_modifiers = $this->default_modifiers;
@@ -1906,11 +1907,8 @@ function _run_insert_handler($args)
*/ */
if (isset($plugin)) { if (isset($plugin)) {
if (!$plugin[3]) { if (!$plugin[3]) {
// no line number, see if it is valid if (!function_exists($plugin[0])) {
if ($type == 'function' && !function_exists($plugin[0])) { $this->_trigger_plugin_error("$type '$name' is not implemented", $tpl_file, $tpl_line);
$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__);
} else { } else {
$plugin[1] = $tpl_file; $plugin[1] = $tpl_file;
$plugin[2] = $tpl_line; $plugin[2] = $tpl_line;

View File

@@ -147,7 +147,7 @@ class Smarty_Compiler extends Smarty {
// matches valid registered object: // matches valid registered object:
// foo.bar // 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: // matches valid parameter values:
// true // true
@@ -647,8 +647,7 @@ class Smarty_Compiler extends Smarty {
\*======================================================================*/ \*======================================================================*/
function _compile_registered_object_tag($tag_command, $attrs, $tag_modifier) function _compile_registered_object_tag($tag_command, $attrs, $tag_modifier)
{ {
list($object, $obj_comp) = explode('.', $tag_command); list($object, $obj_comp) = explode('->', $tag_command);
$this->_add_plugin('object', $object);
$arg_list = array(); $arg_list = array();
if(count($attrs)) { if(count($attrs)) {
@@ -656,6 +655,7 @@ class Smarty_Compiler extends Smarty {
foreach ($attrs as $arg_name => $arg_value) { foreach ($attrs as $arg_name => $arg_value) {
if($arg_name == 'assign') { if($arg_name == 'assign') {
$_assign_var = $arg_value; $_assign_var = $arg_value;
unset($attrs['assign']);
continue; continue;
} }
if (is_bool($arg_value)) if (is_bool($arg_value))
@@ -664,14 +664,20 @@ class Smarty_Compiler extends Smarty {
} }
} }
if(!$this->_plugins['object'][$object][0]) { if(!$this->_reg_objects[$object][0]) {
$this->_trigger_plugin_error("Smarty error: Registered '$object' is not an object"); $this->trigger_error("Smarty error: registered '$object' is not an object");
} elseif(method_exists($this->_plugins['object'][$object][0], $obj_comp)) { } elseif(method_exists($this->_reg_objects[$object][0], $obj_comp)) {
// method // 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 { } else {
// property // property
$return = "\$this->_plugins['object']['$object'][0]->$obj_comp"; $return = "\$this->_reg_objects['$object'][0]->$obj_comp";
} }
if($tag_modifier != '') { if($tag_modifier != '') {