Skip to content

Instantly share code, notes, and snippets.

@BenExile
Created November 14, 2011 00:12
Show Gist options
  • Save BenExile/1362952 to your computer and use it in GitHub Desktop.
Save BenExile/1362952 to your computer and use it in GitHub Desktop.
Listener status concept
<?php
/**
* @author Paul Dragoonis (dragoonis@php.net)
* @license http://opensource.org/licenses/mit-license.php MIT
* @package Core
* @link wwww.ppi.io
*/
namespace PPI\Exception;
class Handler implements ExceptionInterface {
/**
* The event listeners
*
* @var array
*/
protected $_listeners = array();
/**
* Listener status
*
* @var array
*/
protected $_listenerStatus = array();
/**
* PPI Exception handler
* The try/catch block will prevent a fatal error if an exception is thrown within the handler itself
*
* @param object $e Exception object
*/
public function handle(\Exception $e) {
try {
$trace = $e->getTrace();
// Execute each callback
foreach($this->_listeners as $listener){
$response = $listener->handle($e);
$this->_listenerStatus[] = array(
'object' => get_class($listener),
'response' => $response,
);
}
require(SYSTEMPATH . 'View' . DS . 'Exception.php');
} catch(\Exception $e){
require(SYSTEMPATH . 'View' . DS . 'Exception.php');
}
exit;
}
/**
* Add an Exception callback
*
* @param \PPI\Exception\Interface
*/
public function addListener(\PPI\Exception\ExceptionInterface $listener) {
$this->_listeners[] = $listener;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment