Created
November 14, 2011 00:12
-
-
Save BenExile/1362952 to your computer and use it in GitHub Desktop.
Listener status concept
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @author Paul Dragoonis ([email protected]) | |
* @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