svn: /pear/pear-core/trunk/ PEAR.php
[email protected] (Helgi Þormar Þorbjörnsson)
| Newsgroups | php.pear.cvs,php.pear.core |
|---|---|
| Message-ID | <[email protected]> |
dufuz Sat, 08 May 2010 20:55:14 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=299155
Log:
Clean up, fix code according to CS, add a few docblocks.
Changed paths:
U pear/pear-core/trunk/PEAR.php
svn-diffs-299155.txt
(text/x-diff, 11.2 KB)
Modified: pear/pear-core/trunk/PEAR.php =================================================================== --- pear/pear-core/trunk/PEAR.php 2010-05-08 20:38:12 UTC (rev 299154) +++ pear/pear-core/trunk/PEAR.php 2010-05-08 20:55:14 UTC (rev 299155) @@ -12,7 +12,7 @@ * @author Stig Bakken <[email protected]> * @author Tomas V.V.Cox <[email protected]> * @author Greg Beaver <[email protected]> - * @copyright 1997-2009 The Authors + * @copyright 1997-2010 The Authors * @license http://opensource.org/licenses/bsd-license.php New BSD License * @version CVS: $Id$ * @link http://pear.php.net/package/PEAR @@ -86,8 +86,6 @@ */ class PEAR { - // {{{ properties - /** * Whether to enable internal debug messages. * @@ -138,10 +136,6 @@ */ var $_expected_errors = array(); - // }}} - - // {{{ constructor - /** * Constructor. Registers this object in * $_PEAR_destructor_object_list for destructor emulation if a @@ -158,9 +152,11 @@ if ($this->_debug) { print "PEAR constructor called, class=$classname\n"; } + if ($error_class !== null) { $this->_error_class = $error_class; } + while ($classname && strcasecmp($classname, "pear")) { $destructor = "_$classname"; if (method_exists($this, $destructor)) { @@ -177,9 +173,6 @@ } } - // }}} - // {{{ destructor - /** * Destructor (the emulated type of...). Does nothing right now, * but is included for forward compatibility, so subclass @@ -197,9 +190,6 @@ } } - // }}} - // {{{ getStaticProperty() - /** * If you have a class that's mostly/entirely static, and you need static * properties, you can use this method to simulate them. Eg. in your method(s) @@ -226,9 +216,6 @@ return $properties[$class][$var]; } - // }}} - // {{{ registerShutdownFunc() - /** * Use this function to register a shutdown method for static * classes. @@ -249,9 +236,6 @@ $GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args); } - // }}} - // {{{ isError() - /** * Tell whether a value is a PEAR error. * @@ -278,9 +262,6 @@ return $data->getCode() == $code; } - // }}} - // {{{ setErrorHandling() - /** * Sets how errors generated by this object should be handled. * Can be invoked both in objects and statically. If called @@ -319,7 +300,6 @@ * * @since PHP 4.0.5 */ - function setErrorHandling($mode = null, $options = null) { if (isset($this) && is_a($this, 'PEAR')) { @@ -357,9 +337,6 @@ } } - // }}} - // {{{ expectError() - /** * This method is used to tell which errors you expect to get. * Expected errors are always returned with error mode @@ -382,12 +359,9 @@ } else { array_push($this->_expected_errors, array($code)); } - return sizeof($this->_expected_errors); + return count($this->_expected_errors); } - // }}} - // {{{ popExpect() - /** * This method pops one element off the expected error codes * stack. @@ -399,9 +373,6 @@ return array_pop($this->_expected_errors); } - // }}} - // {{{ _checkDelExpect() - /** * This method checks unsets an error code if available * @@ -413,8 +384,7 @@ function _checkDelExpect($error_code) { $deleted = false; - - foreach ($this->_expected_errors AS $key => $error_array) { + foreach ($this->_expected_errors as $key => $error_array) { if (in_array($error_code, $error_array)) { unset($this->_expected_errors[$key][array_search($error_code, $error_array)]); $deleted = true; @@ -425,12 +395,10 @@ unset($this->_expected_errors[$key]); } } + return $deleted; } - // }}} - // {{{ delExpect() - /** * This method deletes all occurences of the specified element from * the expected error codes stack. @@ -444,33 +412,26 @@ { $deleted = false; if ((is_array($error_code) && (0 != count($error_code)))) { - // $error_code is a non-empty array here; - // we walk through it trying to unset all - // values - foreach($error_code as $key => $error) { - if ($this->_checkDelExpect($error)) { - $deleted = true; - } else { - $deleted = false; - } + // $error_code is a non-empty array here; we walk through it trying + // to unset all values + foreach ($error_code as $key => $error) { + $deleted = $this->_checkDelExpect($error) ? true : false; } + return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME } elseif (!empty($error_code)) { // $error_code comes alone, trying to unset it if ($this->_checkDelExpect($error_code)) { return true; - } else { - return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME } + + return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME } // $error_code is empty return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME } - // }}} - // {{{ raiseError() - /** * This method is a wrapper that returns an instance of the * configured error class with this object's default error @@ -569,19 +530,23 @@ return $a; } - // }}} - // {{{ throwError() - /** * Simpler form of raiseError with fewer options. In most cases * message, code and userinfo are enough. * - * @param string $message + * @param mixed $message a text error message or a PEAR error object * + * @param int $code a numeric error code (it is up to your class + * to define these if you want to use codes) + * + * @param string $userinfo If you need to pass along for example debug + * information, this parameter is meant for that. + * + * @access public + * @return object a PEAR error object + * @see PEAR::raiseError */ - function &throwError($message = null, - $code = null, - $userinfo = null) + function &throwError($message = null, $code = null, $userinfo = null) { if (isset($this) && is_a($this, 'PEAR')) { $a = &$this->raiseError($message, $code, null, null, $userinfo); @@ -592,7 +557,6 @@ return $a; } - // }}} function staticPushErrorHandling($mode, $options = null) { $stack = &$GLOBALS['_PEAR_error_handler_stack']; @@ -664,8 +628,6 @@ return true; } - // {{{ pushErrorHandling() - /** * Push a new error handler on top of the error handler options stack. With this * you can easily override the actual error handler for some code and restore @@ -699,9 +661,6 @@ return true; } - // }}} - // {{{ popErrorHandling() - /** * Pop the last error handler used * @@ -723,9 +682,6 @@ return true; } - // }}} - // {{{ loadExtension() - /** * OS independant PHP extension load. Remember to take care * on the correct extension name for case sensitive OSes. @@ -762,16 +718,12 @@ return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix); } - - // }}} } if (PEAR_ZE2) { include_once 'PEAR5.php'; } -// {{{ _PEAR_call_destructors() - function _PEAR_call_destructors() { global $_PEAR_destructor_object_list; @@ -814,7 +766,6 @@ } } -// }}} /** * Standard PEAR error class for PHP 4 * @@ -834,8 +785,6 @@ */ class PEAR_Error { - // {{{ properties - var $error_message_prefix = ''; var $mode = PEAR_ERROR_RETURN; var $level = E_USER_NOTICE; @@ -844,9 +793,6 @@ var $userinfo = ''; var $backtrace = null; - // }}} - // {{{ constructor - /** * PEAR_Error constructor * @@ -930,10 +876,8 @@ die(sprintf($format, $msg)); } - if ($this->mode & PEAR_ERROR_CALLBACK) { - if (is_callable($this->callback)) { - call_user_func($this->callback, $this); - } + if ($this->mode & PEAR_ERROR_CALLBACK && is_callable($this->callback)) { + call_user_func($this->callback, $this); } if ($this->mode & PEAR_ERROR_EXCEPTION) { @@ -942,36 +886,28 @@ } } - // }}} - // {{{ getMode() - /** * Get the error mode from an error object. * * @return int error mode * @access public */ - function getMode() { + function getMode() + { return $this->mode; } - // }}} - // {{{ getCallback() - /** * Get the callback function/method from an error object. * * @return mixed callback function or object/method array * @access public */ - function getCallback() { + function getCallback() + { return $this->callback; } - // }}} - // {{{ getMessage() - - /** * Get the error message from an error object. * @@ -983,10 +919,6 @@ return ($this->error_message_prefix . $this->message); } - - // }}} - // {{{ getCode() - /** * Get error code from an error object * @@ -998,9 +930,6 @@ return $this->code; } - // }}} - // {{{ getType() - /** * Get the name of this error/exception. * @@ -1012,9 +941,6 @@ return get_class($this); } - // }}} - // {{{ getUserInfo() - /** * Get additional user-supplied information. * @@ -1026,9 +952,6 @@ return $this->userinfo; } - // }}} - // {{{ getDebugInfo() - /** * Get additional debug information supplied by the application. * @@ -1040,9 +963,6 @@ return $this->getUserInfo(); } - // }}} - // {{{ getBacktrace() - /** * Get the call backtrace from where the error was generated. * Supported with PHP 4.3.0 or newer. @@ -1062,9 +982,6 @@ return $this->backtrace[$frame]; } - // }}} - // {{{ addUserInfo() - function addUserInfo($info) { if (empty($this->userinfo)) { @@ -1074,14 +991,10 @@ } } - // }}} - // {{{ toString() function __toString() { return $this->getMessage(); } - // }}} - // {{{ toString() /** * Make a string representation of this object. @@ -1089,7 +1002,8 @@ * @return string a string with an object summary * @access public */ - function toString() { + function toString() + { $modes = array(); $levels = array(E_USER_NOTICE => 'notice', E_USER_WARNING => 'warning', @@ -1128,8 +1042,6 @@ $this->error_message_prefix, $this->userinfo); } - - // }}} } /*