1: <?php
 2: /**
 3:  * Picon Framework
 4:  * http://code.google.com/p/picon-framework/
 5:  *
 6:  * Copyright (C) 2011-2012 Martin Cassidy <martin.cassidy@webquub.com>
 7: 
 8:  * Picon Framework is free software: you can redistribute it and/or modify
 9:  * it under the terms of the GNU General Public License as published by
10:  * the Free Software Foundation, either version 3 of the License, or
11:  * (at your option) any later version.
12: 
13:  * Picon Framework is distributed in the hope that it will be useful,
14:  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16:  *  General Public License for more details.
17: 
18:  * You should have received a copy of the GNU General Public License
19:  * along with Picon Framework.  If not, see <http://www.gnu.org/licenses/>.
20:  * */
21: 
22: namespace picon;
23: 
24: /**
25:  * Handles all PHP errors and uncaught exceptions, registers handles
26:  * upon instantiation.
27:  * 
28:  * @author Martin Cassidy
29:  * @package core
30:  */
31: class PiconErrorHandler
32: {
33:     public function __construct()
34:     {
35:         set_error_handler(array($this, 'onError'));
36:         set_exception_handler(array($this, 'onException'));
37:     }
38:     
39:     /**
40:      * @todo the error level should be setable, warnings and notices are currently ignored
41:      * @param type $errno
42:      * @param type $errstr
43:      * @param type $errfile
44:      * @param type $errline 
45:      */
46:     public function onError($errno, $errstr, $errfile, $errline)
47:     {
48:         if($errno==E_USER_ERROR||$errno==E_ERROR)
49:         {
50:             throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
51:         }
52:     }
53:     
54:     public function onException(\Exception $exception)
55:     {
56:         print('<h1>Unhandled Exception</h1>');
57:         print('<h3>'.$exception->getMessage().' in '.$exception->getFile().' on line '.$exception->getLine().'</h3>');
58:         print('<h2>Trace</h2><ul>');
59:         foreach($exception->getTrace() as $trace)
60:         {
61:             print('<li>'.$trace['class'].'::'.$trace['function'].'() in '.$trace['file'].' on line '.$trace['line'].'</li>');
62:         }
63:         print('</ul>');
64: 
65:         die();
66:     }
67: }
68: 
69: ?>
70: