|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author @fabfuel <[email protected]> |
|
4
|
|
|
* @created 16.11.14, 16:34 |
|
5
|
|
|
*/ |
|
6
|
|
|
namespace Fabfuel\Prophiler; |
|
7
|
|
|
|
|
8
|
|
|
use Fabfuel\Prophiler\Adapter\Psr\Log\Logger; |
|
9
|
|
|
use Fabfuel\Prophiler\Iterator\ComponentFilteredIterator; |
|
10
|
|
|
|
|
11
|
|
|
class Toolbar |
|
12
|
|
|
{ |
|
13
|
|
|
protected $alertSeverities = [ |
|
14
|
|
|
Logger::SEVERITY_ALERT, |
|
15
|
|
|
Logger::SEVERITY_ERROR, |
|
16
|
|
|
Logger::SEVERITY_EMERGENCY, |
|
17
|
|
|
Logger::SEVERITY_CRITICAL |
|
18
|
|
|
]; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var ProfilerInterface |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $profiler; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var DataCollectorInterface[] |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $dataCollectors = []; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param ProfilerInterface $profiler |
|
32
|
|
|
*/ |
|
33
|
2 |
|
public function __construct(ProfilerInterface $profiler) |
|
34
|
|
|
{ |
|
35
|
2 |
|
$this->setProfiler($profiler); |
|
36
|
2 |
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Render the toolbar |
|
40
|
|
|
*/ |
|
41
|
1 |
|
public function render() |
|
42
|
|
|
{ |
|
43
|
1 |
|
$alerts = new ComponentFilteredIterator( |
|
44
|
1 |
|
$this->profiler, |
|
45
|
1 |
|
'Logger', |
|
46
|
1 |
|
['severity' => $this->alertSeverities] |
|
47
|
1 |
|
); |
|
48
|
|
|
|
|
49
|
1 |
|
ob_start(); |
|
50
|
1 |
|
$this->partial('toolbar', [ |
|
51
|
1 |
|
'profiler' => $this->getProfiler(), |
|
52
|
1 |
|
'dataCollectors' => $this->getDataCollectors(), |
|
53
|
1 |
|
'aggregators' => $this->getProfiler()->getAggregators(), |
|
54
|
1 |
|
'alertCount' => count($alerts) |
|
55
|
1 |
|
]); |
|
56
|
1 |
|
return ob_get_clean(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param string $viewPath |
|
61
|
|
|
* @param array $params |
|
62
|
|
|
*/ |
|
63
|
2 |
|
public function partial($viewPath, array $params = []) |
|
64
|
|
|
{ |
|
65
|
2 |
|
extract($params, EXTR_OVERWRITE); |
|
66
|
2 |
|
$viewScriptPath = __DIR__ . '/View/' . $viewPath . '.phtml'; |
|
67
|
|
|
|
|
68
|
2 |
|
if (!file_exists($viewScriptPath)) { |
|
69
|
1 |
|
throw new \InvalidArgumentException(sprintf( |
|
70
|
1 |
|
'View not found: %s', |
|
71
|
|
|
$viewScriptPath |
|
72
|
1 |
|
)); |
|
73
|
|
|
} |
|
74
|
1 |
|
require $viewScriptPath; |
|
75
|
1 |
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @return ProfilerInterface |
|
79
|
|
|
*/ |
|
80
|
1 |
|
public function getProfiler() |
|
81
|
|
|
{ |
|
82
|
1 |
|
return $this->profiler; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param ProfilerInterface $profiler |
|
87
|
|
|
*/ |
|
88
|
1 |
|
public function setProfiler($profiler) |
|
89
|
|
|
{ |
|
90
|
1 |
|
$this->profiler = $profiler; |
|
91
|
1 |
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Add a data collector to the profiler |
|
95
|
|
|
* |
|
96
|
|
|
* @param DataCollectorInterface $dataCollector |
|
97
|
|
|
* @return $this |
|
98
|
|
|
*/ |
|
99
|
1 |
|
public function addDataCollector(DataCollectorInterface $dataCollector) |
|
100
|
|
|
{ |
|
101
|
1 |
|
$this->dataCollectors[] = $dataCollector; |
|
102
|
1 |
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @return DataCollectorInterface[] |
|
106
|
|
|
*/ |
|
107
|
1 |
|
public function getDataCollectors() |
|
108
|
|
|
{ |
|
109
|
1 |
|
return $this->dataCollectors; |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|