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 By default E_ALL | E_STRICT |
24
|
|
|
* |
25
|
|
|
* @return string|null |
26
|
|
|
*/ |
27
|
6 |
|
public function setErrorHandler(callable $handler, $types = null) |
28
|
|
|
{ |
29
|
6 |
|
return set_error_handler($handler, $types === null ? E_ALL | E_STRICT : $types); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param callable $handler |
34
|
|
|
* |
35
|
|
|
* @return string|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 |
|
return http_response_code($httpCode); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param int $exitStatus |
128
|
|
|
*/ |
129
|
|
|
public function stopExecution($exitStatus) |
130
|
|
|
{ |
131
|
|
|
exit($exitStatus); |
|
|
|
|
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
An exit expression should only be used in rare cases. For example, if you write a short command line script.
In most cases however, using an
exit
expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.