1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Whoops - php errors for cool kids |
4
|
|
|
* @author Filipe Dobreira <http://github.com/filp> |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Whoops\Util; |
8
|
|
|
|
9
|
|
|
class SystemFacade |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Turns on output buffering. |
13
|
|
|
* |
14
|
|
|
* @return bool |
15
|
|
|
*/ |
16
|
4 |
|
public function startOutputBuffering() |
17
|
|
|
{ |
18
|
4 |
|
return ob_start(); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param callable $handler |
23
|
|
|
* @param int $types |
24
|
|
|
* |
25
|
|
|
* @return callable|null |
26
|
|
|
*/ |
27
|
8 |
|
public function setErrorHandler(callable $handler, $types = 'use-php-defaults') |
28
|
|
|
{ |
29
|
|
|
// Since PHP 5.4 the constant E_ALL contains all errors (even E_STRICT) |
30
|
8 |
|
if ($types === 'use-php-defaults') { |
31
|
7 |
|
$types = E_ALL; |
32
|
7 |
|
} |
33
|
8 |
|
return set_error_handler($handler, $types); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param callable $handler |
38
|
|
|
* |
39
|
|
|
* @return callable|null |
40
|
|
|
*/ |
41
|
7 |
|
public function setExceptionHandler(callable $handler) |
42
|
|
|
{ |
43
|
7 |
|
return set_exception_handler($handler); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
1 |
|
public function restoreExceptionHandler() |
50
|
|
|
{ |
51
|
1 |
|
restore_exception_handler(); |
52
|
1 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return void |
56
|
|
|
*/ |
57
|
1 |
|
public function restoreErrorHandler() |
58
|
|
|
{ |
59
|
1 |
|
restore_error_handler(); |
60
|
1 |
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param callable $function |
64
|
|
|
* |
65
|
|
|
* @return void |
66
|
|
|
*/ |
67
|
7 |
|
public function registerShutdownFunction(callable $function) |
68
|
|
|
{ |
69
|
7 |
|
register_shutdown_function($function); |
70
|
7 |
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return string|false |
74
|
|
|
*/ |
75
|
4 |
|
public function cleanOutputBuffer() |
76
|
|
|
{ |
77
|
4 |
|
return ob_get_clean(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return int |
82
|
|
|
*/ |
83
|
1 |
|
public function getOutputBufferLevel() |
84
|
|
|
{ |
85
|
1 |
|
return ob_get_level(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return bool |
90
|
|
|
*/ |
91
|
1 |
|
public function endOutputBuffering() |
92
|
|
|
{ |
93
|
1 |
|
return ob_end_clean(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return void |
98
|
|
|
*/ |
99
|
1 |
|
public function flushOutputBuffer() |
100
|
|
|
{ |
101
|
1 |
|
flush(); |
102
|
1 |
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return int |
106
|
|
|
*/ |
107
|
4 |
|
public function getErrorReportingLevel() |
108
|
|
|
{ |
109
|
4 |
|
return error_reporting(); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return array|null |
114
|
|
|
*/ |
115
|
1 |
|
public function getLastError() |
116
|
|
|
{ |
117
|
1 |
|
return error_get_last(); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @param int $httpCode |
122
|
|
|
* |
123
|
|
|
* @return int |
124
|
|
|
*/ |
125
|
1 |
|
public function setHttpResponseCode($httpCode) |
126
|
|
|
{ |
127
|
1 |
|
if (!headers_sent()) { |
128
|
|
|
// Ensure that no 'location' header is present as otherwise this |
129
|
|
|
// will override the HTTP code being set here, and mask the |
130
|
|
|
// expected error page. |
131
|
1 |
|
header_remove('location'); |
132
|
1 |
|
} |
133
|
|
|
|
134
|
1 |
|
return http_response_code($httpCode); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param int $exitStatus |
139
|
|
|
*/ |
140
|
|
|
public function stopExecution($exitStatus) |
141
|
|
|
{ |
142
|
|
|
exit($exitStatus); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|