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
|
|
|
protected $skautis; |
21
|
|
|
|
22
|
2 |
|
public function __construct(Skautis $skautis) |
23
|
|
|
{ |
24
|
2 |
|
$this->skautis = $skautis; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @inheritdoc |
29
|
|
|
*/ |
30
|
2 |
|
public function collect(Request $request, Response $response, \Exception $exception = null) |
31
|
|
|
{ |
32
|
|
|
$config = $this->skautis->getConfig(); |
33
|
2 |
|
$this->data = [ |
34
|
2 |
|
'queries' => $this->skautis->getDebugLog(), |
35
|
2 |
|
'app_id' => $config->getAppId(), |
36
|
2 |
|
'test_mode' => $config->isTestMode(), |
37
|
2 |
|
'cache' => $config->getCache(), |
38
|
2 |
|
'compression' => $config->getCompression(), |
39
|
|
|
'role_id' => $this->skautis->getUser()->getRoleId(), |
40
|
|
|
'unit_id' => $this->skautis->getUser()->getUnitId(), |
41
|
|
|
'token' => $this->skautis->getUser()->getLoginId(), |
42
|
|
|
'is_logged_in' => $this->skautis->getUser()->isLoggedIn(), |
43
|
|
|
'logout_date' => $this->skautis->getUser()->getLogoutDate(), |
44
|
2 |
|
'maintenance' => $this->skautis->isMaintenance(), |
45
|
|
|
]; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function __call($method, $args) |
49
|
|
|
{ |
50
|
|
|
return $this->data["$method"]; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Ziska vsechny SkautisQuery |
55
|
|
|
* @return SkautisQuery[] |
56
|
|
|
*/ |
57
|
|
|
public function getRequests() |
58
|
|
|
{ |
59
|
|
|
return $this->data['queries']; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Pocet requestu |
64
|
|
|
* @return int |
65
|
|
|
*/ |
66
|
|
|
public function getRequestCount() |
67
|
|
|
{ |
68
|
|
|
return count($this->data['queries']); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return int Miliseconds |
73
|
|
|
*/ |
74
|
|
|
public function getTotalTime() |
75
|
|
|
{ |
76
|
|
|
$totalTime = 0; |
77
|
|
|
foreach ($this->data['queries'] as $query) { |
78
|
|
|
$totalTime += $query->time; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return $totalTime * 1000; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @inheritdoc |
86
|
|
|
*/ |
87
|
|
|
public function getName() |
88
|
|
|
{ |
89
|
|
|
return 'skautis_collector'; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|