Open Journal Systems  3.3.0
PEAR_ErrorStack Class Reference

Public Member Functions

 __construct ($package, $msgCallback=false, $contextCallback=false, $throwPEAR_Error=false)
 
 _handleError ($err)
 
 _log ($err)
 
 getErrorMessageTemplate ($code)
 
 getErrors ($purge=false, $level=false)
 
 getMessageCallback ()
 
 hasErrors ($level=false)
 
 pop ()
 
 popCallback ()
 
 push ($code, $level='error', $params=array(), $msg=false, $repackage=false, $backtrace=false)
 
 pushCallback ($cb)
 
 raiseError ()
 
 setContextCallback ($contextCallback)
 
 setErrorMessageTemplate ($template)
 
 setLogger (&$log)
 
 setMessageCallback ($msgCallback)
 

Static Public Member Functions

static _sortErrors ($a, $b)
 
static getErrorMessage (&$stack, $err, $template=false)
 
static getFileLine ($code, $params, $backtrace=null)
 
static setDefaultCallback ($callback=false, $package=false)
 
static setDefaultLogger (&$log)
 
static & singleton ( $package, $msgCallback=false, $contextCallback=false, $throwPEAR_Error=false, $stackClass='PEAR_ErrorStack')
 
static staticGetErrors ( $purge=false, $level=false, $merge=false, $sortfunc=array('PEAR_ErrorStack', '_sortErrors'))
 
static staticHasErrors ($package=false, $level=false)
 
static staticPop ($package)
 
static staticPopCallback ()
 
static staticPush ( $package, $code, $level='error', $params=array(), $msg=false, $repackage=false, $backtrace=false)
 
static staticPushCallback ($cb)
 

Data Fields

 $_compat = false
 
 $_contextCallback = false
 
 $_errorCallback = array()
 
 $_errorMsgs = array()
 
 $_errors = array()
 
 $_errorsByLevel = array()
 
 $_logger = false
 
 $_msgCallback = false
 
 $_package
 

Detailed Description

Definition at line 141 of file ErrorStack.php.

Constructor & Destructor Documentation

◆ __construct()

PEAR_ErrorStack::__construct (   $package,
  $msgCallback = false,
  $contextCallback = false,
  $throwPEAR_Error = false 
)

Set up a new error stack

Parameters
string$packagename of the package this error stack represents
callback$msgCallbackcallback used for error message generation
callback$contextCallbackcallback used for context generation, defaults to getFileLine()
boolean$throwPEAR_Error

Definition at line 258 of file ErrorStack.php.

References setContextCallback(), and setMessageCallback().

Member Function Documentation

◆ _handleError()

PEAR_ErrorStack::_handleError (   $err)

Internal error handler for PEAR_ErrorStack class

Dies if the error is an exception (and would have died anyway) @access private

Definition at line 309 of file ErrorStack.php.

◆ _log()

PEAR_ErrorStack::_log (   $err)

Log an error using PEAR::Log

Parameters
array$errError array
array$levelsError level => Log constant map @access protected

Definition at line 651 of file ErrorStack.php.

References $_logger, and $GLOBALS.

Referenced by push().

◆ _sortErrors()

static PEAR_ErrorStack::_sortErrors (   $a,
  $b 
)
static

Error sorting function, sorts by time @access private

Definition at line 831 of file ErrorStack.php.

◆ getErrorMessage()

static PEAR_ErrorStack::getErrorMessage ( $stack,
  $err,
  $template = false 
)
static

Standard error message generation callback

This method may also be called by a custom error message generator to fill in template values from the params array, simply set the third parameter to the error message template string to use

The special variable __msg% is reserved: use it only to specify where a message passed in by the user should be placed in the template, like so:

Error message: msg% - internal error

If the message passed like so:

$stack->push(ERROR_CODE, 'error', array(), 'server error 500');

The returned error message will be "Error message: server error 500 - internal error"

Parameters
PEAR_ErrorStack
array
string|falsePre-generated error message template
Returns
string

Definition at line 930 of file ErrorStack.php.

References staticPush().

◆ getErrorMessageTemplate()

PEAR_ErrorStack::getErrorMessageTemplate (   $code)

Standard Error Message Template generator from code

Returns
string

