summaryrefslogtreecommitdiffstats
path: root/system/classes/error.php
blob: 6f5478424eb8299a6a98eebf1502c645d8558a3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php

/**
 * Short description for class
 */
class Error {

    /**
     * Description for public
     * @var unknown 
     * @access public  
     */
	public $exception;

    /**
     * Short description for function
     * 
     * @return void   
     * @access public 
     */
	public function render() {
		ob_end_clean();
		$view = View::get('error');
		$view->exception = $this->exception;
		echo $view->render();
	}

    /**
     * Short description for function
     * 
     * @param unknown $exception Parameter description (if any) ...
     * @return void    
     * @access public  
     * @static 
     */
	public static function onError($exception) {
		set_exception_handler(array('Error', 'internalException'));
		set_error_handler ( array('Error', 'internalError'), E_ALL);
		$error = new Error();
		$error->exception = $exception;
		$error->render();
	}

    /**
     * Short description for function
     * 
     * @param unknown        $errno   Parameter description (if any) ...
     * @param unknown        $errstr  Parameter description (if any) ...
     * @param unknown        $errfile Parameter description (if any) ...
     * @param unknown        $errline Parameter description (if any) ...
     * @return void           
     * @access public         
     * @throws ErrorException Exception description (if any) ...
     * @static 
     */
	public static function errorHandler($errno, $errstr, $errfile, $errline) {
		throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
	}

    /**
     * Short description for function
     * 
     * @param mixed  $exception Parameter description (if any) ...
     * @return void   
     * @access public 
     * @static 
     */
	public static function internalException($exception) {
		echo $exception->getMessage().' in '.$exception->getFile().' on line '.$exception->getLine();
	}

    /**
     * Short description for function
     * 
     * @param unknown $errno   Parameter description (if any) ...
     * @param string  $errstr  Parameter description (if any) ...
     * @param string  $errfile Parameter description (if any) ...
     * @param string  $errline Parameter description (if any) ...
     * @return void    
     * @access public  
     * @static 
     */
	public static function internalError($errno, $errstr, $errfile, $errline) {
		echo $errstr.' in '.$errfile.' on line '.$errline;
	}

    /**
     * Short description for function
     * 
     * @return void   
     * @access public 
     * @static 
     */
	public static function init(){
		set_exception_handler(array('Error', 'onError'));
		set_error_handler ( array('Error', 'errorHandler'), E_ALL);
	}

}