tangra logo
   
[ class tree: tangra_lib ] [ index: tangra_lib ] [ all elements ]
 

Source for file exception_handler.class.php

Documentation is available at exception_handler.class.php

  1. <?php
  2. // *** Tangra (Application Framework and Tools for PHP)
  3. // $Id$
  4. //
  5.  
  6. /**
  7.  * Contains class Exception_Handler
  8.  *
  9.  * @package  tangra_lib
  10.  * @subpackage  core
  11.  */
  12.  
  13.  
  14. /**
  15.  * Loading interface
  16.  */
  17. require_once(TANGRA_MAIN_DIR.'interfaces/i_exception_listener.class.php');
  18.  
  19.  
  20. /**
  21.  * Used for central registar for exception listeners.
  22.  *
  23.  * Exception_Handler is used to register all exception listeners and call each one of them when exception occures.
  24.  * Normally this class is not used directly by the users.
  25.  *
  26.  * @package  tangra_lib
  27.  * @subpackage  core
  28.  */
  29. class Exception_Handler extends Tangra_Class {
  30.     /**
  31.      * Simple array that contains registered listeners
  32.      *
  33.      * @var array 
  34.      * @access private
  35.      */
  36.     private $listeners = array();
  37.  
  38.  
  39.     /**
  40.      * Adds new listener
  41.      *
  42.      * @param I_Exception_Listener $el 
  43.      * @return boolean  Returns  true on success and false on failure
  44.      */
  45.     public function add_listener(I_Exception_Listener $el{
  46.         return array_push($this->listeners$el);
  47.     }
  48.  
  49.  
  50.     /**
  51.      * Calls each of the registered listeners with exceptin $e as parameter.
  52.      *
  53.      * @param Exception $e 
  54.      */
  55.     public function handler(Exception $e{
  56.         foreach($this->listeners as $l{
  57.             $l->error($e);
  58.         }
  59.     }
  60. }