FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
phalcon-devtools/src/Error/ErrorHandler.php at master · marksda/phalcon-devtools · GitHub
marksda
/
phalcon-devtools
Public
forked from
phalcon/phalcon-devtools
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
phalcon-devtools
/
src
/
Error
/
ErrorHandler.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
206 lines (185 loc) · 5.5 KB
Breadcrumbs
phalcon-devtools
/
src
/
Error
/
ErrorHandler.php
Copy path
File metadata and controls
206 lines (185 loc) · 5.5 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php
declare
(strict_types=
1
);
/**
* This file is part of the Phalcon Developer Tools.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace
Phalcon
\
DevTools
\
Error
;
use
Phalcon
\
Di
\
Injectable
;
use
Phalcon
\
Logger
\
Logger
;
class
ErrorHandler
extends
Injectable
{
/**
* Registers itself as error and exception handler.
*/
public
function
register
()
{
switch
(
APPLICATION_ENV
) {
case
ENV_TESTING
:
case
ENV_DEVELOPMENT
:
ini_set
(
'
display_errors
'
,
'
1
'
);
ini_set
(
'
display_startup_errors
'
,
'
1
'
);
error_reporting
(-
1
);
break
;
default
:
ini_set
(
'
display_errors
'
,
'
0
'
);
ini_set
(
'
display_startup_errors
'
,
'
0
'
);
error_reporting
(
0
);
break
;
}
if
(
PHP_SAPI
==
'
cli
'
) {
ini_set
(
'
html_errors
'
,
'
0
'
);
}
else
{
ini_set
(
'
html_errors
'
,
'
1
'
);
}
set_error_handler
([
$
this
,
'
customErrorHandler
'
]);
$
that
=
$
this
;
set_exception_handler
(
/** @var \Exception\Error $e */
function
(
$
e
)
use
(
$
that
) {
$
options
= [
'
type
'
=>
$
e
->
getCode
(),
'
message
'
=>
$
e
->
getMessage
(),
'
file
'
=>
$
e
->
getFile
(),
'
line
'
=>
$
e
->
getLine
(),
'
isException
'
=>
true
,
'
exception
'
=>
$
e
,
];
$
that
->
handle
(
new
AppError
(
$
options
));
}
);
register_shutdown_function
(
function
()
use
(
$
that
) {
if
(!
is_null
(
$
options
=
error_get_last
())) {
$
that
->
handle
(
new
AppError
(
$
options
));
}
}
);
}
/**
* @param AppError $error
*/
public
function
handle
(
AppError
$
error
):
void
{
$
di
=
$
this
->
getDI
();
$
type
=
$
this
->
mapErrors
(
$
error
->
type
());
$
message
=
"
$
type
:
{
$
error
->
message
()}
in
{
$
error
->
file
()}
on line
{
$
error
->
line
()}"
;
if
(
$
di
->
has
(
'
logger
'
)) {
/** @var Logger $logger */
$
logger
=
$
this
->
getDI
()->
getShared
(
'
logger
'
);
$
logger
->
log
(
$
this
->
mapErrorsToLogType
(
$
error
->
type
()),
$
message
);
}
switch
(
$
error
->
type
()) {
case
E_WARNING
:
case
E_NOTICE
:
case
E_CORE_WARNING
:
case
E_COMPILE_WARNING
:
case
E_USER_WARNING
:
case
E_USER_NOTICE
:
case
E_STRICT
:
case
E_DEPRECATED
:
case
E_USER_DEPRECATED
:
case
E_ALL
:
break
;
default
:
if
(
$
di
->
has
(
'
view
'
)) {
// @todo
}
else
{
echo
$
message
;
}
}
}
/**
* Maps error code to a string.
*
* @param int $code
* @return mixed
*/
public
function
mapErrors
(
int
$
code
)
{
switch
(
$
code
) {
case
0
:
return
'
Uncaught exception
'
;
case
E_ERROR
:
return
'
E_ERROR
'
;
case
E_WARNING
:
return
'
E_WARNING
'
;
case
E_PARSE
:
return
'
E_PARSE
'
;
case
E_NOTICE
:
return
'
E_NOTICE
'
;
case
E_CORE_ERROR
:
return
'
E_CORE_ERROR
'
;
case
E_CORE_WARNING
:
return
'
E_CORE_WARNING
'
;
case
E_COMPILE_ERROR
:
return
'
E_COMPILE_ERROR
'
;
case
E_COMPILE_WARNING
:
return
'
E_COMPILE_WARNING
'
;
case
E_USER_ERROR
:
return
'
E_USER_ERROR
'
;
case
E_USER_WARNING
:
return
'
E_USER_WARNING
'
;
case
E_USER_NOTICE
:
return
'
E_USER_NOTICE
'
;
case
E_STRICT
:
return
'
E_STRICT
'
;
case
E_RECOVERABLE_ERROR
:
return
'
E_RECOVERABLE_ERROR
'
;
case
E_DEPRECATED
:
return
'
E_DEPRECATED
'
;
case
E_USER_DEPRECATED
:
return
'
E_USER_DEPRECATED
'
;
}
return
$
code
;
}
/**
* Maps error code to a log type.
*
* @param int $code
* @return int
*/
public
function
mapErrorsToLogType
(
int
$
code
):
int
{
switch
(
$
code
) {
case
E_ERROR
:
case
E_RECOVERABLE_ERROR
:
case
E_CORE_ERROR
:
case
E_COMPILE_ERROR
:
case
E_USER_ERROR
:
case
E_PARSE
:
return
Logger::
ERROR
;
case
E_WARNING
:
case
E_USER_WARNING
:
case
E_CORE_WARNING
:
case
E_COMPILE_WARNING
:
return
Logger::
WARNING
;
case
E_NOTICE
:
case
E_USER_NOTICE
:
return
Logger::
NOTICE
;
case
E_STRICT
:
case
E_DEPRECATED
:
case
E_USER_DEPRECATED
:
return
Logger::
INFO
;
}
return
Logger::
ERROR
;
}
public
function
customErrorHandler
(
$
errno
,
$
errstr
,
$
errfile
,
$
errline
)
{
if
(!(
$
errno
&
error_reporting
())) {
return
;
}
$
options
= [
'
type
'
=>
$
errno
,
'
message
'
=>
$
errstr
,
'
file
'
=>
$
errfile
,
'
line
'
=>
$
errline
,
'
isError
'
=>
true
,
];
$
this
->
handle
(
new
AppError
(
$
options
));
}
}
Back
|
FazBrowse Home
|
New Git URL