cvs: pear /MDB2 MDB2.php
| From: | Lukas Smith | Date: | Sun, 13 Mar 2005 20:25:40 +0000 |
| Subject: | cvs: pear /MDB2 MDB2.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-30253@lists.php.net to get a copy of this message | ||
lsmith Sun Mar 13 15:25:40 2005 EDT
Modified files:
/pear/MDB2 MDB2.php
Log:
- added __call() support
http://cvs.php.net/diff.php/pear/MDB2/MDB2.php?r1=1.84&r2=1.85&ty=u
Index: pear/MDB2/MDB2.php
diff -u pear/MDB2/MDB2.php:1.84 pear/MDB2/MDB2.php:1.85
--- pear/MDB2/MDB2.php:1.84 Tue Mar 8 11:44:16 2005
+++ pear/MDB2/MDB2.php Sun Mar 13 15:25:39 2005
@@ -43,7 +43,7 @@
// | Author: Lukas Smith <smith@backendmedia.com> |
// +----------------------------------------------------------------------+
//
-// $Id: MDB2.php,v 1.84 2005/03/08 16:44:16 lsmith Exp $
+// $Id: MDB2.php,v 1.85 2005/03/13 20:25:39 lsmith Exp $
//
/**
@@ -889,7 +889,7 @@
* $options['result_class'] -> class used for result sets
* $options['buffered_result_class'] -> class used for buffered result sets
* $options['result_wrap_class'] -> class used to wrap result sets into
- * $options['result_buffering'] -> boolean should results be buffered or not?
+ * $options['result_buffering'] -> boolean|integer should results be buffered or
not?
* $options['fetch_class'] -> class to use when fetch mode object is used
* $options['persistent'] -> boolean persistent connection?
* $options['debug'] -> integer numeric debug level
@@ -901,6 +901,7 @@
* $options['use_transactions'] -> boolean
* $options['decimal_places'] -> integer
* $options['portability'] -> portability constant
+ * $options['modules'] -> short to long module name mapping for __call()
* @var array
* @access public
*/
@@ -922,6 +923,13 @@
'use_transactions' => false,
'decimal_places' => 2,
'portability' => MDB2_PORTABILITY_ALL,
+ 'modules' => array(
+ 'ex' => 'Extended',
+ 'dt' => 'Datatype',
+ 'mg' => 'Manager',
+ 'rv' => 'Reverse',
+ 'na' => 'Native',
+ ),
);
/**
@@ -1023,6 +1031,13 @@
var $blobs = array();
/**
+ * array of module instances
+ * @var array
+ * @access private
+ */
+ var $modules = array();
+
+ /**
* determines of the PHP4 destructor emulation has been enabled yet
* @var array
* @access private
@@ -1486,18 +1501,56 @@
'unable to load module: '.$module.' into property:
'.$property);
}
$this->{$property} =& new $class_name($this->db_index);
+ $this->modules[$module] =& $this->{$property};
if ($version) {
// this wil be used in the connect method to determine if the module
- // needs to be loaded with a different version
+ // needs to be loaded with a different version if the server
+ // version changed in between connects
$this->loaded_version_modules[] = $property;
}
- } elseif (!is_object($this->{$property})) {
- return $this->raiseError(MDB2_ERROR_LOADMODULE, null, null,
- 'unable to load module: '.$module.' into property:
'.$property);
}
+
return $this->{$property};
}
+ /**
+ * Calls a module method using the __call magic method
+ *
+ * @param string Method name.
+ * @param array Arguments.
+ * @return mixed Returned value.
+ */
+ function __call($method, $params)
+ {
+ $module = null;
+ if(preg_match('/^([a-z]+)([A-Z])(.*)$/', $method, $match)
+ && isset($this->options['modules'][$match[1]])
+ ) {
+ $module = $this->options['modules'][$match[1]];
+ $method = strtolower($match[2]).$match[3];
+ if (!isset($this->modules[$module]) || !is_object($this->modules[$module])) {
+ $result =& $this->loadModule($module);
+ if (PEAR::isError($result)) {
+ return $result;
+ }
+ }
+ } else {
+ foreach($this->modules as $key => $foo) {
+ if (is_object($this->modules[$key])
+ && method_exists($this->modules[$key], $method)
+ ) {
+ $module = $key;
+ break;
+ }
+ }
+ }
+ if (is_null($module)) {
+ return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
+ $method.': method not implemented');
+ }
+ return call_user_func_array(array(&$this->modules[$module], $method), $params);
+ }
+
// }}}
// {{{ beginTransaction()