|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Recca0120\LaravelTracy\Panels; |
|
4
|
|
|
|
|
5
|
|
|
use Recca0120\LaravelTracy\Contracts\IAjaxPanel; |
|
6
|
|
|
use Tracy\Debugger; |
|
7
|
|
|
|
|
8
|
|
|
class EventPanel extends AbstractSubscriablePanel implements IAjaxPanel |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* $counter. |
|
12
|
|
|
* |
|
13
|
|
|
* @var int |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $counter = 0; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* $totalTime. |
|
19
|
|
|
* |
|
20
|
|
|
* @var float |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $totalTime = 0.0; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* $events. |
|
26
|
|
|
* |
|
27
|
|
|
* @var array |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $events = []; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* getAttributes. |
|
33
|
|
|
* |
|
34
|
|
|
* @return array |
|
35
|
|
|
*/ |
|
36
|
2 |
|
public function getAttributes() |
|
37
|
|
|
{ |
|
38
|
|
|
return [ |
|
39
|
2 |
|
'counter' => $this->counter, |
|
40
|
2 |
|
'totalTime' => $this->totalTime, |
|
41
|
2 |
|
'events' => $this->events, |
|
42
|
|
|
]; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* subscribe. |
|
47
|
|
|
*/ |
|
48
|
2 |
|
protected function subscribe() |
|
49
|
|
|
{ |
|
50
|
2 |
|
$id = get_class($this); |
|
51
|
2 |
|
Debugger::timer($id); |
|
52
|
2 |
|
$events = $this->laravel['events']; |
|
53
|
|
|
|
|
54
|
2 |
|
if (version_compare($this->laravel->version(), 5.4, '>=') === true) { |
|
55
|
1 |
View Code Duplication |
$events->listen('*', function ($key, $payload) use ($id) { |
|
56
|
1 |
|
$execTime = Debugger::timer($id); |
|
57
|
1 |
|
$editorLink = static::editorLink(static::findSource()); |
|
58
|
1 |
|
$this->totalTime += $execTime; |
|
59
|
1 |
|
$this->events[] = compact('execTime', 'key', 'payload', 'editorLink'); |
|
60
|
1 |
|
}); |
|
61
|
|
|
} else { |
|
62
|
1 |
View Code Duplication |
$events->listen('*', function ($payload) use ($id, $events) { |
|
63
|
1 |
|
$execTime = Debugger::timer($id); |
|
64
|
1 |
|
$key = $events->firing(); |
|
65
|
1 |
|
$editorLink = static::editorLink(static::findSource()); |
|
66
|
1 |
|
$this->totalTime += $execTime; |
|
67
|
1 |
|
$this->events[] = compact('execTime', 'key', 'payload', 'editorLink'); |
|
68
|
1 |
|
}); |
|
69
|
|
|
} |
|
70
|
2 |
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|