PEAR_ErrorStack
[ class tree: PEAR_ErrorStack ] [ index: PEAR_ErrorStack ] [ all elements ]

Class: PEAR_ErrorStack

Source Location: /PEAR-1.3.1/PEAR/ErrorStack.php

Class Overview


Error Stack Implementation


Author(s):

Copyright:

  • 2004 Gregory Beaver

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 131]
Error Stack Implementation

Usage:

  1.  // global error stack
  2.  $global_stack &PEAR_ErrorStack::singleton('MyPackage');
  3.  // local error stack
  4.  $local_stack = new PEAR_ErrorStack('MyPackage');



[ Top ]


Class Variables

$_contextCallback =  false

[line 174]

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

Type:   false|string|array


[ Top ]

$_errorCallback = array()

[line 186]

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


Type:   false|string|array


[ Top ]

$_exceptionClass =  'Exception'

[line 200]

Class name to use for a PHP 5 exception that will be returned
  • Access: protected

Type:   string


[ Top ]

$_logger =  false

[line 193]

PEAR::Log object for logging errors
  • Access: protected

Type:   false|Log


[ Top ]

$_package =

[line 147]

Package name this error stack represents
  • Access: protected

Type:   string


[ Top ]



Method Detail

PEAR_ErrorStack (Constructor)   [line 220]

PEAR_ErrorStack PEAR_ErrorStack( string $package, [callback $msgCallback = false], [callback $contextCallback = false], [boolean $throwPEAR_Error = false], [string $exceptionClass = null])

Set up a new error stack

Parameters:

string   $package   —  name of the package this error stack represents
callback   $msgCallback   —  callback used for error message generation
callback   $contextCallback   —  callback used for context generation, defaults to getFileLine()
boolean   $throwPEAR_Error   — 
string   $exceptionClass   —  exception class to instantiate if in PHP 5

[ Top ]

getErrorMessage   [line 816]

string getErrorMessage( PEAR_ErrorStack &$stack, array $err, [string|false $template = false])

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:

  1.  $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   &$stack   — 
array   $err   — 
string|false   $template   —  Pre-generated error message template

[ Top ]

getErrorMessageTemplate   [line 849]

string getErrorMessageTemplate( $code)

Standard Error Message Template generator from code

Parameters:

   $code   — 

[ Top ]

getErrors   [line 656]

array getErrors( [boolean $purge = false])

Retrieve all errors since last purge

Parameters:

boolean   $purge   —  set in order to empty the error stack

[ Top ]

getFileLine   [line 741]

array|false getFileLine( array $code, unused $params, [integer $backtrace = null])

Standard file/line number/function/class context callback

This function uses a backtrace generated from http://www.php.net/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.

  • Return: either array('file' => file, 'line' => line, 'function' => function name, 'class' => class name) or if this doesn't work, then false

Parameters:

array   $code   —  Results of debug_backtrace()
unused   $params   — 
integer   $backtrace   —  backtrace frame.

[ Top ]

getMessageCallback   [line 332]

array|string|false getMessageCallback( )

Get an error code => error message mapping callback

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

  • Return: Callback function/method or false if none

[ Top ]

hasErrors   [line 645]

boolean hasErrors( )

Determine whether there are any errors on the stack

[ Top ]

pop   [line 636]

false|array pop( )

Pop an error off of the error stack
  • Since: 0.4alpha it is no longer possible to specify a specific error level to return - the last error pushed will be returned, instead

[ Top ]

popCallback   [line 396]

array|string|false popCallback( )

Remove a callback from the error callback stack

[ Top ]

push   [line 479]

