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

Source for file Error.class.php

Documentation is available at Error.class.php

  1. <?php
  2. /**
  3. * Cgiapp2 - Framework for building reusable web-applications
  4. *
  5. * A PHP5 port of perl's CGI::Application, a framework for building reusable web
  6. * applications.
  7. *
  8. * @package Cgiapp2
  9. * @author Matthew Weier O'Phinney <mweierophinney@gmail.com>; based on
  10. * CGI::Application, by Jesse Erlbaum <jesse@erlbaum.net>, et. al.
  11. * @copyright (c) 2004 - present, Matthew Weier O'Phinney
  12. * @license BSD License (http://www.opensource.org/licenses/bsd-license.php)
  13. * @category Tools and Utilities
  14. * @tutorial Cgiapp2/Cgiapp2.cls
  15. * @version $Id:$
  16. */
  17.  
  18. /**
  19. * Cgiapp2 PHP Error Handling
  20. *
  21. * Cgiapp2_Error implements an Observer pattern for PHP errors. You may build a
  22. * observer classes that receivee notifications when PHP errors are raised. Such
  23. * classes need only have an event() method that accepts a Cgiapp2_Error object,
  24. * and have to register their class or an instance with Cgiapp2_Error using
  25. * {@link attach()}.
  26. *
  27. * @package Cgiapp2
  28. * @author Matthew Weier O'Phinney <mweierophinney@gmail.com>
  29. * @copyright (c) 2006 - present Matthew Weier O'Phinney
  30. * @version @release-version@
  31. */
  32. class Cgiapp2_Error
  33. {
  34. /**@+
  35. * @access public
  36. */
  37.  
  38. /**
  39. * Error level integer
  40. * @var int
  41. * @access public
  42. */
  43. public $errno;
  44.  
  45. /**
  46. * Error message
  47. * @var string
  48. * @access public
  49. */
  50. public $errstr;
  51.  
  52. /**
  53. * Filename in which error was raised
  54. * @var string
  55. * @access public
  56. */
  57. public $errfile;
  58.  
  59. /**
  60. * Line number in which error was raised
  61. * @var int
  62. * @access public
  63. */
  64. public $errline;
  65.  
  66. /**
  67. * Symbol table at point where error occurred
  68. * @var array
  69. * @access public
  70. */
  71. public $errcontext;
  72.  
  73. /**
  74. * Array of observers
  75. * @var array
  76. * @static
  77. * @access protected
  78. */
  79. private static $observers = array();
  80.  
  81. /**
  82. * Constructor
  83. *
  84. * @access public
  85. * @param string
  86. * @param int
  87. * @param int
  88. */
  89. public function __construct($errno, $errstr, $errfile = null, $errline = null, $errcontext = null)
  90. {
  91. $this->errno = $errno;
  92. $this->errstr = $errstr;
  93. $this->errfile = $errfile;
  94. $this->errline = $errline;
  95. $this->errcontext = $errcontext;
  96.  
  97. $this->notify();
  98. }
  99.  
  100. /**
  101. * Handle PHP Errors
  102. *
  103. * Creates a Cgiapp2_Error from a PHP error (if the PHP error handler has
  104. * been set to this method).
  105. *
  106. * @static
  107. * @access public
  108. */
  109. public static function handler($errno, $errstr, $errfile = null, $errline = null, $errcontext = null)
  110. {
  111. return new Cgiapp2_Error($errno, $errstr, $errfile, $errline, $errcontext);
  112. }
  113.  
  114. /**
  115. * String representation of exception
  116. *
  117. * @access public
  118. * @return void
  119. */
  120. public function __toString()
  121. {
  122. return __CLASS__ . ': [' . $this->code . ']: ' . $this->message . "\n";
  123. }
  124.  
  125. /**
  126. * Attach an observer
  127. *
  128. * @static
  129. * @access public
  130. * @param string|object $class Classname or object
  131. * @return void
  132. */
  133. final public static function attach($class)
  134. {
  135. if (is_object($class) || class_exists($class)) {
  136. array_push(self::$observers, $class);
  137. }
  138. }
  139.  
  140. /**
  141. * Notify observers of an error event
  142. *
  143. * @access public
  144. * @return void
  145. */
  146. final public function notify()
  147. {
  148. foreach (self::$observers as $class) {
  149. if (is_callable(array($class, 'event'))) {
  150. call_user_func(array($class, 'event'), $this);
  151. }
  152. }
  153. }
  154. }

Documentation generated on Sat, 03 Jun 2006 10:48:41 -0400 by phpDocumentor 1.3.0RC5