1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SkautisBundle\Profiler; |
4
|
|
|
|
5
|
|
|
use Skautis\Skautis; |
6
|
|
|
use Skautis\SkautisQuery; |
7
|
|
|
use Symfony\Component\HttpKernel\DataCollector\DataCollector; |
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Sbira data o skautisu pro zobrazeni v profileru |
13
|
|
|
*/ |
14
|
|
|
class SkautisDataCollector extends DataCollector |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var Skautis |
19
|
|
|
* |
20
|
|
|
* @method string app_id() |
21
|
|
|
* @method bool test_mode() |
22
|
|
|
* @method bool cache() |
23
|
|
|
* @method bool compression() |
24
|
|
|
* @method string role_id() |
25
|
|
|
* @method string unit_id() |
26
|
|
|
* @method string token() |
27
|
|
|
* @method bool is_logged_in() |
28
|
|
|
* @method \DateTime logout_date() |
29
|
|
|
* @method bool maintenance() |
30
|
|
|
*/ |
31
|
|
|
protected $skautis; |
32
|
|
|
|
33
|
2 |
|
public function __construct(Skautis $skautis) |
34
|
|
|
{ |
35
|
2 |
|
$this->skautis = $skautis; |
36
|
2 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @inheritdoc |
40
|
|
|
*/ |
41
|
2 |
|
public function collect(Request $request, Response $response, \Exception $exception = null) |
42
|
|
|
{ |
43
|
2 |
|
$config = $this->skautis->getConfig(); |
44
|
2 |
|
$this->data = [ |
45
|
2 |
|
'queries' => $this->skautis->getDebugLog(), |
46
|
2 |
|
'app_id' => $config->getAppId(), |
47
|
2 |
|
'test_mode' => $config->isTestMode(), |
48
|
2 |
|
'cache' => $config->getCache(), |
49
|
2 |
|
'compression' => $config->getCompression(), |
50
|
2 |
|
'role_id' => $this->skautis->getUser()->getRoleId(), |
51
|
2 |
|
'unit_id' => $this->skautis->getUser()->getUnitId(), |
52
|
2 |
|
'token' => $this->skautis->getUser()->getLoginId(), |
53
|
2 |
|
'is_logged_in' => $this->skautis->getUser()->isLoggedIn(), |
54
|
2 |
|
'logout_date' => $this->skautis->getUser()->getLogoutDate(), |
55
|
2 |
|
'maintenance' => $this->skautis->isMaintenance(), |
56
|
|
|
]; |
57
|
2 |
|
} |
58
|
|
|
|
59
|
2 |
|
public function __call($method, $args) |
60
|
|
|
{ |
61
|
2 |
|
return $this->data["$method"]; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Ziska vsechny SkautisQuery |
66
|
|
|
* @return SkautisQuery[] |
67
|
|
|
*/ |
68
|
|
|
public function getRequests() |
69
|
|
|
{ |
70
|
|
|
return $this->data['queries']; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Pocet requestu |
75
|
|
|
* @return int |
76
|
|
|
*/ |
77
|
|
|
public function getRequestCount() |
78
|
|
|
{ |
79
|
|
|
return count($this->data['queries']); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return int Miliseconds |
84
|
|
|
*/ |
85
|
|
|
public function getTotalTime() |
86
|
|
|
{ |
87
|
|
|
$totalTime = 0; |
88
|
|
|
foreach ($this->data['queries'] as $query) { |
89
|
|
|
$totalTime += $query->time; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return $totalTime * 1000; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @inheritdoc |
97
|
|
|
*/ |
98
|
|
|
public function getName() |
99
|
|
|
{ |
100
|
|
|
return 'skautis_collector'; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|