[PHP-CVS] cvs: php4 /pear PEAR.php.in
jon Mon Apr 2 20:12:49 2001 EDT Modified files: /php4/pear PEAR.php.in Log: Cleaner (and probably safer) condition handling. Index: php4/pear/PEAR.php.in diff -u php4/pear/PEAR.php.in:1.17 php4/pear/PEAR.php.in:1.18 --- php4/pear/PEAR.php.in:1.17 Thu Mar 29 11:54:27 2001 +++ php4/pear/PEAR.php.in Mon Apr 2 20:12:49 2001 @@ -17,7 +17,7 @@ // | Stig Bakken [EMAIL PROTECTED] | // +--+ // -// $Id: PEAR.php.in,v 1.17 2001/03/29 19:54:27 chagenbu Exp $ +// $Id: PEAR.php.in,v 1.18 2001/04/03 03:12:49 jon Exp $ // define('PEAR_ERROR_RETURN', 1); @@ -236,8 +236,7 @@ if ($mode === null) { if (isset($this-_default_error_mode)) { $mode = $this-_default_error_mode; -} -if ($mode === null) { +} else { $mode = $GLOBALS['_PEAR_default_error_mode']; } } @@ -245,8 +244,7 @@ if ($mode == PEAR_ERROR_TRIGGER $options === null) { if (isset($this-_default_error_options)) { $options = $this-_default_error_options; -} -if ($options === null) { +} else { $options = $GLOBALS['_PEAR_default_error_options']; } } @@ -257,8 +255,7 @@ is_object($options[0]) is_string($options[1]))) { if (isset($this-_default_error_callback)) { $options = $this-_default_error_callback; -} -if ($options === null) { +} else { $options = $GLOBALS['_PEAR_default_error_callback']; } } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-CVS] cvs: php4 /pear PEAR.php.in
chagenbuThu Mar 29 11:54:28 2001 EDT Modified files: /php4/pear PEAR.php.in Log: Fix a couple of warnings when calling PEAR::raiseError() statically. Index: php4/pear/PEAR.php.in diff -u php4/pear/PEAR.php.in:1.16 php4/pear/PEAR.php.in:1.17 --- php4/pear/PEAR.php.in:1.16 Thu Mar 22 17:15:05 2001 +++ php4/pear/PEAR.php.in Thu Mar 29 11:54:27 2001 @@ -17,7 +17,7 @@ // | Stig Bakken [EMAIL PROTECTED] | // +--+ // -// $Id: PEAR.php.in,v 1.16 2001/03/23 01:15:05 ssb Exp $ +// $Id: PEAR.php.in,v 1.17 2001/03/29 19:54:27 chagenbu Exp $ // define('PEAR_ERROR_RETURN', 1); @@ -234,14 +234,18 @@ $options = null, $userinfo = null) { if ($mode === null) { -$mode = $this-_default_error_mode; +if (isset($this-_default_error_mode)) { +$mode = $this-_default_error_mode; +} if ($mode === null) { $mode = $GLOBALS['_PEAR_default_error_mode']; } } if ($mode == PEAR_ERROR_TRIGGER $options === null) { -$options = $this-_default_error_options; +if (isset($this-_default_error_options)) { +$options = $this-_default_error_options; +} if ($options === null) { $options = $GLOBALS['_PEAR_default_error_options']; } @@ -251,14 +255,20 @@ if (!is_string($options) !(is_array($options) sizeof($options) == 2 is_object($options[0]) is_string($options[1]))) { -$options = $this-_default_error_callback; +if (isset($this-_default_error_callback)) { +$options = $this-_default_error_callback; +} if ($options === null) { $options = $GLOBALS['_PEAR_default_error_callback']; } } } else { if ($options === null) { -$options = $this-_default_error_options; +if (isset($this-_default_error_options)) { +$options = $this-_default_error_options; +} else { +$options = $GLOBALS['_PEAR_default_error_options']; +} } } return new PEAR_Error($message, $code, $mode, $options, $userinfo); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-CVS] cvs: php4 /pear PEAR.php.in
ssb Sat Mar 10 01:59:16 2001 EDT Modified files: /php4/pear PEAR.php.in Log: * only register the destructor if it exists Index: php4/pear/PEAR.php.in diff -u php4/pear/PEAR.php.in:1.14 php4/pear/PEAR.php.in:1.15 --- php4/pear/PEAR.php.in:1.14 Thu Feb 1 12:15:08 2001 +++ php4/pear/PEAR.php.in Sat Mar 10 01:59:15 2001 @@ -17,7 +17,7 @@ // | Stig Bakken [EMAIL PROTECTED] | // +--+ // -// $Id: PEAR.php.in,v 1.14 2001/02/01 20:15:08 cmv Exp $ +// $Id: PEAR.php.in,v 1.15 2001/03/10 09:59:15 ssb Exp $ // define('PEAR_ERROR_RETURN', 1); @@ -73,11 +73,14 @@ /** * Constructor. Registers this object in - * $_PEAR_destructor_object_list for destructor emulation. + * $_PEAR_destructor_object_list for destructor emulation if a + * destructor object exists. */ function PEAR() { -global $_PEAR_destructor_object_list; -$_PEAR_destructor_object_list[] = $this; +if (method_exists($this, "_".get_class($this))) { +global $_PEAR_destructor_object_list; +$_PEAR_destructor_object_list[] = $this; +} if ($this-_debug) { printf("PEAR constructor called, class=%s\n", get_class($this)); @@ -199,7 +202,30 @@ // {{{ raiseError() /** - * This method is called by DB to generate an error. + * This method is a wrapper that returns an instance of PEAR_Error + * with this object's default error handling applied. If the + * $mode and $options parameters are not specified, the object's + * defaults are used. + * + * @param $message a text error message + * @param $code a numeric error code (it is up to your class + * to define these if you want to use codes) + * @param $mode One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT, + * PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE or + * PEAR_ERROR_CALLBACK. + * @param $options If $mode is PEAR_ERROR_TRIGGER, this parameter + * specifies the PHP-internal error level (one of + * E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR). + * If $mode is PEAR_ERROR_CALLBACK, this + * parameter specifies the callback function or + * method. In other error modes this parameter + * is ignored. + * @param $userinfo If you need to pass along for example debug + * information, this parameter is meant for that. + * + * @return object a PEAR error object + * + * @see PEAR::setErrorHandling * * @since PHP 4.0.5 */ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-CVS] cvs: php4 /pear PEAR.php.in
cmv Thu Feb 1 12:15:09 2001 EDT Modified files: /php4/pear PEAR.php.in Log: trigger_error() should be ($msg,$level), no? Index: php4/pear/PEAR.php.in diff -u php4/pear/PEAR.php.in:1.13 php4/pear/PEAR.php.in:1.14 --- php4/pear/PEAR.php.in:1.13 Tue Jan 30 17:27:09 2001 +++ php4/pear/PEAR.php.in Thu Feb 1 12:15:08 2001 @@ -17,7 +17,7 @@ // | Stig Bakken [EMAIL PROTECTED] | // +--+ // -// $Id: PEAR.php.in,v 1.13 2001/01/31 01:27:09 ssb Exp $ +// $Id: PEAR.php.in,v 1.14 2001/02/01 20:15:08 cmv Exp $ // define('PEAR_ERROR_RETURN', 1); @@ -185,12 +185,12 @@ is_object($options[0]) is_string($options[1]))) { $setcallback = $options; } else { -trigger_error(E_USER_WARNING, "invalid error callback"); +trigger_error("invalid error callback", E_USER_WARNING); } break; default: -trigger_error(E_USER_WARNING, "invalid error mode"); +trigger_error("invalid error mode", E_USER_WARNING); break; } } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-CVS] cvs: php4 /pear PEAR.php.in
ssb Tue Jan 30 17:27:11 2001 EDT Modified files: /php4/pear PEAR.php.in Log: whitespace Index: php4/pear/PEAR.php.in diff -u php4/pear/PEAR.php.in:1.12 php4/pear/PEAR.php.in:1.13 --- php4/pear/PEAR.php.in:1.12 Mon Jan 29 16:55:27 2001 +++ php4/pear/PEAR.php.in Tue Jan 30 17:27:09 2001 @@ -17,7 +17,7 @@ // | Stig Bakken [EMAIL PROTECTED] | // +--+ // -// $Id: PEAR.php.in,v 1.12 2001/01/30 00:55:27 ssb Exp $ +// $Id: PEAR.php.in,v 1.13 2001/01/31 01:27:09 ssb Exp $ // define('PEAR_ERROR_RETURN', 1); @@ -60,14 +60,14 @@ */ class PEAR { - // {{{ properties +// {{{ properties - var $_debug = false; +var $_debug = false; var $_default_error_mode = null; var $_default_error_options = null; var $_default_error_handler = ''; - // }}} +// }}} // {{{ constructor @@ -75,33 +75,33 @@ * Constructor. Registers this object in * $_PEAR_destructor_object_list for destructor emulation. */ - function PEAR() { - global $_PEAR_destructor_object_list; - $_PEAR_destructor_object_list[] = $this; - if ($this-_debug) { - printf("PEAR constructor called, class=%s\n", - get_class($this)); - } - } +function PEAR() { +global $_PEAR_destructor_object_list; +$_PEAR_destructor_object_list[] = $this; +if ($this-_debug) { +printf("PEAR constructor called, class=%s\n", + get_class($this)); +} +} // }}} // {{{ destructor /** * Destructor (the emulated type of...). Does nothing right now, -* but is included for forward compatibility, so subclass -* destructors should always call it. + * but is included for forward compatibility, so subclass + * destructors should always call it. * * See the note in the class desciption about output from * destructors. -* -* @access public + * + * @access public */ function _PEAR() { - if ($this-_debug) { - printf("PEAR destructor called, class=%s\n", - get_class($this)); - } +if ($this-_debug) { +printf("PEAR destructor called, class=%s\n", + get_class($this)); +} } // }}} @@ -110,15 +110,15 @@ /** * Tell whether a value is a PEAR error. * - * @param $data the value to test - * @access public - * @return booltrue if $data is an error - */ - function isError($data) { - return (bool)(is_object($data) - (get_class($data) == "pear_error" || - is_subclass_of($data, "pear_error"))); - } + * @param $data the value to test + * @access public + * @return booltrue if $data is an error + */ +function isError($data) { +return (bool)(is_object($data) + (get_class($data) == "pear_error" || + is_subclass_of($data, "pear_error"))); +} // }}} // {{{ setErrorHandling() @@ -246,16 +246,16 @@ function _PEAR_call_destructors() { global $_PEAR_destructor_object_list; if (is_array($_PEAR_destructor_object_list) sizeof($_PEAR_destructor_object_list)) { - reset($_PEAR_destructor_object_list); - while (list($k, $objref) = each($_PEAR_destructor_object_list)) { - $destructor = "_".get_class($objref); - if (method_exists($objref, $destructor)) { - $objref-$destructor(); - } - } - // Empty the object list to ensure that destructors are - // not called more than once. - $_PEAR_destructor_object_list = array(); +reset($_PEAR_destructor_object_list); +while (list($k, $objref) = each($_PEAR_destructor_object_list)) { +$destructor = "_".get_class($objref); +if (method_exists($objref, $destructor)) { +$objref-$destructor(); +} +} +// Empty the object list to ensure that destructors are +// not called more than once. +$_PEAR_destructor_object_list = array(); } } @@ -265,235 +265,235 @@ { // {{{ properties - var $error_message_prefix = ''; - var $error_prepend= ''; - var $error_append = ''; - var $mode = PEAR_ERROR_RETURN; - var $level= E_USER_NOTICE; - var $code = -1; - var $message = ''; - var $debuginfo= ''; - - // Wait until we have a stack-groping function in PHP. - //var $file= ''; - //var $line= 0;
[PHP-CVS] cvs: php4 /pear PEAR.php.in /pear/tests pear_error.phpt pear_error3.phpt
ssb Mon Jan 29 16:55:27 2001 EDT Added files: /php4/pear/testspear_error3.phpt Modified files: /php4/pear PEAR.php.in /php4/pear/testspear_error.phpt Log: @Added raiseError and setErrorHandling methods to PEAR class (Stig, PEAR) # This allows all objects to have their own default error handling # or use a global default. Index: php4/pear/PEAR.php.in diff -u php4/pear/PEAR.php.in:1.11 php4/pear/PEAR.php.in:1.12 --- php4/pear/PEAR.php.in:1.11 Tue Jan 9 17:01:52 2001 +++ php4/pear/PEAR.php.in Mon Jan 29 16:55:27 2001 @@ -17,7 +17,7 @@ // | Stig Bakken [EMAIL PROTECTED] | // +--+ // -// $Id: PEAR.php.in,v 1.11 2001/01/10 01:01:52 ssb Exp $ +// $Id: PEAR.php.in,v 1.12 2001/01/30 00:55:27 ssb Exp $ // define('PEAR_ERROR_RETURN', 1); @@ -30,6 +30,9 @@ define('PEAR_INSTALL_DIR', '@PEAR_INSTALLDIR@'); define('PEAR_EXTENSION_DIR', '@EXTENSION_DIR@'); +$_PEAR_default_error_mode = PEAR_ERROR_RETURN; +$_PEAR_default_error_options = E_USER_NOTICE; +$_PEAR_default_error_callback = ''; $_PEAR_destructor_object_list = array(); // @@ -60,6 +63,9 @@ // {{{ properties var $_debug = false; +var $_default_error_mode = null; +var $_default_error_options = null; +var $_default_error_handler = ''; // }}} @@ -115,6 +121,124 @@ } // }}} +// {{{ setErrorHandling() + +/** + * Sets how errors generated by this DB object should be handled. + * Can be invoked both in objects and statically. If called + * statically, setErrorHandling sets the default behaviour for all + * PEAR objects. If called in an object, setErrorHandling sets + * the default behaviour for that object. + * + * @param $mode int + *one of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT, + *PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE or + *PEAR_ERROR_CALLBACK. + * + * @param $options mixed + *Ignored unless $mode is PEAR_ERROR_TRIGGER or + *PEAR_ERROR_CALLBACK. When $mode is PEAR_ERROR_TRIGGER, + *this parameter is expected to be an integer and one of + *E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR. When + *$mode is PEAR_ERROR_CALLBACK, this parameter is expected + *to be the callback function or method. A callback + *function is a string with the name of the function, a + *callback method is an array of two elements: the element + *at index 0 is the object, and the element at index 1 is + *the name of the method to call in the object. + * + * @see PEAR_ERROR_RETURN + * @see PEAR_ERROR_PRINT + * @see PEAR_ERROR_TRIGGER + * @see PEAR_ERROR_DIE + * @see PEAR_ERROR_CALLBACK + * + * @since PHP 4.0.5 + */ + +function setErrorHandling($mode, $options = null) +{ +if (isset($this)) { +$setmode = $this-_default_error_mode; +$setoptions = $this-_default_error_options; +$setcallback = $this-_default_error_callback; +} else { +$setmode = $GLOBALS['_PEAR_default_error_mode']; +$setoptions = $GLOBALS['_PEAR_default_error_options']; +$setcallback = $GLOBALS['_PEAR_default_error_callback']; +} + +switch ($mode) { +case PEAR_ERROR_RETURN: +case PEAR_ERROR_PRINT: +case PEAR_ERROR_TRIGGER: +case PEAR_ERROR_DIE: +case null: +$setmode = $mode; +$setoptions = $options; +break; + +case PEAR_ERROR_CALLBACK: +$setmode = $mode; +if (is_string($options) || +(is_array($options) sizeof($options) == 2 + is_object($options[0]) is_string($options[1]))) { +$setcallback = $options; +} else { +trigger_error(E_USER_WARNING, "invalid error callback"); +} +break; + +default: +trigger_error(E_USER_WARNING, "invalid error mode"); +break; +} +} + +// }}} +// {{{ raiseError() + +/** + * This method is called by DB to generate an error. + * + * @since PHP 4.0.5 + */ + +function raiseError($message = null, $code = null, $mode = null, + $options = null, $userinfo = null) +{ +if ($mode === null) { +$mode = $this-_default_error_mode; +if ($mode === null) { +$mode = $GLOBALS['_PEAR_default_error_mode']; +} +} + +if ($mode == PEAR_ERROR_TRIGGER $options === null) { +$options = $this-_default_error_options; +