// +----------------------------------------------------------------------+ // // $Id: DataObject.php,v 1.62 2003/02/14 15:34:54 alan_k Exp $ // // Object Based LDAP Query Builder and data store // require_once 'PEAR.php'; define('LDAP_DATAOBJECT_MUST', 1); define('LDAP_DATAOBJECT_SINGLE', 2); /* * * storage for connection and result objects, * it is done this way so that print_r()'ing the is smaller, and * it reduces the memory size of the object. * -- future versions may use $this->_connection = & PEAR object.. * although will need speed tests to see how this affects it. * - includes sub arrays * - connections = md5 sum mapp to pear db object * - results = [id] => map to pear db object * - ini = mapping of database to ini file results * - links = mapping of database to links file * - lasterror = pear error objects for last error event. */ $GLOBALS['_LDAP_DATAOBJECT']['RESULTS'] = array(); $GLOBALS['_LDAP_DATAOBJECT']['CONNECTIONS'] = array(); $GLOBALS['_LDAP_DATAOBJECT']['INI'] = array(); $GLOBALS['_LDAP_DATAOBJECT']['LASTERROR'] = null; /** * The main "LDAP_DataObject" class is really a base class for your own tables classes * * // Set up the class by creating an ini file (refer to the manual for more details * [LDAP_DataObject] * database = mysql:/username:password@host/database * schema_location = /home/myapplication/database * class_location = /home/myapplication/DBTables/ * clase_prefix = DBTables_ * * * //Start and initialize...................... - dont forget the & * $config = parse_ini_file('example.ini',true); * $options = &PEAR::setStaticProperty('LDAP_DataObject','options'); * $options = $config['LDAP_DataObject']; * * // example of a class (that does not use the 'auto generated tables data') * class mytable extends LDAP_DataObject { * // mandatory - set the table * var $_database_dsn = "mysql://username:password@localhost/database"; * var $__table = "mytable"; * function _get_table() { * return array( * 'id' => 1, // integer or number * 'name' => 2, // string * ); * } * } * * // use in the application * * * Simple get one row * * $instance = new mytable; * $instance->get("id",12); * echo $instance->somedata; * * * Get multiple rows * * $instance = new mytable; * $instance->whereAdd("ID > 12"); * $instance->whereAdd("ID < 14"); * $instance->find(); * while ($instance->fetch()) { * echo $instance->somedata; * } * * * @package LDAP_DataObject * @author Alan Knowles * @since PHP 4.0 */ Class LDAP_DataObject { /** * The Version - use this to check feature changes * * @access private * @var string */ var $_LDAP_DataObject_version = "0.1"; /** * The LDAP objectclass group (used by table extends) * * @access private * @var string */ var $_objectclasses = ''; // database table /** * The key to use to create new dn's * * @access private * @var string */ var $_key = ''; // database table /* ============================================================= */ /* Major Public Methods */ /* (designed to be optionally then called with parent::method()) */ /* ============================================================= */ /** * Get a result using using the dn. * * for example * $object->get('cn=admin,dc=example,dc=com'); * Returns Number of rows located (usually 1) for success, * and puts all the table columns into this classes variables * * see the fetch example on how to extend this. * * if no value is entered, it is assumed that $key is a value * and get will then use the first key in _get_keys * to obtain the key. * * @param string $k column * @access public * @return int No. of rows */ function get($v) { if (!$GLOBALS['_LDAP_DATAOBJECT_PRODUCTION']) { $this->debug(" $v " , "GET"); } $this->dn = $v; return $this->find(1); } /** * An autoloading, caching static get method using key, value (based on get) * * Usage: * $object = LDAP_DataObject::staticGet("DbTable_mytable",12); * or * $object = LDAP_DataObject::staticGet("DbTable_mytable","name","fred"); * * or write it into your extended class: * function &staticGet($k,$v=NULL) { return LDAP_DataObject::staticGet("This_Class",$k,$v); } * * @param string $class class name * @param string $k column (or value if using _get_keys) * @param string $v value (optional) * @access public * @return object */ function &staticGet($dn) { $cache = &PEAR::getStaticProperty('LDAP_DataObject','cache'); $key = $dn; if (!$GLOBALS['_LDAP_DATAOBJECT_PRODUCTION']) { LDAP_DataObject::debug("$class $key","STATIC GET"); } if (@$cache[$class][$key]) { return $cache[$class][$key]; } if (!$GLOBALS['_LDAP_DATAOBJECT_PRODUCTION']) { LDAP_DataObject::debug("$class $key","STATIC GET"); } $newclass = LDAP_DataObject::_autoloadClass($class); if (!$newclass) { LDAP_DataObject::raiseError("could not autoload $class"); return false; } $obj = &new $newclass; if (!$obj) { LDAP_DataObject::raiseError("Error creating $newclass"); return false; } if (!@$cache[$class]) { $cache[$class] = array(); } if (!$obj->get($dn)) { LDAP_DataObject::raiseError("No Data return from get $dn"); return false; } $cache[$class][$key] = $obj; return $cache[$class][$key]; } /** * find results, either normal or crosstable * * for example * * $object = new mytable(); * $object->ID = 1; * $object->find(); * * * will set $object->N to number of rows, and expects next command to fetch rows * will return $object->N * * @param boolean $n Fetch first result * @access public * @return int */ function find($n = false) { if (!$GLOBALS['_LDAP_DATAOBJECT_PRODUCTION']) { $this->debug($n, "__find",1); } if (!$this->_objectclasses) { echo "NO \$__table SPECIFIED in class definition"; exit; } $this->N = 0; $tmpcond = $this->_condition; $this->_build_condition($this->_get_table()) ; // $this->_query(); // is select ////add by ming ... keep old condition .. so that find can reuse $this->_condition = $tmpcond; if (!$GLOBALS['_LDAP_DATAOBJECT_PRODUCTION']) { $this->debug("CHECK autofetchd $n", "__find", 1); } if ($n && $this->N > 0 ) { if (!$GLOBALS['_LDAP_DATAOBJECT_PRODUCTION']) { $this->debug("ABOUT TO AUTOFETCH", "__find", 1); } $this->fetch() ; } if (!$GLOBALS['_LDAP_DATAOBJECT_PRODUCTION']) { $this->debug("DONE", "__find", 1); } return $this->N; } /** * fetches next row into this objects var's * * returns 1 on success 0 on failure * * * * Example * $object = new mytable(); * $object->name = "fred"; * $object->find(); * $store = array(); * while ($object->fetch()) { * echo $this->ID; * $store[] = $object; // builds an array of object lines. * } * * to add features to a fetch * function fetch () { * $ret = parent::fetch(); * $this->date_formated = date('dmY',$this->date); * return $ret; * } * * @access public * @return boolean on success */ function fetch() { if (!@$this->N) { LDAP_DataObject::raiseError("fetch: No Data Available"); return false; } $result = &$GLOBALS['_LDAP_DATAOBJECT']['RESULTS'][$this->_LDAP_resultid]; if (!($this->_N < $this->N)) { // end of data. return false; } $array = $result[$this->_N]; $this->_N++; if (!$GLOBALS['_LDAP_DATAOBJECT_PRODUCTION']) { $this->debug(serialize($array),"FETCH", 3); } if (!is_array($array)) { // this is probably end of data!! //LDAP_DataObject::raiseError("fetch: no data returned", LDAP_DATAOBJECT_ERROR_NODATA); return false; } $table = $this->_get_table($array['objectclass']); $keys = array_keys($table); $uckeys = array_keys(array_change_key_case($table,CASE_UPPER)); //echo "UCKEYS"; //print_r($uckeys); foreach($array as $k=>$v) { if (is_numeric($k)) { continue; } if ($k == 'count') { continue; } $kk = $k; if ($k != 'dn') { $tpos = array_search(strtoupper($k),$uckeys); if ($tpos !== false) { $kk = $keys[$tpos]; } else { echo "ERROR: unknown key?: $k\n"; } } if (is_array($array[$k]) && isset($array[$k]['count'])) { unset($array[$k]['count']); } $this->$kk = $array[$k]; } // set link flag if (!$GLOBALS['_LDAP_DATAOBJECT_PRODUCTION']) { $this->debug("{$this->_objectclasses} DONE", "fetchrow"); } return true; } /** * Adds a condition to the WHERE statement, defaults to AND * * $object->whereAdd(); //reset or cleaer ewhwer * $object->whereAdd("cn=*"); * $object->whereAdd("cn=fred","&"); * * @param string $cond condition * @param string $logic optional logic "OR" (defaults to "AND") * @access public * @return none */ function whereAdd($cond = false, $logic = '&') { if ($cond === false) { $this->_condition = ''; return; } if ($this->_condition) { $this->_condition = "({$logic}({$cond}){$this->_condition})"; return; } $this->_condition = "({$cond})"; } /** * Sets the order by condition -- TODO! * * $object->orderBy(); //clears order by * $object->orderBy("ID"); * $object->orderBy("ID,age"); // no support for this - dont try it yet. * * @param string $order Order * @access public * @return none */ function orderBy($order = false) { if ($order === false) { $this->_order_by = ''; return; } if (!$this->_order_by) { $this->_order_by = "{$order} "; return; } $this->_order_by .= " , {$order}"; } /** * Sets the base * * $object->orderBy(); //clears order by * $object->orderBy("ID"); * $object->orderBy("ID,age"); // no support for this - dont try it yet. * * @param string $order Order * @access public * @return none */ function base($base=false) { if ($base === false) { return $this->_base; } return $this->_base = $base; } /** * Sets the Limit * * $boject->limit(); // clear limit * $object->limit(12); * $object->limit(12,10); * * @param string $a limit start (or number), or blank to reset * @param string $b number * @access public * @return none */ function limit($a = NULL, $b = NULL) { if ($a === NULL) { $this->_limit = ''; return; } if ($b === NULL) { $this->_limit = array($a); return; } $this->_limit = array($a,$b); } /** * Adds a select columns * * $object->selectAdd(); // resets select to nothing! * $object->selectAdd("*"); // default select * $object->selectAdd("a,b,c,d"); * * @param string $k * @access public * @return none */ function selectAdd($k = NULL) { if ($k === NULL) { $this->_data_select = ''; return; } if ($this->_data_select) $this->_data_select .= ', '; $this->_data_select .= " $k "; } /** * Insert the current objects variables into the database * * Returns the ID of the inserted element - mysql specific = fixme? * * for example * * Designed to be extended * * $object = new mytable(); * $object->name = "fred"; * echo $object->insert(); * * @access public * @return mixed|false key value or false on failure */ function insert() { $v = $this->{$this->_key}; if (is_array($v)) { $v = $v[0]; } $v = $this->escape($v); $this->dn = "{$this->_key}={$v},{$this->_base}"; return $this->update('ldap_add'); } /** * Updates current objects variables into the database * uses the _get_keys() to decide how to update * Returns the true on success * * for example * * $object = new mytable(); * $object->get("ID",234); * $object->email="testing@test.com"; * if(!$object->update()) * echo "UPDATE FAILED"; * * @access public * @return boolean true = success */ function update($action = 'ldap_modify') { global $_LDAP_DATAOBJECT, $_LDAP_DATAOBJECT_PRODUCTION; //$this->_data_select //, $this->__table , // $this->_condition , // $this->_order_by . " ". // $this->_limit $options = &PEAR::getStaticProperty('LDAP_DataObject','options'); if (!$_LDAP_DATAOBJECT_PRODUCTION) { $this->debug("INSERT","sql"); } $this->_connect(); $connection = &$_LDAP_DATAOBJECT['CONNECTIONS'][$this->_bind_md5]; $items = $this->_get_table(); if (!$items) { LDAP_DataObject::raiseError("insert:No table definition for {$this->__table}"); return false; } $insert = array(); foreach($items as $k => $v) { if (!isset($this->$k)) { continue; } if ($k == 'dn') { continue; } if (is_array($this->$k) && (count($this->$k) == 1)) { $v = $this->$k; if (empty($v[0])) { continue; } $insert[$k] = $v[0]; continue; } $insert[$k] = $this->$k; } echo "$action , $connection, {$this->dn}"; print_r($insert); $r = $action($connection, $this->dn, $insert); if (!$r) { LDAP_DataObject::raiseError(ldap_error($connection),ldap_errno($connection)); return false; } return true; } /** * Deletes items from table which match current objects variables * * Returns the true on success * * for example * * Designed to be extended * * $object = new mytable(); * $object->ID=123; * echo $object->delete(); // builds a conditon * $object = new mytable(); * $object->whereAdd('age > 12'); * $object->delete(true); // use the condition * * @param bool $useWhere (optional) If LDAP_DATAOBJECT_WHEREADD_ONLY is passed in then * we will build the condition only using the whereAdd's. Default is to * build the condition only using the object parameters. * * @access public * @return bool True on success */ function delete() { global $_LDAP_DATAOBJECT, $_LDAP_DATAOBJECT_PRODUCTION; //$this->_data_select //, $this->__table , // $this->_condition , // $this->_order_by . " ". // $this->_limit $options = &PEAR::getStaticProperty('LDAP_DataObject','options'); if (!$_LDAP_DATAOBJECT_PRODUCTION) { $this->debug("INSERT","sql"); } $this->_connect(); $connection = &$_LDAP_DATAOBJECT['CONNECTIONS'][$this->_bind_md5]; $r = ldap_delete($connection,$this->dn); if (!$r) { LDAP_DataObject::raiseError(ldap_error($connection),ldap_errno($connection)); return false; } return true; } /* ==================================================== */ /* Major Private Vars */ /* ==================================================== */ /** * The Database connection dsn (as described in the PEAR DB) * only used really if you are writing a very simple application/test.. * try not to use this - it is better stored in configuration files.. * * @access private * @var array */ var $_bind = ''; /** * The Database connection id (md5 sum of databasedsn) * * @access private * @var string */ var $_bind_md5 = ''; /** * The Search base (use $object->base(xxx)) to set it.. * * @access private * @var string */ var $_base = ''; /** * The number of the current rows returned from a query * * @access private * @var int */ var $_N = 0; // Number of rows returned from a query /** * The WHERE condition * * @access private * @var string */ var $_condition = ''; /** * The ORDER BY condition * * @access private * @var string */ var $_order_by = ''; /** * The Limit by statement * * @access private * @var string */ var $_limit = ''; /** * The default Select * @access private * @var string */ var $_data_select = ''; /** * Database result id (references global $__LDAP_DataObject_results * * @access private * @var integer */ var $_LDAP_resultid; // database result object /** * Last Error that has occured * - use $this->_lastError or * $last_error = &PEAR::getStaticProperty('LDAP_DataObject','lastError'); * * @access public * @var object PEAR_Error (or false) */ var $_lastError = false; /* =========================================================== */ /* Major Public Vars - near the end so all dyn. & public vars print out in a group /* =========================================================== */ /** * The Number of rows returned from a query * * @access public * @var int */ var $N = 0; // Number of rows returned from a query /** * The DN of the result. - like an ID in an SQL database * * @access public * @var string */ var $dn; /* =========================================================== */ /* Major Private Methods - the core part!*/ /* =========================================================== */ /** * Autoload the table definitions * * * @access private * @return boolean */ function _loadDefinitions() { global $_LDAP_DATAOBJECT; if ($_LDAP_DATAOBJECT['INI']) { return; } // internally the classnames area stored uppercase! $_LDAP_DATAOBJECT['INI'] = array_change_key_case( parse_ini_file(dirname(__FILE__).'/ldap.ini', true), CASE_UPPER); // needs to load user defined ones ? return true; } /** * get an associative array of table columns * * @access private * @return array (associative) */ function &_get_table($objects = array()) { global $_LDAP_DATAOBJECT; $this->_loadDefinitions(); $this->objectClass = array(); $ret = array(); if (!count($objects)) { $objects = $this->_objectclasses; } foreach($objects as $o) { if (is_numeric($o)) { continue; } if (in_array($o, $this->objectClass)) { continue; } $this->objectClass[] = $o; $ret['_extends'] = ''; if (empty($_LDAP_DATAOBJECT['INI'][strtoupper($o)])) { echo "could not find definition for $o\n"; } $ret = array_merge($ret,$_LDAP_DATAOBJECT['INI'][strtoupper($o)]); while ($oo = $ret['_extends']) { $ret['_extends'] = ''; if (in_array($oo, $this->objectClass)) { continue; } $this->objectClass[] = $oo; $ret = array_merge($ret,$_LDAP_DATAOBJECT['INI'][strtoupper($oo)]); } } unset($ret['_extends']); //print_r($ret); return $ret; } /** * clear the cache values for this class - normally done on insert/update etc. * * @access private * @return none */ function _clear_cache() { $cache = &PEAR::getStaticProperty('LDAP_DataObject','cache'); $class = get_class($this); if (@$cache[$class]) { unset($cache[$class]); } } /** * connects to the database * * First shot at a configuration strategy... * * // * * @access private * @return none */ function _connect() { global $_LDAP_DATAOBJECT, $_LDAP_DATAOBJECT_PRODUCTION; if ($this->_bind_md5 && isset($_LDAP_DATAOBJECT['CONNECTIONS'][$this->_bind_md5])) { // we are alread connected.. return; } // it's not currently connected! // try and work out what to use for the dsn ! $options= &PEAR::getStaticProperty('LDAP_DataObject','options'); $bind = $this->_bind; if (!$bind) { if (!$bind) { $bind = array(@$options['bind'],@$options['bindPassword']); } } $this->_bind_md5 = md5(serialize($bind)); if (!$_LDAP_DATAOBJECT_PRODUCTION) { $this->debug("NEW CONNECTION", "CONNECT",3); /* actualy make a connection */ $this->debug(serialize($bind). " {$this->_bind_md5}", "CONNECT",3); } $ldapconn = ldap_connect($options['host']); echo "connection = $ldapconn \n"; if (!$ldapconn) { LDAP_DataObject::raiseError( "failed to connect to " . $options['host'], 0, PEAR_ERROR_DIE ); } $_LDAP_DATAOBJECT['CONNECTIONS'][$this->_bind_md5] = $ldapconn; $bind = ldap_bind($ldapconn, $bind[0],$bind[1]); if (!$bind) { LDAP_DataObject::raiseError( ldap_error($ldapconn), ldap_errno($ldapconn), PEAR_ERROR_DIE ); } return true; } /** * sends query to database - this is the private one that must work - internal functions use this rather than $this->query() * * @access private * @return mixed none or PEAR_Error */ function _query() { global $_LDAP_DATAOBJECT, $_LDAP_DATAOBJECT_PRODUCTION; //$this->_data_select //, $this->__table , // $this->_condition , // $this->_order_by . " ". // $this->_limit $options = &PEAR::getStaticProperty('LDAP_DataObject','options'); if (!$_LDAP_DATAOBJECT_PRODUCTION) { $this->debug("QUERY","sql"); } $this->_connect(); $connection = &$_LDAP_DATAOBJECT['CONNECTIONS'][$this->_bind_md5]; $this->_LDAP_resultid = count($_LDAP_DATAOBJECT['RESULTS']); // add to the results stuff... if ($this->_data_select == '') { $attributes = array_keys($this->_get_table()); } else { $attributes = explode(',',str_replace(' ','',$this->_data_select)); } $limit = 0; if (isset($this->limit[1])) { $limit = $this->limit[0] + $this->limit[1]; } else if (isset($this->limit[0])) { $limit = $this->limit[0]; } if ($this->_base) { $base = $this->_base; } else { $base = $options['base']; } $method = 'ldap_search'; if ($this->dn) { $base = $this->dn; $method = 'ldap_read'; } //print_r(array($connection, // $base, // $this->_condition, // $attributes, // 0, // $limit)); $search = $method($connection, $base, $this->_condition, $attributes, 0, $limit); $_LDAP_DATAOBJECT['RESULTS'][$this->_LDAP_resultid] = ldap_get_entries($connection,$search); $result = &$_LDAP_DATAOBJECT['RESULTS'][$this->_LDAP_resultid]; // do limit if req. if (isset($this->limit[1])) { $result = array_slice($result,$this->limit[0],$this->limit[1]); } // sorting ? $this->N = $result['count']; $this->_N = 0; // reset pointer echo "GOT {$this->N} results"; } /** * Like addslashes for sql databases = escapes important stuff * * @param string $string * @access public * @return string */ function escape($str) { static $trans = array( '*' => '\\*', '(' => '\\(', ')' => '\\)', '\\' => '\\\\'); return strtr( $str ,$trans); } /** * Builds the WHERE based on the values of of this object * * @param mixed $keys * @access private * @return string */ function _build_condition(&$keys) { global $_LDAP_DATAOBJECT, $_LDAP_DATAOBJECT_PRODUCTION; //print_r($this); $this->_connect(); foreach($keys as $k => $v) { // echo "LOOKING FOR $k\n"; /* these filter checks are a bit suspicious.. - need to check that update really wants to work this way */ if (!isset($this->$k)) { continue; } if (is_string($this->$k)) { $this->whereAdd($k .'=' . $this->escape( $this->$k )); continue; } if (is_numeric($this->$k)) { $this->whereAdd("$k={$this->$k}"); continue; } if (is_array($this->$k)) { // echo "GOT ARRAY\n"; foreach($this->$k as $vv) { //echo "GOT $vv\n"; if (is_string($vv)) { $this->whereAdd($k .'=' . $this->escape($vv)); continue; } if (is_numeric($vv)) { $this->whereAdd("{$k}={$vv}"); continue; } } } /* this is probably an error condition! */ //$this->whereAdd("$k = 0"); } //exit; } /** * Copies items that are in the table definitions from an * array or object into the current object * will not override key values. * * * @param array | object $from * @access public * @return boolean , true on success */ function setFrom(&$from) { $keys = array('dn'); $items = $this->_get_table(); if (!$items) { LDAP_DataObject::raiseError("setFrom:Could not find table definition for {$this->__table}"); return; } foreach (array_keys($items) as $k) { if (in_array($k,$keys)) { continue; // dont overwrite keys } if (!$k) { continue; // ignore empty keys!!! what } if (is_object($from) && @isset($from->$k)) { if (is_object($from[$k])) { $this->$k = (array) $from[$k]; } $this->$k = $from->$k; continue; } if (!@isset($from[$k])) { continue; } if (is_object($from[$k])) { $this->$k = (array) $from[$k]; continue; } $this->$k = $from[$k]; } return true; } /** * validate - override this to set up your validation rules * * validate the current objects values either just testing strings/numbers or * using the user defined validate{Row name}() methods. * will attempt to call $this->validate{column_name}() - expects true = ok false = ERROR * you can the use the validate Class from your own methods. * * @access public * @return array of validation results or true */ function validate() { //require_once 'Validate.php'; $table = &$this->_get_table(); $ret = array(); foreach($table as $key => $val) { echo serialize(@$this->{$key}); echo "$key = $val is " .LDAP_DATAOBJECT_MUST ."
"; if (!isset($this->$key) && ($val & LDAP_DATAOBJECT_MUST)) { echo "GOT ERROR
"; $ret[$key] = "Required Field Missing"; continue; } if ((empty($this->$key) || (is_string($this->$key) && !strlen(@$this->$key))) && ($val & LDAP_DATAOBJECT_MUST)) { $ret[$key] = "Required Field Missing"; continue; } if (!isset($this->$key)) { continue; } if (is_array($this->$key)) { if (!strlen(@$this->{$key}[0]) && ($val & LDAP_DATAOBJECT_MUST)) { $ret[$key] = "Required Field Missing"; continue; } } // should really do single value checks as well.. } if (count($ret)) { return $ret; } return true; // everything is OK. } /* ----------------------- Debugger ------------------ */ /** * Debugger. - use this in your extended classes to output debugging information. * * Uses LDAP_DataObject::DebugLevel(x) to turn it on * * @param string $message - message to output * @param string $logtype - bold at start * @param string $level - output level * @access public * @return none */ function debug($message, $logtype = 0, $level = 1) { if ($GLOBALS['_LDAP_DATAOBJECT_PRODUCTION']) { return; } if (LDAP_DataObject::debugLevel()<$level) { return; } if (!ini_get('html_errors')) { echo "$logtype : $message\n"; flush(); return; } echo "
$logtype $message
\n"; flush(); } /** * sets and returns debug level * eg. LDAP_DataObject::debugLevel(4); * * @param int $v level * @access public * @return none */ function debugLevel($v = NULL) { if ($GLOBALS['_LDAP_DATAOBJECT_PRODUCTION']) { PEAR::raiseError("DB_DataObject in Production Mode",NULL,PEAR_ERROR_DIE); } $options = &PEAR::getStaticProperty('LDAP_DataObject','options'); if ($v !== NULL) { $options['debug'] = $v; } return @$options['debug']; } /** * Default error handling is to create a pear error, but never return it. * if you need to handle errors you should look at setting the PEAR_Error callback * this is due to the fact it would wreck havoc on the internal methods! * * @param int $message message * @param int $type type * @param int $behaviour behaviour (die or continue!); * @access public * @return error object */ function raiseError($message, $type = NULL, $behaviour = NULL) { if (PEAR::isError($message)) { $error = $message; } else { $error = PEAR::raiseError($message, $type, $behaviour); } // this will never work totally with PHP's object model. // as this is passed on static calls (like staticGet in our case) if (@is_object($this) && is_subclass_of($this,'ldap_dataobject')) { $this->_lastError = $error; } $GLOBALS['_LDAP_DATAOBJECT']['LASTERROR'] = $error; // no checks for production here?....... LDAP_DataObject::debug($message,"ERROR",1); return $error; } /** * Define the $GLOBALS['_LDAP_DATAOBJECT_PRODUCTION'] variable * * After Profiling DB_DataObject, I discoved that the debug calls where taking * considerable time (well 0.1 ms), so this should stop those calls happening. * by setting production =1 in the config, you disable all debug calls.. * THIS STILL NEEDS FURTHER INVESTIGATION * * @access public * @return error object */ function staticInitialize() { $options = &PEAR::getStaticProperty('LDAP_DataObject','options'); if (@$options['production']) { $GLOBALS['_LDAP_DATAOBJECT_PRODUCTION']= 1; return; } $GLOBALS['_LDAP_DATAOBJECT_PRODUCTION']= 0; } } LDAP_DataObject::staticInitialize(); ?>