21,9 → 21,8 |
* @category Debugging |
* @package PEAR_ErrorStack |
* @author Greg Beaver <cellog@php.net> |
* @copyright 2004-2006 Greg Beaver |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version CVS: $Id: ErrorStack.php,v 1.26 2006/10/31 02:54:40 cellog Exp $ |
* @copyright 2004-2008 Greg Beaver |
* @license http://opensource.org/licenses/bsd-license.php New BSD License |
* @link http://pear.php.net/package/PEAR_ErrorStack |
*/ |
|
132,12 → 131,11 |
* $local_stack = new PEAR_ErrorStack('MyPackage'); |
* </code> |
* @author Greg Beaver <cellog@php.net> |
* @version 1.5.1 |
* @version 1.10.1 |
* @package PEAR_ErrorStack |
* @category Debugging |
* @copyright 2004-2006 Greg Beaver |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version CVS: $Id: ErrorStack.php,v 1.26 2006/10/31 02:54:40 cellog Exp $ |
* @copyright 2004-2008 Greg Beaver |
* @license http://opensource.org/licenses/bsd-license.php New BSD License |
* @link http://pear.php.net/package/PEAR_ErrorStack |
*/ |
class PEAR_ErrorStack { |
194,12 → 192,12 |
* @access protected |
*/ |
var $_contextCallback = false; |
|
|
/** |
* If set to a valid callback, this will be called every time an error |
* is pushed onto the stack. The return value will be used to determine |
* whether to allow an error to be pushed or logged. |
* |
* |
* The return value must be one an PEAR_ERRORSTACK_* constant |
* @see PEAR_ERRORSTACK_PUSHANDLOG, PEAR_ERRORSTACK_PUSH, PEAR_ERRORSTACK_LOG |
* @var false|string|array |
206,7 → 204,7 |
* @access protected |
*/ |
var $_errorCallback = array(); |
|
|
/** |
* PEAR::Log object for logging errors |
* @var false|Log |
213,7 → 211,7 |
* @access protected |
*/ |
var $_logger = false; |
|
|
/** |
* Error messages - designed to be overridden |
* @var array |
220,10 → 218,10 |
* @abstract |
*/ |
var $_errorMsgs = array(); |
|
|
/** |
* Set up a new error stack |
* |
* |
* @param string $package name of the package this error stack represents |
* @param callback $msgCallback callback used for error message generation |
* @param callback $contextCallback callback used for context generation, |
230,7 → 228,7 |
* defaults to {@link getFileLine()} |
* @param boolean $throwPEAR_Error |
*/ |
function PEAR_ErrorStack($package, $msgCallback = false, $contextCallback = false, |
function __construct($package, $msgCallback = false, $contextCallback = false, |
$throwPEAR_Error = false) |
{ |
$this->_package = $package; |
250,12 → 248,13 |
* defaults to {@link getFileLine()} |
* @param boolean $throwPEAR_Error |
* @param string $stackClass class to instantiate |
* @static |
* |
* @return PEAR_ErrorStack |
*/ |
function &singleton($package, $msgCallback = false, $contextCallback = false, |
$throwPEAR_Error = false, $stackClass = 'PEAR_ErrorStack') |
{ |
public static function &singleton( |
$package, $msgCallback = false, $contextCallback = false, |
$throwPEAR_Error = false, $stackClass = 'PEAR_ErrorStack' |
) { |
if (isset($GLOBALS['_PEAR_ERRORSTACK_SINGLETON'][$package])) { |
return $GLOBALS['_PEAR_ERRORSTACK_SINGLETON'][$package]; |
} |
297,15 → 296,14 |
/** |
* Set up a PEAR::Log object for all error stacks that don't have one |
* @param Log $log |
* @static |
*/ |
function setDefaultLogger(&$log) |
public static function setDefaultLogger(&$log) |
{ |
if (is_object($log) && method_exists($log, 'log') ) { |
$GLOBALS['_PEAR_ERRORSTACK_DEFAULT_LOGGER'] = &$log; |
} elseif (is_callable($log)) { |
$GLOBALS['_PEAR_ERRORSTACK_DEFAULT_LOGGER'] = &$log; |
} |
} |
} |
|
/** |
358,9 → 356,8 |
* messages for a singleton |
* @param array|string Callback function/method |
* @param string Package name, or false for all packages |
* @static |
*/ |
function setDefaultCallback($callback = false, $package = false) |
public static function setDefaultCallback($callback = false, $package = false) |
{ |
if (!is_callable($callback)) { |
$callback = false; |
432,9 → 429,8 |
* @see PEAR_ERRORSTACK_PUSHANDLOG, PEAR_ERRORSTACK_PUSH, PEAR_ERRORSTACK_LOG |
* @see staticPopCallback(), pushCallback() |
* @param string|array $cb |
* @static |
*/ |
function staticPushCallback($cb) |
public static function staticPushCallback($cb) |
{ |
array_push($GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK'], $cb); |
} |
443,9 → 439,8 |
* Remove a temporary overriding error callback |
* @see staticPushCallback() |
* @return array|string|false |
* @static |
*/ |
function staticPopCallback() |
public static function staticPopCallback() |
{ |
$ret = array_pop($GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK']); |
if (!is_array($GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK'])) { |
604,11 → 599,11 |
* to find error context |
* @return PEAR_Error|array if compatibility mode is on, a PEAR_Error is also |
* thrown. see docs for {@link push()} |
* @static |
*/ |
function staticPush($package, $code, $level = 'error', $params = array(), |
$msg = false, $repackage = false, $backtrace = false) |
{ |
public static function staticPush( |
$package, $code, $level = 'error', $params = array(), |
$msg = false, $repackage = false, $backtrace = false |
) { |
$s = &PEAR_ErrorStack::singleton($package); |
if ($s->_contextCallback) { |
if (!$backtrace) { |
750,9 → 745,8 |
* @param string|false Package name to check for errors |
* @param string Level name to check for a particular severity |
* @return boolean |
* @static |
*/ |
function staticHasErrors($package = false, $level = false) |
public static function staticHasErrors($package = false, $level = false) |
{ |
if ($package) { |
if (!isset($GLOBALS['_PEAR_ERRORSTACK_SINGLETON'][$package])) { |
776,12 → 770,13 |
* @param boolean $merge Set to return a flat array, not organized by package |
* @param array $sortfunc Function used to sort a merged array - default |
* sorts by time, and should be good for most cases |
* @static |
* |
* @return array |
*/ |
function staticGetErrors($purge = false, $level = false, $merge = false, |
$sortfunc = array('PEAR_ErrorStack', '_sortErrors')) |
{ |
public static function staticGetErrors( |
$purge = false, $level = false, $merge = false, |
$sortfunc = array('PEAR_ErrorStack', '_sortErrors') |
) { |
$ret = array(); |
if (!is_callable($sortfunc)) { |
$sortfunc = array('PEAR_ErrorStack', '_sortErrors'); |
806,7 → 801,7 |
* Error sorting function, sorts by time |
* @access private |
*/ |
function _sortErrors($a, $b) |
public static function _sortErrors($a, $b) |
{ |
if ($a['time'] == $b['time']) { |
return 0; |
829,9 → 824,8 |
* @param unused |
* @param integer backtrace frame. |
* @param array Results of debug_backtrace() |
* @static |
*/ |
function getFileLine($code, $params, $backtrace = null) |
public static function getFileLine($code, $params, $backtrace = null) |
{ |
if ($backtrace === null) { |
return false; |
857,7 → 851,7 |
'line' => $filebacktrace['line']); |
// rearrange for eval'd code or create function errors |
if (strpos($filebacktrace['file'], '(') && |
preg_match(';^(.*?)\((\d+)\) : (.*?)$;', $filebacktrace['file'], |
preg_match(';^(.*?)\((\d+)\) : (.*?)\\z;', $filebacktrace['file'], |
$matches)) { |
$ret['file'] = $matches[1]; |
$ret['line'] = $matches[2] + 0; |
903,10 → 897,10 |
* @param PEAR_ErrorStack |
* @param array |
* @param string|false Pre-generated error message template |
* @static |
* |
* @return string |
*/ |
function getErrorMessage(&$stack, $err, $template = false) |
public static function getErrorMessage(&$stack, $err, $template = false) |
{ |
if ($template) { |
$mainmsg = $template; |