[ Index ]
 

Code source de SPIP Agora 1.4

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/Pear/PEAR/ -> ErrorStack.php (sommaire)

Error Stack Implementation This is an incredibly simple implementation of a very complex error handling facility.  It contains the ability to track multiple errors from multiple packages simultaneously.  In addition, it can track errors of many levels, save data along with the error, context information such as the exact file, line number, class and function that generated the error, and if necessary, it can raise a traditional PEAR_Error. It has built-in support for PEAR::Log, to log errors as they occur

Author: Greg Beaver <cellog@php.net>
License: http://www.php.net/license/3_0.txt PHP License v3.0
Version: PEAR1.3.2 (beta)
Poids: 981 lignes (35 kb)
Inclus ou requis:0 fois
Référencé: 0 fois
Nécessite: 0 fichiers

Définit 1 class

PEAR_ErrorStack:: (27 méthodes):
  PEAR_ErrorStack()
  singleton()
  _handleError()
  setDefaultLogger()
  setLogger()
  setMessageCallback()
  getMessageCallback()
  setDefaultCallback()
  setContextCallback()
  pushCallback()
  popCallback()
  staticPushCallback()
  staticPopCallback()
  push()
  staticPush()
  _log()
  pop()
  hasErrors()
  getErrors()
  staticHasErrors()
  staticGetErrors()
  _sortErrors()
  getFileLine()
  getErrorMessage()
  getErrorMessageTemplate()
  setErrorMessageTemplate()
  raiseError()


Classe: PEAR_ErrorStack  - X-Ref

Error Stack Implementation

Usage:
<code>
// global error stack
$global_stack = &PEAR_ErrorStack::singleton('MyPackage');
// local error stack
$local_stack = new PEAR_ErrorStack('MyPackage');
</code>
PEAR_ErrorStack($package, $msgCallback = false, $contextCallback = false,$throwPEAR_Error = false)   X-Ref
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,
param: boolean  $throwPEAR_Error

singleton($package, $msgCallback = false, $contextCallback = false,$throwPEAR_Error = false, $stackClass = 'PEAR_ErrorStack')   X-Ref
Return a single error stack for this package.

Note that all parameters are ignored if the stack for package $package
has already been instantiated
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,
param: boolean  $throwPEAR_Error
param: string   $stackClass class to instantiate
return: PEAR_ErrorStack

_handleError($err)   X-Ref
Internal error handler for PEAR_ErrorStack class

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

setDefaultLogger(&$log)   X-Ref
Set up a PEAR::Log object for all error stacks that don't have one

param: Log $log

setLogger(&$log)   X-Ref
Set up a PEAR::Log object for this error stack

param: Log $log

setMessageCallback($msgCallback)   X-Ref
Set an error code => error message mapping callback

This method sets the callback that can be used to generate error
messages for any instance
param: array|string Callback function/method

getMessageCallback()   X-Ref
Get an error code => error message mapping callback

This method returns the current callback that can be used to generate error
messages
return: array|string|false Callback function/method or false if none

setDefaultCallback($callback = false, $package = false)   X-Ref
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
param: array|string Callback function/method
param: string Package name, or false for all packages

setContextCallback($contextCallback)   X-Ref
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()
param: array|string|null Callback function/method

pushCallback($cb)   X-Ref
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
param: string|array $cb

popCallback()   X-Ref
Remove a callback from the error callback stack

return: array|string|false

staticPushCallback($cb)   X-Ref
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)
param: string|array $cb

staticPopCallback()   X-Ref
Remove a temporary overriding error callback

return: array|string|false

push($code, $level = 'error', $params = array()   X-Ref
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
param: int    $code      Package-specific error code
param: string $level     Error level.  This is NOT spell-checked
param: array  $params    associative array of error parameters
param: string $msg       Error message, or a portion of it if the message
param: array  $repackage If this error re-packages an error pushed by
param: array  $backtrace Protected parameter: use this to pass in the
return: PEAR_Error|array|Exception

staticPush($package, $code, $level = 'error', $params = array()   X-Ref
Static version of {@link push()}

param: string $package   Package name this error belongs to
param: int    $code      Package-specific error code
param: string $level     Error level.  This is NOT spell-checked
param: array  $params    associative array of error parameters
param: string $msg       Error message, or a portion of it if the message
param: array  $repackage If this error re-packages an error pushed by
param: array  $backtrace Protected parameter: use this to pass in the
return: PEAR_Error|null|Exception

_log($err)   X-Ref
Log an error using PEAR::Log

param: array $err Error array
param: array $levels Error level => Log constant map

pop()   X-Ref
Pop an error off of the error stack

return: false|array

hasErrors($level = false)   X-Ref
Determine whether there are any errors on the stack

param: string|array Level name.  Use to determine if any errors
return: boolean

getErrors($purge = false, $level = false)   X-Ref
Retrieve all errors since last purge

param: boolean set in order to empty the error stack
param: string level name, to return only errors of a particular severity
return: array

staticHasErrors($package = false, $level = false)   X-Ref
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
param: string|false Package name to check for errors
param: string Level name to check for a particular severity
return: boolean

staticGetErrors($purge = false, $level = false, $merge = false,$sortfunc = array('PEAR_ErrorStack', '_sortErrors')   X-Ref
Get a list of all errors since last purge, organized by package

param: boolean $purge Set to purge the error stack of existing errors
param: string  $level Set to a level name in order to retrieve only errors of a particular level
param: boolean $merge Set to return a flat array, not organized by package
param: array   $sortfunc Function used to sort a merged array - default
return: array

_sortErrors($a, $b)   X-Ref
Error sorting function, sorts by time


getFileLine($code, $params, $backtrace = null)   X-Ref
Standard file/line number/function/class context callback

This function uses a backtrace generated from {@link 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.
param: unused
param: integer backtrace frame.
param: array Results of debug_backtrace()
return: array|false either array('file' => file, 'line' => line,

getErrorMessage(&$stack, $err, $template = false)   X-Ref
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:

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

The returned error message will be "Error message: server error 500 -
internal error"
param: PEAR_ErrorStack
param: array
param: string|false Pre-generated error message template
return: string

getErrorMessageTemplate($code)   X-Ref
Standard Error Message Template generator from code

return: string

setErrorMessageTemplate($template)   X-Ref
Set the Error Message Template array

The array format must be:
<pre>
array(error code => 'message template',...)
</pre>

Error message parameters passed into {@link 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'
return: string

raiseError()   X-Ref
emulate PEAR::raiseError()

return: PEAR_Error



Généré le : Sat Feb 24 14:40:03 2007 par Balluche grâce à PHPXref 0.7