PEAR_Error|array|Exception push( int $code, [string $level = 'error'], [array $params = array()], [string $msg = false], [array $repackage = false], [array $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

  • Return:

    if compatibility mode is on, a PEAR_Error is also thrown. If the class Exception exists, then one is returned to allow code like:

    1.  throw ($stack->push(MY_ERROR_CODE'error'array('username' => 'grob')));

    The errorData property of the exception class will be set to the array that would normally be returned. If a PEAR_Error is returned, the userinfo property is set to the array

    Otherwise, an array is returned in this format:

    1.  array(
    2.     'code' => $code,
    3.     'params' => $params,
    4.     'package' => $this->_package,
    5.     'level' => $level,
    6.     'time' => time(),
    7.     'context' => $context,
    8.     'message' => $msg,
    9.  //['repackage' => $err] repackaged error array
    10.  );


Parameters:

int   $code   —  Package-specific error code
string   $level   —  Error level. This is NOT spell-checked
array   $params   —  associative array of error parameters
string   $msg   —  Error message, or a portion of it if the message is to be generated
array   $repackage   —  If this error re-packages an error pushed by another package, place the array returned from pop() in this parameter
array   $backtrace   —  Protected parameter: use this to pass in the http://www.php.net/debug_backtrace that should be used to find error context

[ Top ]

pushCallback   [line 386]

void pushCallback( string|array $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


Parameters:

string|array   $cb   — 

[ Top ]

raiseError   [line 882]

PEAR_Error raiseError( )

emulate PEAR::raiseError()

[ Top ]

setContextCallback   [line 360]

void setContextCallback( array|string $contextCallback)

Set an error code => error message mapping callback

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


Parameters:

array|string   $contextCallback   —  Callback function/method

[ Top ]

setDefaultCallback   [line 345]

void setDefaultCallback( [array|string $callback = false])

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|string   $callback   —  Callback function/method

[ Top ]

setDefaultLogger   [line 293]

void setDefaultLogger( &$log, Log $log)

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

Parameters:

Log   $log   — 
   &$log   — 

[ Top ]

setErrorMessageTemplate   [line 871]

string 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'


Parameters:

   $template   — 

[ Top ]

setLogger   [line 302]

void setLogger( &$log, Log $log)

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

Parameters:

Log   $log   — 
   &$log   — 

[ Top ]

setMessageCallback   [line 314]

void setMessageCallback( array|string $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|string   $msgCallback   —  Callback function/method

[ Top ]

singleton   [line 249]

PEAR_ErrorStack &singleton( string $package, [callback $msgCallback = false], [callback $contextCallback = false], [boolean $throwPEAR_Error = false], [string $exceptionClass = null], [string $stackClass = 'PEAR_ErrorStack'])

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   $package   —  name of the package this error stack represents
callback   $msgCallback   —  callback used for error message generation
callback   $contextCallback   —  callback used for context generation, defaults to getFileLine()
boolean   $throwPEAR_Error   — 
string   $exceptionClass   —  exception class to instantiate if in PHP 5
string   $stackClass   —  class to instantiate

[ Top ]

staticGetErrors   [line 690]

array staticGetErrors( [ $purge = false], [boolean $merge = false], [array $sortfunc = array('PEAR_ErrorStack', '_sortErrors')], boolean $clearStack)

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

Parameters:

boolean   $clearStack   —  Set to purge the error stack of existing errors
boolean   $merge   —  Set to return a flat array, not organized by package
array   $sortfunc   —  Function used to sort a merged array - default sorts by time, and should be good for most cases
   $purge   — 

[ Top ]

staticHasErrors   [line 671]

boolean staticHasErrors( )

Determine whether there are any errors on any error stack

[ Top ]

staticPopCallback   [line 424]

array|string|false staticPopCallback( )

Remove a callback from every error callback stack

[ Top ]

staticPush   [line 588]

PEAR_Error|null|Exception staticPush( string $package, int $code, [string $level = 'error'], [array $params = array()], [string $msg = false], [array $repackage = false], [array $backtrace = false])

Static version of push()
  • Return: if compatibility mode is on, a PEAR_Error is also thrown. If the class Exception exists, then one is returned to allow code like:
    1.  throw ($stack->push(MY_ERROR_CODE'error'array('username' => 'grob')));

Parameters:

string   $package   —  Package name this error belongs to
int   $code   —  Package-specific error code
string   $level   —  Error level. This is NOT spell-checked
array   $params   —  associative array of error parameters
string   $msg   —  Error message, or a portion of it if the message is to be generated
array   $repackage   —  If this error re-packages an error pushed by another package, place the array returned from pop() in this parameter
array   $backtrace   —  Protected parameter: use this to pass in the http://www.php.net/debug_backtrace that should be used to find error context

[ Top ]

staticPushCallback   [line 411]

void staticPushCallback( string|array $cb)

Set an error Callback for every package error stack

Parameters:

string|array   $cb   — 

[ Top ]

_log   [line 606]

void _log( array $err, [array $levels = array( 'exception' => PEAR_LOG_CRIT, 'alert' => PEAR_LOG_ALERT, 'critical' => PEAR_LOG_CRIT, 'error' => PEAR_LOG_ERR, 'warning' => PEAR_LOG_WARNING, 'notice' => PEAR_LOG_NOTICE, 'info' => PEAR_LOG_INFO, 'debug' => PEAR_LOG_DEBUG)])

Log an error using PEAR::Log
  • Access: protected

Parameters:

array   $err   —  Error array
array   $levels   —  Error level => Log constant map

[ Top ]


Documentation generated on Mon, 11 Mar 2019 10:14:40 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.