From e1d55a36f903ac260d1d510c30d5bf1b1f2d92c4 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 31 Dec 2005 09:13:31 +0000 Subject: [PATCH] Extracting set() logic out to do_set() --- kernel.php | 54 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/kernel.php b/kernel.php index 0104274..f23f30d 100644 --- a/kernel.php +++ b/kernel.php @@ -294,20 +294,62 @@ class Shared_Object_Framework */ function set($fieldname, $value) { - if (is_array($this->fields["$fieldname"])) + $this->do_set($fieldname, $value, null); + } + + // ################################################################### + /** + * Does the actual setting of the field. set() is defined in each + * module, but this controls the actual data. This is done so that + * there isn't an extra parameter in set() that controls module spaces + * + * @access protected + * + * @param string Field name + * @param mixed Value + * @param string Module name (as referred to in ISSO->modules[]) to place in + */ + function do_set($fieldname, $value, $module) + { + if ($module == null) { - if (method_exists($this, $this->fields["$fieldname"][1])) + $field =& $this->fields["$fieldname"]; + } + else + { + $field =& $this->modules["$module"]->fields["$fieldname"]; + } + + if (is_array($field)) + { + if ($field[1] != null) { - $value = $this->{$this->fields["$fieldname"][1]}($value); + if (preg_match('#^\$(.*)#', $field[1])) + { + $caller = preg_replace('#^\$(.*)->([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)$#e', 'array(&\1, \2)', $field[1]); + } + else + { + $caller = array(&$this, $field[1]); + } + + $value = call_user_func($caller, $value); } - $this->$fieldname = $value; + if ($module == null) + { + $this->$fieldname = $value; + } + else + { + $this->modules["$module"]->$fieldname = $value; + } - $this->fields["$fieldname"][2] = true; + $field[2] = true; } else { - trigger_error('Invalid field `' . $fieldname . '` specified in ISSO->set()', E_USER_ERROR); + trigger_error('Invalid field `' . $module . '.' . $fieldname . '` specified in ISSO->do_set()', E_USER_ERROR); } } -- 2.22.5