1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Http\HttplugBundle\Collector; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Symfony\Component\HttpFoundation\Request; |
7
|
|
|
use Symfony\Component\HttpFoundation\Response; |
8
|
|
|
use Symfony\Component\HttpKernel\DataCollector\DataCollector; |
9
|
|
|
|
10
|
|
|
class Collector extends DataCollector |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var ProfileStack[] |
14
|
|
|
*/ |
15
|
|
|
private $stacks; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var array |
19
|
|
|
*/ |
20
|
|
|
private $clients; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param array $clients |
24
|
|
|
*/ |
25
|
|
|
public function __construct(array $clients) |
26
|
|
|
{ |
27
|
|
|
$this->stacks = []; |
28
|
|
|
$this->clients = $clients; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
public function collect(Request $request, Response $response, Exception $exception = null) |
35
|
|
|
{ |
36
|
|
|
// We do not need to collect any data from the Symfony Request and Response |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
|
|
public function getName() |
43
|
|
|
{ |
44
|
|
|
return 'httplug'; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param ProfileStack $stack |
49
|
|
|
*/ |
50
|
|
|
public function addStack(ProfileStack $stack) |
51
|
|
|
{ |
52
|
|
|
$this->stacks[] = $stack; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return ProfileStack[] |
57
|
|
|
*/ |
58
|
|
|
public function getStacks() |
59
|
|
|
{ |
60
|
|
|
return $this->stacks; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return ProfileStack |
65
|
|
|
*/ |
66
|
|
|
public function getCurrentStack() |
67
|
|
|
{ |
68
|
|
|
return end($this->stacks); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return ProfileStack[] |
73
|
|
|
*/ |
74
|
|
|
public function getSuccessfulStacks() |
75
|
|
|
{ |
76
|
|
|
return array_filter($this->stacks, function (ProfileStack $stack) { |
77
|
|
|
return $stack->isSuccessful(); |
|
|
|
|
78
|
|
|
}); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return ProfileStack[] |
83
|
|
|
*/ |
84
|
|
|
public function getFailedStacks() |
85
|
|
|
{ |
86
|
|
|
return array_filter($this->stacks, function (ProfileStack $stack) { |
87
|
|
|
return !$stack->isSuccessful(); |
|
|
|
|
88
|
|
|
}); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return array |
93
|
|
|
*/ |
94
|
|
|
public function getClients() |
95
|
|
|
{ |
96
|
|
|
return $this->clients; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param $client |
101
|
|
|
* |
102
|
|
|
* @return ProfileStack[] |
103
|
|
|
*/ |
104
|
|
|
public function getClientStacks($client) |
105
|
|
|
{ |
106
|
|
|
return array_filter($this->stacks, function (ProfileStack $stack) use ($client) { |
107
|
|
|
return $stack->getClient() == $client; |
108
|
|
|
}); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|