Source for file Error.class.php
Documentation is available at Error.class.php
* Gumbo Library Framework
* This library is being released under the terms of the New BSD License. A
* copy of the license is packaged with the software (LICENSE.txt). If no
* copy is found, a copy of the license template can be found at:
* http://www.opensource.org/licenses/bsd-license.php
* @copyright Copyright (c) 2007, iBayou, Michael Luster
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @author Michael Luster <mluster79@yahoo.com>
* @link http://sourceforge.net/projects/phpgumbo
* @copyright Copyright (c) 2007, iBayou, Michael Luster
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @author Michael Luster <mluster79@yahoo.com>
* @link http://sourceforge.net/projects/phpgumbo
gumbo_load ("Interface_Error");
gumbo_load ("Interface_Singleton");
gumbo_load ("Interface_Observerable");
class Gumbo_Error implements Gumbo_Interface_Error, Gumbo_Interface_Singleton, IteratorAggregate, Gumbo_Interface_Observerable {
/** @var int OK no errors found */
/** @var int DEBUG debug error found */
/** @var int NOTICE user notice found */
/** @var int WARNING user warning found */
/** @var int ERROR user error found */
/** @var int CRITICAL critical error found */
/** @var int ALERT alert error found */
/** @var int EMERGENCY emergency error found */
/** @var int ALL all error levels */
/** @var Gumbo_Interface_Singleton $_instance */
private static $_instance =
null;
/** @var array $_observers list of Observer objects */
/** @var int $_level error levels commited during the program execution */
/** @var array $_errors list of Exceptions added to the object */
/** @var bool $_exists if any errors exists */
/** @var int $_report_level the minimum level on errors to report */
/** @var int $_ignore_level disregards any errors at or below this level */
* @return Gumbo_Interface_Error
if (self::$_instance ==
null) {
self::$_instance =
new Gumbo_Error ();
* Attaches an Error_Observer to the object
* @param Gumbo_Interface_Observer $obj
* @return int current error level
public function attach (Gumbo_Interface_Observer $obj) {
// check if object was previously loaded
// add the Error_Observer
// return the current error level
* Detach an Error_Observer from the object
* @param Gumbo_Interface_Observer $obj
public function detach (Gumbo_Interface_Observer $obj) {
if ($val ===
$obj) { unset
($this->_observers [$key]); }
* Notifies the Error_Observers about changes to the system
$val->update (array ("error_level", $this->level ()));
* Adds an Exception to the list
public function add (Exception $e) {
// check if Exception should be ignore
if (!($this->level () & $code)) {
* Clears all the errors from the system
* @postcondition level() = Gumbo_Error::OK
* @postcondition exceptions thrown are cleared
* @param int $level level to clear
public function clear ($level=
null) {
foreach ($this->getAll ($level, true) as $key=>
$e) {
// remove the level from the current error level
if ($this->level () & $level) {
if ($this->count () <=
0) {
* Sets the minimum error reporting level
* A value of 0 reports ALL errors
* Sets the ignore level, which disregards any errors at or below this level
* @param int $level limit to supplied level and above
* @param bool $only limits to only errors at the supplied level
public function getAll ($level=
null, $only=
false) {
if (!is_bool ($only)) { $only =
false; }
// check for non Gumbo_Exception classes
* Returns if any Errors exist
* @param int $level if errors of this level exist
public function exists ($level=
null) {
// return if only errors of given level exists
// set the right Error Level
// return if any errors exist
* Returns the current error level value
* The Error level will be a binary representation of the
* available error level constants. This will allow the system
* to determine the level of errors triggered during program
public function level () {
* Returns the number of errors
* @param int $level number of errors at level
public function count ($level=
null) {
// returning number of specific level of errors
// set proper Error Level of Exception
* Returns the minimum reporting level
* Returns the minimum ignore level
* Returns an Iterator object
// set proper Error Level on Exception
* Returns if the given integer is a valid error level
define ("ERROR_OK", Gumbo_Error::OK);
define ("ERROR_DEBUG", Gumbo_Error::DEBUG);
define ("ERROR_NOTICE", Gumbo_Error::NOTICE);
define ("ERROR_WARNING", Gumbo_Error::WARNING);
define ("ERROR_ERROR", Gumbo_Error::ERROR);
define ("ERROR_CRITICAL", Gumbo_Error::CRITICAL);
define ("ERROR_ALERT", Gumbo_Error::ALERT);
define ("ERROR_EMERGENCY", Gumbo_Error::EMERGENCY);