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
|
2 |
|
public function startOutputBuffering() |
17
|
|
|
{ |
18
|
2 |
|
return ob_start(); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param callable $handler |
23
|
|
|
* @param int $types |
24
|
|
|
* |
25
|
|
|
* @return callable|null |
26
|
|
|
*/ |
27
|
6 |
|
public function setErrorHandler(callable $handler, $types = E_ALL | E_STRICT) |
28
|
|
|
{ |
29
|
6 |
|
return set_error_handler($handler, $types); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param callable $handler |
34
|
|
|
* |
35
|
|
|
* @return callable|null |
36
|
|
|
*/ |
37
|
5 |
|
public function setExceptionHandler(callable $handler) |
38
|
|
|
{ |
39
|
5 |
|
return set_exception_handler($handler); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
1 |
|
public function restoreExceptionHandler() |
46
|
|
|
{ |
47
|
1 |
|
restore_exception_handler(); |
48
|
1 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return void |
52
|
|
|
*/ |
53
|
1 |
|
public function restoreErrorHandler() |
54
|
|
|
{ |
55
|
1 |
|
restore_error_handler(); |
56
|
1 |
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param callable $function |
60
|
|
|
* |
61
|
|
|
* @return void |
62
|
|
|
*/ |
63
|
5 |
|
public function registerShutdownFunction(callable $function) |
64
|
|
|
{ |
65
|
5 |
|
register_shutdown_function($function); |
66
|
5 |
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return string|false |
70
|
|
|
*/ |
71
|
2 |
|
public function cleanOutputBuffer() |
72
|
|
|
{ |
73
|
2 |
|
return ob_get_clean(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return int |
78
|
|
|
*/ |
79
|
1 |
|
public function getOutputBufferLevel() |
80
|
|
|
{ |
81
|
1 |
|
return ob_get_level(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return bool |
86
|
|
|
*/ |
87
|
1 |
|
public function endOutputBuffering() |
88
|
|
|
{ |
89
|
1 |
|
return ob_end_clean(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return void |
94
|
|
|
*/ |
95
|
1 |
|
public function flushOutputBuffer() |
96
|
|
|
{ |
97
|
1 |
|
flush(); |
98
|
1 |
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return int |
102
|
|
|
*/ |
103
|
4 |
|
public function getErrorReportingLevel() |
104
|
|
|
{ |
105
|
4 |
|
return error_reporting(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return array|null |
110
|
|
|
*/ |
111
|
1 |
|
public function getLastError() |
112
|
|
|
{ |
113
|
1 |
|
return error_get_last(); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param int $httpCode |
118
|
|
|
* |
119
|
|
|
* @return int |
120
|
|
|
*/ |
121
|
1 |
|
public function setHttpResponseCode($httpCode) |
122
|
|
|
{ |
123
|
1 |
|
if (function_exists('http_response_code')) { |
124
|
1 |
|
return http_response_code($httpCode); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
// http_response_code is added in 5.4. |
128
|
|
|
// For compatibility with 5.3 we use the third argument in header call |
129
|
|
|
// First argument must be a real header. |
130
|
|
|
// If it is empty, PHP will ignore the third argument. |
131
|
|
|
// If it is invalid, such as a single space, Apache will handle it well, |
132
|
|
|
// but the PHP development server will hang. |
133
|
|
|
// Setting a full status line would require us to hardcode |
134
|
|
|
// string values for all different status code, and detect the protocol. |
135
|
|
|
// which is an extra error-prone complexity. |
136
|
|
|
header('X-Ignore-This: 1', true, $httpCode); |
137
|
|
|
|
138
|
|
|
return $httpCode; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @param int $exitStatus |
143
|
|
|
*/ |
144
|
|
|
public function stopExecution($exitStatus) |
145
|
|
|
{ |
146
|
|
|
exit($exitStatus); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|