FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
debugbar/src/DebugBar/DebugBar.php at master · phalcon/debugbar · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
phalcon
/
debugbar
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
2
Star
5
Code
Issues
6
Pull requests
0
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
debugbar
/
src
/
DebugBar
/
DebugBar.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
291 lines (252 loc) · 6.27 KB
Breadcrumbs
debugbar
/
src
/
DebugBar
/
DebugBar.php
Copy path
File metadata and controls
291 lines (252 loc) · 6.27 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<?php
/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/
declare
(strict_types=
1
);
namespace
Phalcon
\
DebugBar
;
use
Phalcon
\
DebugBar
\
Contracts
\
Collector
;
use
Phalcon
\
DebugBar
\
Contracts
\
ExceptionAware
;
use
Phalcon
\
DebugBar
\
Contracts
\
LoggerAware
;
use
Phalcon
\
DebugBar
\
Contracts
\
MessageAware
;
use
Phalcon
\
DebugBar
\
Contracts
\
TimeAware
;
use
Phalcon
\
DebugBar
\
Exceptions
\
Exception
;
use
Throwable
;
use
function
count
;
/**
* Aggregates registered collectors into a single per-request payload. The
* registry is keyed by each collector's name, so registering a collector whose
* name already exists replaces the previous one (last-write-wins).
*
* The convenience methods (`message()`, `startMeasure()`, `addException()`, …)
* delegate to the `messages`/`time`/`exceptions` collectors when present and
* no-op otherwise, so disabling a collector can never break calling code.
*
* @phpstan-import-type payload from DebugBarTypes
*/
class
DebugBar
{
/**
* @var array<string, Collector>
*/
protected
array
$
collectors
= [];
/**
* @var payload
*/
protected
array
$
data
= [
'
data
'
=> [],
'
meta
'
=> [],
];
/**
* Registers (or replaces) a collector under its name.
*
* @param Collector $collector
*
* @return static
*/
public
function
addCollector
(
Collector
$
collector
):
static
{
$
this
->
collectors
[
$
collector
->
getName
()] =
$
collector
;
return
$
this
;
}
/**
* @param Throwable $throwable
*
* @return static
*/
public
function
addException
(
Throwable
$
throwable
):
static
{
$
collector
=
$
this
->
collectors
[
'
exceptions
'
] ??
null
;
if
(
$
collector
instanceof
ExceptionAware) {
$
collector
->
addThrowable
(
$
throwable
);
}
return
$
this
;
}
/**
* @param string $message
* @param string $level
* @param array<array-key, mixed> $context
*
* @return static
*/
public
function
addLog
(
string
$
message
,
string
$
level
,
array
$
context
= []):
static
{
$
collector
=
$
this
->
collectors
[
'
logger
'
] ??
null
;
if
(
$
collector
instanceof
LoggerAware) {
$
collector
->
addLog
(
$
message
,
$
level
,
$
context
);
}
return
$
this
;
}
/**
* Runs every collector and caches the aggregated payload.
*
* @return payload
*/
public
function
collect
():
array
{
$
data
= [];
foreach
(
$
this
->
collectors
as
$
name
=>
$
collector
) {
$
data
[
$
name
] =
$
collector
->
collect
();
}
$
this
->
data
= [
'
data
'
=>
$
data
,
'
meta
'
=> [
'
collectors
'
=>
count
(
$
data
),
],
];
return
$
this
->
data
;
}
/**
* @param mixed ...$args
*
* @return static
*/
public
function
debug
(
mixed
...
$
args
):
static
{
foreach
(
$
args
as
$
arg
) {
$
this
->
message
(
$
arg
,
'
debug
'
);
}
return
$
this
;
}
/**
* @param mixed ...$args
*
* @return static
*/
public
function
error
(
mixed
...
$
args
):
static
{
foreach
(
$
args
as
$
arg
) {
$
this
->
message
(
$
arg
,
'
error
'
);
}
return
$
this
;
}
/**
* @param string $name
*
* @return Collector
* @throws Exception when no collector is registered under $name
*/
public
function
getCollector
(
string
$
name
):
Collector
{
if
(!
isset
(
$
this
->
collectors
[
$
name
])) {
throw
new
Exception
(
'
Unknown collector:
'
.
$
name
);
}
return
$
this
->
collectors
[
$
name
];
}
/**
* @return array<string, Collector>
*/
public
function
getCollectors
():
array
{
return
$
this
->
collectors
;
}
/**
* Returns the last aggregated payload (empty until collect() has run).
*
* @return payload
*/
public
function
getData
():
array
{
return
$
this
->
data
;
}
/**
* @param string $name
*
* @return bool
*/
public
function
hasCollector
(
string
$
name
):
bool
{
return
isset
(
$
this
->
collectors
[
$
name
]);
}
/**
* @param mixed ...$args
*
* @return static
*/
public
function
info
(
mixed
...
$
args
):
static
{
foreach
(
$
args
as
$
arg
) {
$
this
->
message
(
$
arg
,
'
info
'
);
}
return
$
this
;
}
/**
* @param mixed $message
* @param string $label
*
* @return static
*/
public
function
message
(
mixed
$
message
,
string
$
label
=
'
info
'
):
static
{
$
collector
=
$
this
->
collectors
[
'
messages
'
] ??
null
;
if
(
$
collector
instanceof
MessageAware) {
$
collector
->
addMessage
(
$
message
,
$
label
);
}
return
$
this
;
}
/**
* @param mixed ...$args
*
* @return static
*/
public
function
notice
(
mixed
...
$
args
):
static
{
foreach
(
$
args
as
$
arg
) {
$
this
->
message
(
$
arg
,
'
notice
'
);
}
return
$
this
;
}
/**
* @param string $name
*
* @return static
*/
public
function
removeCollector
(
string
$
name
):
static
{
unset(
$
this
->
collectors
[
$
name
]);
return
$
this
;
}
/**
* @param string $name
* @param string|null $label
*
* @return static
*/
public
function
startMeasure
(
string
$
name
, ?
string
$
label
=
null
):
static
{
$
collector
=
$
this
->
collectors
[
'
time
'
] ??
null
;
if
(
$
collector
instanceof
TimeAware) {
$
collector
->
startMeasure
(
$
name
,
$
label
);
}
return
$
this
;
}
/**
* @param string $name
*
* @return static
*/
public
function
stopMeasure
(
string
$
name
):
static
{
$
collector
=
$
this
->
collectors
[
'
time
'
] ??
null
;
if
(
$
collector
instanceof
TimeAware) {
$
collector
->
stopMeasure
(
$
name
);
}
return
$
this
;
}
/**
* @param mixed ...$args
*
* @return static
*/
public
function
warning
(
mixed
...
$
args
):
static
{
foreach
(
$
args
as
$
arg
) {
$
this
->
message
(
$
arg
,
'
warning
'
);
}
return
$
this
;
}
}
Back
|
FazBrowse Home
|
New Git URL