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

Source for file Exception.class.php

Documentation is available at Exception.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 Exception Handling
  20. *
  21. * Cgiapp2_Exception implements an Observer pattern. You may build observer
  22. * classes that receive notifications when Cgiapp2_Exceptions (or classes
  23. * derived from it) are raised. Such classes need only have an event() method
  24. * that accepts a Cgiapp2_Exception object, and have to register their class or
  25. * an instance with Cgiapp2_Exception using {@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_Exception extends Exception
  33. {
  34. /**
  35. * Array of observers
  36. * @var array
  37. * @static
  38. * @access protected
  39. */
  40. private static $observers = array();
  41.  
  42. /**
  43. * Constructor
  44. *
  45. * @access public
  46. * @param string
  47. * @param int
  48. * @param int
  49. */
  50. public function __construct($message, $code = 0)
  51. {
  52. parent::__construct($message, $code);
  53.  
  54. $this->notify();
  55. }
  56.  
  57. /**
  58. * String representation of exception
  59. *
  60. * @access public
  61. * @return void
  62. */
  63. public function __toString()
  64. {
  65. return __CLASS__ . ': [' . $this->code . ']: ' . $this->message . "\n";
  66. }
  67.  
  68. /**
  69. * Attach an observer
  70. *
  71. * @static
  72. * @access public
  73. * @param string|object $class Classname or object
  74. * @return void
  75. */
  76. final public static function attach($class)
  77. {
  78. if (is_object($class) || class_exists($class)) {
  79. array_push(self::$observers, $class);
  80. }
  81. }
  82.  
  83. /**
  84. * Notify observers of an error event
  85. *
  86. * @access public
  87. * @return void
  88. */
  89. final public function notify()
  90. {
  91. foreach (self::$observers as $class) {
  92. if (is_callable(array($class, 'event'))) {
  93. call_user_func(array($class, 'event'), $this);
  94. }
  95. }
  96. }
  97. }

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