Definition at line 964 of file ErrorStack.php.

◆ getErrors()

PEAR_ErrorStack::getErrors (   $purge = false,
  $level = false 
)

Retrieve all errors since last purge

Parameters
booleanset in order to empty the error stack
stringlevel name, to return only errors of a particular severity
Returns
array

Definition at line 737 of file ErrorStack.php.

References $_errors.

◆ getFileLine()

static PEAR_ErrorStack::getFileLine (   $code,
  $params,
  $backtrace = null 
)
static

Standard file/line number/function/class context callback

This function uses a backtrace generated from debug_backtrace() and so will not work at all in PHP < 4.3.0. The frame should reference the frame that contains the source of the error.

Returns
array|false either array('file' => file, 'line' => line, 'function' => function name, 'class' => class name) or if this doesn't work, then false
Parameters
unused
integerbacktrace frame.
arrayResults of debug_backtrace()

Definition at line 855 of file ErrorStack.php.

◆ getMessageCallback()

PEAR_ErrorStack::getMessageCallback ( )

Get an error code => error message mapping callback

This method returns the current callback that can be used to generate error messages

Returns
array|string|false Callback function/method or false if none

Definition at line 374 of file ErrorStack.php.

References $_msgCallback.

◆ hasErrors()

PEAR_ErrorStack::hasErrors (   $level = false)

Determine whether there are any errors on the stack

Parameters
string|arrayLevel name. Use to determine if any errors of level (string), or levels (array) have been pushed
Returns
boolean

Definition at line 722 of file ErrorStack.php.

◆ pop()

PEAR_ErrorStack::pop ( )

Pop an error off of the error stack

Returns
false|array
Since
0.4alpha it is no longer possible to specify a specific error level to return - the last error pushed will be returned, instead

Definition at line 687 of file ErrorStack.php.

◆ popCallback()

PEAR_ErrorStack::popCallback ( )

Remove a callback from the error callback stack

See also
pushCallback()
Returns
array|string|false

Definition at line 443 of file ErrorStack.php.

Referenced by push().

◆ push()

PEAR_ErrorStack::push (   $code,
  $level = 'error',
  $params = array(),
  $msg = false,
  $repackage = false,
  $backtrace = false 
)

Add an error to the stack

If the message generator exists, it is called with 2 parameters.

  • the current Error Stack object
  • an array that is in the same format as an error. Available indices are 'code', 'package', 'time', 'params', 'level', and 'context'

Next, if the error should contain context information, this is handled by the context grabbing method. Finally, the error is pushed onto the proper error stack

Parameters
int$codePackage-specific error code
string$levelError level. This is NOT spell-checked
array$paramsassociative array of error parameters
string$msgError message, or a portion of it if the message is to be generated
array$repackageIf this error re-packages an error pushed by another package, place the array returned from pop() in this parameter
array$backtraceProtected parameter: use this to pass in the debug_backtrace() that should be used to find error context
Returns
PEAR_Error|array if compatibility mode is on, a PEAR_Error is also thrown. If a PEAR_Error is returned, the userinfo property is set to the following array:

