cvs: php4 /pear Makefile.in PEAR.php.in /pear/DB mysql.php /pear/DB/tests db_error.phpt db_error2.phpt /pear/tests pear_error.phpt
pear_error_callback.phpt

From: Date: Wed, 13 Sep 2000 07:39:54 +0000
Subject: cvs: php4 /pear Makefile.in PEAR.php.in /pear/DB mysql.php /pear/DB/tests db_error.phpt db_error2.phpt /pear/tests pear_error.phpt
pear_error_callback.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-1745@lists.php.net to get a copy of this message
ssb Wed Sep 13 00:39:54 2000 EDT Removed files: /php4/pear/tests pear_error_callback.phpt Modified files: /php4/pear Makefile.in PEAR.php.in /php4/pear/DB mysql.php /php4/pear/DB/tests db_error.phpt db_error2.phpt /php4/pear/tests pear_error.phpt Log: PEAR: * show what's going on when PEAR files are installed * allow multiple modes (or'ed) in PEAR_Error @PEAR: allow multiple modes in PEAR_Error (Stig) Index: php4/pear/Makefile.in diff -u php4/pear/Makefile.in:1.42 php4/pear/Makefile.in:1.43 --- php4/pear/Makefile.in:1.42 Tue Aug 29 02:10:44 2000 +++ php4/pear/Makefile.in Wed Sep 13 00:39:53 2000 @@ -41,15 +41,15 @@ install-data-local: PEAR.php @if $(mkinstalldirs) $(peardir); then \ for i in $(PEAR_SUBDIRS); do \ - $(mkinstalldirs) $(peardir)/$$i; \ + (set -x;$(mkinstalldirs) $(peardir)/$$i); \ done; \ for i in $(PEAR_FILES); do \ dir=echo $$i|sed 's%[^/][^/]*$$%%'; \ - $(INSTALL_DATA) $(srcdir)/$$i $(peardir)/$$dir; \ + (set -x;$(INSTALL_DATA) $(srcdir)/$$i $(peardir)/$$dir); \ done; \ for i in PEAR.php; do \ dir=echo $$i|sed 's%[^/][^/]*$$%%'; \ - $(INSTALL_DATA) $(builddir)/$$i $(peardir)/$$dir; \ + (set -x;$(INSTALL_DATA) $(builddir)/$$i $(peardir)/$$dir); \ done; \ else \ cat $(srcdir)/install-pear.txt; \ Index: php4/pear/PEAR.php.in diff -u php4/pear/PEAR.php.in:1.6 php4/pear/PEAR.php.in:1.7 --- php4/pear/PEAR.php.in:1.6 Fri Sep 8 19:39:56 2000 +++ php4/pear/PEAR.php.in Wed Sep 13 00:39:53 2000 @@ -17,14 +17,14 @@ // | Stig Bakken <ssb@fast.no> | // +----------------------------------------------------------------------+ // -// $Id: PEAR.php.in,v 1.6 2000/09/09 02:39:56 ssb Exp $ +// $Id: PEAR.php.in,v 1.7 2000/09/13 07:39:53 ssb Exp $ // -define('PEAR_ERROR_RETURN', 0); -define('PEAR_ERROR_PRINT', 1); -define('PEAR_ERROR_TRIGGER', 2); -define('PEAR_ERROR_DIE', 3); -define('PEAR_ERROR_CALLBACK', 4); +define('PEAR_ERROR_RETURN', 1); +define('PEAR_ERROR_PRINT', 2); +define('PEAR_ERROR_TRIGGER', 4); +define('PEAR_ERROR_DIE', 8); +define('PEAR_ERROR_CALLBACK', 16); define('PHP_BINDIR', '@prefix@/bin'); define('PEAR_INSTALL_DIR', '@PEAR_INSTALLDIR@'); @@ -177,45 +177,46 @@ */ function PEAR_Error($message = 'unknown error', $code = 0, - $mode = PEAR_ERROR_RETURN, - $level = E_USER_NOTICE) + $mode = null, + $options = null) { + if ($mode === null) { + $mode = PEAR_ERROR_RETURN; + } $this->message = $message; $this->code = $code; $this->mode = $mode; - if ($mode == PEAR_ERROR_CALLBACK) { + if ($mode & PEAR_ERROR_CALLBACK) { $this->level = E_USER_NOTICE; - $this->callback = $level; + $this->callback = $options; } else { - $this->level = $level; - $this->callback = false; + if ($options === null) { + $options = E_USER_NOTICE; + } + $this->level = $options; + $this->callback = null; + } + if ($this->mode & PEAR_ERROR_PRINT) { + print $this->getMessage(); + } + if ($this->mode & PEAR_ERROR_TRIGGER) { + trigger_error($this->getMessage(), $this->level); } - switch ($this->mode) { - case PEAR_ERROR_PRINT: - print $this->getMessage(); - break; - case PEAR_ERROR_TRIGGER: - trigger_error($this->getMessage(), $this->level); - break; - case PEAR_ERROR_DIE: - die($this->getMessage()); - break; - case PEAR_ERROR_CALLBACK: - if (is_string($this->callback) && strlen($this->callback)) { - call_user_func($this->callback, $this); - } elseif (is_array($this->callback) && - sizeof($this->callback) == 2 && - is_object($this->callback[0]) && - is_string($this->callback[1]) && - strlen($this->callback[1])) { - call_user_method($this->callback[1], $this->callback[0], - $this); - } - break; - case PEAR_ERROR_RETURN: - default: - break; + if ($this->mode & PEAR_ERROR_DIE) { + die($this->getMessage()); } + if ($this->mode & PEAR_ERROR_CALLBACK) { + if (is_string($this->callback) && strlen($this->callback)) { + call_user_func($this->callback, $this); + } elseif (is_array($this->callback) && + sizeof($this->callback) == 2 && + is_object($this->callback[0]) && + is_string($this->callback[1]) && + strlen($this->callback[1])) { + call_user_method($this->callback[1], $this->callback[0], + $this); + } + } } // }}} @@ -283,19 +284,43 @@ * @return string a string with an object "summary" */ function toString() { - $modes = array(PEAR_ERROR_RETURN => "return", - PEAR_ERROR_PRINT => "print", - PEAR_ERROR_TRIGGER => "trigger", - PEAR_ERROR_DIE => "die", - PEAR_ERROR_CALLBACK => "callback"); + $modes = array(); $levels = array(E_USER_NOTICE => "notice", E_USER_WARNING => "warning", E_USER_ERROR => "error"); - return sprintf("[%s: message=\"%s\" code=%d mode=%s level=%s prefix=\"%s\" prepend=\"%s\" append=\"%s\"]", + if ($this->mode & PEAR_ERROR_CALLBACK) { + if (is_array($this->callback)) { + $callback = get_class($this->callback[0]) . "::" . + $this->callback[1]; + } else { + $callback = $this->callback; + } + return sprintf('[%s: message="%s" code=%d mode=callback '. + 'callback=%s prefix="%s" prepend="%s" append="%s"]', + get_class($this), $this->message, $this->code, + $callback, $this->error_message_prefix, + $this->error_prepend, $this->error_append); + } + if ($this->mode & PEAR_ERROR_CALLBACK) { + $modes[] = "callback"; + } + if ($this->mode & PEAR_ERROR_PRINT) { + $modes[] = "print"; + } + if ($this->mode & PEAR_ERROR_TRIGGER) { + $modes[] = "trigger"; + } + if ($this->mode & PEAR_ERROR_DIE) { + $modes[] = "die"; + } + if ($this->mode & PEAR_ERROR_RETURN) { + $modes[] = "return"; + } + return sprintf('[%s: message="%s" code=%d mode=%s level=%s prefix="%s" prepend="%s" append="%s"]', get_class($this), $this->message, $this->code, - $modes[$this->mode], $levels[$this->level], - $this->error_message_prefix, $this->error_prepend, - $this->error_append); + implode("|", $modes), $levels[$this->level], + $this->error_message_prefix, + $this->error_prepend, $this->error_append); } // }}} Index: php4/pear/DB/mysql.php diff -u php4/pear/DB/mysql.php:1.24 php4/pear/DB/mysql.php:1.25 --- php4/pear/DB/mysql.php:1.24 Mon Sep 11 17:27:50 2000 +++ php4/pear/DB/mysql.php Wed Sep 13 00:39:53 2000 @@ -200,8 +200,8 @@ * * @access public * - * @return int an array on success, a DB error on failure, NULL - * if there is no more data + * @return mixed an array on success, a DB error on failure, NULL + * if there is no more data */ function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT) { if ($fetchmode == DB_FETCHMODE_DEFAULT) { Index: php4/pear/DB/tests/db_error.phpt diff -u php4/pear/DB/tests/db_error.phpt:1.1 php4/pear/DB/tests/db_error.phpt:1.2 --- php4/pear/DB/tests/db_error.phpt:1.1 Fri Sep 8 19:39:56 2000 +++ php4/pear/DB/tests/db_error.phpt Wed Sep 13 00:39:53 2000 @@ -47,11 +47,11 @@ testing different error modes... DB Error: unknown error[db_error: message="DB Error: unknown error" code=-1 mode=print level=notice prefix="" prepend="" append=""] <br> -<b>Notice</b>: DB Error: syntax error in <b>PEAR.php</b> on line <b>198</b><br> +<b>Notice</b>: DB Error: syntax error in <b>PEAR.php</b> on line <b>203</b><br> testing different error serverities... <br> -<b>Notice</b>: DB Error: syntax error in <b>PEAR.php</b> on line <b>198</b><br> +<b>Notice</b>: DB Error: syntax error in <b>PEAR.php</b> on line <b>203</b><br> <br> -<b>Warning</b>: DB Error: syntax error in <b>PEAR.php</b> on line <b>198</b><br> +<b>Warning</b>: DB Error: syntax error in <b>PEAR.php</b> on line <b>203</b><br> <br> -<b>Fatal error</b>: DB Error: syntax error in <b>PEAR.php</b> on line <b>198</b><br> +<b>Fatal error</b>: DB Error: syntax error in <b>PEAR.php</b> on line <b>203</b><br> Index: php4/pear/DB/tests/db_error2.phpt diff -u php4/pear/DB/tests/db_error2.phpt:1.1 php4/pear/DB/tests/db_error2.phpt:1.2 --- php4/pear/DB/tests/db_error2.phpt:1.1 Fri Sep 8 19:39:56 2000 +++ php4/pear/DB/tests/db_error2.phpt Wed Sep 13 00:39:53 2000 @@ -39,6 +39,6 @@ default: [db_error: message="DB Error: return testing error" code=0 mode=return level=notice prefix="" prepend="" append=""] mode=print: DB Error: print testing error mode=trigger: <br> -<b>Notice</b>: DB Error: trigger testing error in <b>PEAR.php</b> on line <b>198</b><br> -mode=function callback: myfunc here, obj=[db_error: message="DB Error: function callback testing error" code=0 mode=callback level=notice prefix="" prepend="" append=""] -mode=object callback: myclass::myfunc here, obj=[db_error: message="DB Error: object callback testing error" code=0 mode=callback level=notice prefix="" prepend="" append=""] +<b>Notice</b>: DB Error: trigger testing error in <b>PEAR.php</b> on line <b>203</b><br> +mode=function callback: myfunc here, obj=[db_error: message="DB Error: function callback testing error" code=0 mode=callback callback=myfunc prefix="" prepend="" append=""] +mode=object callback: myclass::myfunc here, obj=[db_error: message="DB Error: object callback testing error" code=0 mode=callback callback=myclass::myfunc prefix="" prepend="" append=""] Index: php4/pear/tests/pear_error.phpt diff -u php4/pear/tests/pear_error.phpt:1.1 php4/pear/tests/pear_error.phpt:1.2 --- php4/pear/tests/pear_error.phpt:1.1 Fri Sep 8 19:39:56 2000 +++ php4/pear/tests/pear_error.phpt Wed Sep 13 00:39:54 2000 @@ -13,6 +13,18 @@ error_reporting(4095); +function errorhandler(&$obj) { + print "errorhandler function called, obj=".$obj->toString()."\n"; +} + +class errorclass { + function errorhandler(&$obj) { + print "errorhandler method called, obj=".$obj->toString()."\n"; + } +} + +$eo = new errorclass; + print "default PEAR_Error: "; $err = new PEAR_Error; print $err->toString() . "\n"; @@ -23,24 +35,42 @@ var_dump(PEAR::isError($str)); print "Now trying a bunch of variations...\n"; + print "different message: "; $err = new PEAR_Error("test error"); print $err->toString() . "\n"; + print "different message,code: "; $err = new PEAR_Error("test error", -42); print $err->toString() . "\n"; + print "mode=print: "; $err = new PEAR_Error("test error", -42, PEAR_ERROR_PRINT); print $err->toString() . "\n"; + +print "mode=callback(function): "; +$err = new PEAR_Error("test error", -42, PEAR_ERROR_CALLBACK, "errorhandler"); + +print "mode=callback(method): "; +$err = new PEAR_Error("test error", -42, PEAR_ERROR_CALLBACK, + array(&$eo, "errorhandler")); + +print "mode=print&trigger: "; +$err = new PEAR_Error("test error", -42, PEAR_ERROR_PRINT|PEAR_ERROR_TRIGGER); +print $err->toString() . "\n"; + print "mode=trigger: "; $err = new PEAR_Error("test error", -42, PEAR_ERROR_TRIGGER); print $err->toString() . "\n"; + print "mode=trigger,level=notice: "; $err = new PEAR_Error("test error", -42, PEAR_ERROR_TRIGGER, E_USER_NOTICE); print $err->toString() . "\n"; + print "mode=trigger,level=warning: "; $err = new PEAR_Error("test error", -42, PEAR_ERROR_TRIGGER, E_USER_WARNING); print $err->toString() . "\n"; + print "mode=trigger,level=error: "; $err = new PEAR_Error("test error", -42, PEAR_ERROR_TRIGGER, E_USER_ERROR); print $err->toString() . "\n"; @@ -56,14 +86,19 @@ different message: [pear_error: message="test error" code=0 mode=return level=notice prefix="" prepend="" append=""] different message,code: [pear_error: message="test error" code=-42 mode=return level=notice prefix="" prepend="" append=""] mode=print: test error[pear_error: message="test error" code=-42 mode=print level=notice prefix="" prepend="" append=""] +mode=callback(function): errorhandler function called, obj=[pear_error: message="test error" code=-42 mode=callback callback=errorhandler prefix="" prepend="" append=""] +mode=callback(method): errorhandler method called, obj=[pear_error: message="test error" code=-42 mode=callback callback=errorclass::errorhandler prefix="" prepend="" append=""] +mode=print&trigger: test error<br> +<b>Notice</b>: test error in <b>PEAR.php</b> on line <b>203</b><br> +[pear_error: message="test error" code=-42 mode=print|trigger level=notice prefix="" prepend="" append=""] mode=trigger: <br> -<b>Notice</b>: test error in <b>PEAR.php</b> on line <b>198</b><br> +<b>Notice</b>: test error in <b>PEAR.php</b> on line <b>203</b><br> [pear_error: message="test error" code=-42 mode=trigger level=notice prefix="" prepend="" append=""] mode=trigger,level=notice: <br> -<b>Notice</b>: test error in <b>PEAR.php</b> on line <b>198</b><br> +<b>Notice</b>: test error in <b>PEAR.php</b> on line <b>203</b><br> [pear_error: message="test error" code=-42 mode=trigger level=notice prefix="" prepend="" append=""] mode=trigger,level=warning: <br> -<b>Warning</b>: test error in <b>PEAR.php</b> on line <b>198</b><br> +<b>Warning</b>: test error in <b>PEAR.php</b> on line <b>203</b><br> [pear_error: message="test error" code=-42 mode=trigger level=warning prefix="" prepend="" append=""] mode=trigger,level=error: <br> -<b>Fatal error</b>: test error in <b>PEAR.php</b> on line <b>198</b><br> +<b>Fatal error</b>: test error in <b>PEAR.php</b> on line <b>203</b><br>

« previous php.cvs (#1745) next »