array( 'code' => $code, 'params' => $params, 'package' => $this->_package, 'level' => $level, 'time' => time(), 'context' => $context, 'message' => $msg, //['repackage' => $err] repackaged error array/Exception class );

Normally, the previous array is returned.

Definition at line 520 of file ErrorStack.php.

References $_package, $GLOBALS, _log(), popCallback(), pushCallback(), raiseError(), staticPopCallback(), and staticPushCallback().

◆ pushCallback()

PEAR_ErrorStack::pushCallback (   $cb)

Set an error Callback 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 of the ERRORSTACK_* constants.

This functionality can be used to emulate PEAR's pushErrorHandling, and the PEAR_ERROR_CALLBACK mode, without affecting the integrity of the error stack or logging

See also
PEAR_ERRORSTACK_PUSHANDLOG, PEAR_ERRORSTACK_PUSH, PEAR_ERRORSTACK_LOG
popCallback()
Parameters
string | array$cb

Definition at line 433 of file ErrorStack.php.

Referenced by push().

◆ raiseError()

PEAR_ErrorStack::raiseError ( )

emulate PEAR::raiseError()

Returns
PEAR_Error

Definition at line 997 of file ErrorStack.php.

Referenced by push().

◆ setContextCallback()

PEAR_ErrorStack::setContextCallback (   $contextCallback)

Set a callback that generates context information (location of error) for an error stack

This method sets the callback that can be used to generate context information for an error. Passing in NULL will disable context generation and remove the expensive call to debug_backtrace()

Parameters
array|string|nullCallback function/method

Definition at line 404 of file ErrorStack.php.

Referenced by __construct().

◆ setDefaultCallback()

static PEAR_ErrorStack::setDefaultCallback (   $callback = false,
  $package = false 
)
static

Sets a default callback to be used by all error stacks

This method sets the callback that can be used to generate error messages for a singleton

Parameters
array|stringCallback function/method
stringPackage name, or false for all packages

Definition at line 387 of file ErrorStack.php.

References $GLOBALS.

◆ setDefaultLogger()

static PEAR_ErrorStack::setDefaultLogger ( $log)
static

Set up a PEAR::Log object for all error stacks that don't have one

Parameters
Log$log

Definition at line 327 of file ErrorStack.php.

References $GLOBALS.

◆ setErrorMessageTemplate()

PEAR_ErrorStack::setErrorMessageTemplate (   $template)

Set the Error Message Template array

The array format must be:

array(error code => 'message template',...)

Error message parameters passed into push() will be used as input for the error message. If the template is 'message foo% was bar', and the parameters are array('foo' => 'one', 'bar' => 'six'), the error message returned will be 'message one was six'

Returns
string

Definition at line 986 of file ErrorStack.php.

◆ setLogger()

PEAR_ErrorStack::setLogger ( $log)

Set up a PEAR::Log object for this error stack

Parameters
Log$log

Definition at line 340 of file ErrorStack.php.

◆ setMessageCallback()

PEAR_ErrorStack::setMessageCallback (   $msgCallback)

Set an error code => error message mapping callback

This method sets the callback that can be used to generate error messages for any instance

Parameters
array|stringCallback function/method

Definition at line 356 of file ErrorStack.php.

Referenced by __construct().

◆ singleton()

static& PEAR_ErrorStack::singleton (   $package,
  $msgCallback = false,
  $contextCallback = false,
  $throwPEAR_Error = false,
  $stackClass = 'PEAR_ErrorStack' 
)
static

Return a single error stack for this package.

Note that all parameters are ignored if the stack for package $package has already been instantiated

Parameters
string$packagename of the package this error stack represents
callback$msgCallbackcallback used for error message generation
callback$contextCallbackcallback used for context generation, defaults to getFileLine()
boolean$throwPEAR_Error
string$stackClassclass to instantiate
Returns
PEAR_ErrorStack

Definition at line 281 of file ErrorStack.php.

References $GLOBALS, and staticPush().

Referenced by staticPush().

◆ staticGetErrors()

static PEAR_ErrorStack::staticGetErrors (   $purge = false,
  $level = false,
  $merge = false,
  $sortfunc = array('PEAR_ErrorStack', '_sortErrors') 
)
static

Get a list of all errors since last purge, organized by package

Since
PEAR 1.4.0dev BC break! $level is now in the place $merge used to be
Parameters
boolean$purgeSet to purge the error stack of existing errors
string$levelSet to a level name in order to retrieve only errors of a particular level
boolean$mergeSet to return a flat array, not organized by package
array$sortfuncFunction used to sort a merged array - default sorts by time, and should be good for most cases
Returns
array

Definition at line 803 of file ErrorStack.php.

References $GLOBALS.

◆ staticHasErrors()

static PEAR_ErrorStack::staticHasErrors (   $package = false,
  $level = false 
)
static

Determine whether there are any errors on a single error stack, or on any error stack

The optional parameter can be used to test the existence of any errors without the need of singleton instantiation

Parameters
string|falsePackage name to check for errors
stringLevel name to check for a particular severity
Returns
boolean

Definition at line 776 of file ErrorStack.php.

References $GLOBALS.

◆ staticPop()

static PEAR_ErrorStack::staticPop (   $package)
static

Pop an error off of the error stack, static method

Parameters
stringpackage name
Returns
boolean
Since
PEAR1.5.0a1

Definition at line 706 of file ErrorStack.php.

References $GLOBALS.

◆ staticPopCallback()

static PEAR_ErrorStack::staticPopCallback ( )
static

Remove a temporary overriding error callback

See also
staticPushCallback()
Returns
array|string|false

Definition at line 470 of file ErrorStack.php.

References $GLOBALS.

Referenced by push().

◆ staticPush()

static PEAR_ErrorStack::staticPush (   $package,
  $code,
  $level = 'error',
  $params = array(),
  $msg = false,
  $repackage = false,
  $backtrace = false 
)
static

Static version of push()

Parameters
string$packagePackage name this error belongs to
int$codePackage-specific error code
string$levelError level. This is NOT spell-checked
array$paramsassociative array of error parameters
string$msgError message, or a portion of it if the message is to be generated
array$repackageIf this error re-packages an error pushed by another package, place the array returned from pop() in this parameter
array$backtraceProtected parameter: use this to pass in the debug_backtrace() that should be used to find error context
Returns
PEAR_Error|array if compatibility mode is on, a PEAR_Error is also thrown. see docs for push()

Definition at line 630 of file ErrorStack.php.

References singleton().

Referenced by getErrorMessage(), and singleton().

◆ staticPushCallback()

static PEAR_ErrorStack::staticPushCallback (   $cb)
static

Set a temporary overriding error callback for every package error stack

Use this to temporarily disable all existing callbacks (can be used to emulate the @ operator, for instance)

See also
PEAR_ERRORSTACK_PUSHANDLOG, PEAR_ERRORSTACK_PUSH, PEAR_ERRORSTACK_LOG
staticPopCallback(), pushCallback()
Parameters
string | array$cb

Definition at line 460 of file ErrorStack.php.

References $GLOBALS.

Referenced by push().

Field Documentation

◆ $_compat

boolean PEAR_ErrorStack::$_compat = false

Determines whether a PEAR_Error is thrown upon every error addition

@access private

Definition at line 186 of file ErrorStack.php.

◆ $_contextCallback

false string array PEAR_ErrorStack::$_contextCallback = false

If set to a valid callback, this will be used to generate the error context for an error. For PHP-related errors, this will be a file and line number as retrieved from debug_backtrace(), but can be customized for other purposes. The error might actually be in a separate configuration file, or in a database query.

@access protected

Definition at line 212 of file ErrorStack.php.

◆ $_errorCallback

false string array PEAR_ErrorStack::$_errorCallback = array()

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 also
PEAR_ERRORSTACK_PUSHANDLOG, PEAR_ERRORSTACK_PUSH, PEAR_ERRORSTACK_LOG

@access protected

Definition at line 227 of file ErrorStack.php.

◆ $_errorMsgs

array PEAR_ErrorStack::$_errorMsgs = array()

Error messages - designed to be overridden

@abstract

Definition at line 247 of file ErrorStack.php.

◆ $_errors

array PEAR_ErrorStack::$_errors = array()

Errors are stored in the order that they are pushed on the stack.

Since
0.4alpha Errors are no longer organized by error level. This renders pop() nearly unusable, and levels could be more easily handled in a callback anyway

@access private

Definition at line 153 of file ErrorStack.php.

Referenced by getErrors().

◆ $_errorsByLevel

array PEAR_ErrorStack::$_errorsByLevel = array()

Storage of errors by level.

Allows easy retrieval and deletion of only errors from a particular level

Since
PEAR 1.4.0dev

@access private

Definition at line 166 of file ErrorStack.php.

◆ $_logger

false Log PEAR_ErrorStack::$_logger = false

PEAR::Log object for logging errors

@access protected

Definition at line 237 of file ErrorStack.php.

Referenced by _log().

◆ $_msgCallback

false string array PEAR_ErrorStack::$_msgCallback = false

If set to a valid callback, this will be used to generate the error message from the error code, otherwise the message passed in will be used

@access private

Definition at line 198 of file ErrorStack.php.

Referenced by getMessageCallback().

◆ $_package

string PEAR_ErrorStack::$_package

Package name this error stack represents

@access protected

Definition at line 176 of file ErrorStack.php.

Referenced by push().


The documentation for this class was generated from the following file: