3
3
namespace Http \HttplugBundle \Collector ;
4
4
5
5
/**
6
- * An object to handle the collected data for a client.
6
+ * An object to handle the collected data for a client. This is used to display data.
7
7
*
8
8
* The Request object at $requests[0][2] is the state of the object between the third
9
9
* and the fourth plugin. The response after that plugin is found in $responses[0][2].
10
10
*
11
11
* @author Tobias Nyholm <[email protected] >
12
12
*/
13
- class ClientDataCollector
13
+ class ClientDataProvider
14
14
{
15
+ /**
16
+ * Array that tell if a request errored or not. true = success, false = failure.
17
+ * @var array
18
+ */
19
+ private $ failure ;
20
+
15
21
/**
16
22
* A multidimensional array with requests.
17
23
* $requests[0][0] is the first request before all plugins.
@@ -31,11 +37,13 @@ class ClientDataCollector
31
37
private $ responses ;
32
38
33
39
/**
40
+ * @param array $failure if the response was successful or not
34
41
* @param array $requests
35
42
* @param array $responses
36
43
*/
37
- public function __construct (array $ requests , array $ responses )
44
+ public function __construct (array $ failure , array $ requests , array $ responses )
38
45
{
46
+ $ this ->failure = $ failure ;
39
47
$ this ->requests = $ requests ;
40
48
$ this ->responses = $ responses ;
41
49
}
@@ -45,7 +53,7 @@ public function __construct(array $requests, array $responses)
45
53
*
46
54
* @param array $data
47
55
*
48
- * @return ClientDataCollector []
56
+ * @return ClientDataProvider []
49
57
*/
50
58
public static function createFromCollectedData (array $ data )
51
59
{
@@ -58,16 +66,23 @@ public static function createFromCollectedData(array $data)
58
66
}
59
67
60
68
/**
61
- * @param array $messages is an array with keys 'request' and 'response' which hold requests for each call to
69
+ * @param array $messages is an array with keys 'failure', ' request' and 'response' which hold requests for each call to
62
70
* sendRequest and for each depth.
63
71
*
64
- * @return ClientDataCollector
72
+ * @return ClientDataProvider
65
73
*/
66
74
private static function createOne ($ messages )
67
75
{
76
+ $ orderedFaulure = [];
68
77
$ orderedRequests = [];
69
78
$ orderedResponses = [];
70
79
80
+ foreach ($ messages ['failure ' ] as $ depth => $ failures ) {
81
+ foreach ($ failures as $ idx => $ failure ) {
82
+ $ orderedFaulure [$ idx ][$ depth ] = $ failure ;
83
+ }
84
+ }
85
+
71
86
foreach ($ messages ['request ' ] as $ depth => $ requests ) {
72
87
foreach ($ requests as $ idx => $ request ) {
73
88
$ orderedRequests [$ idx ][$ depth ] = $ request ;
@@ -80,7 +95,7 @@ private static function createOne($messages)
80
95
}
81
96
}
82
97
83
- return new self ($ orderedRequests , $ orderedResponses );
98
+ return new self ($ orderedFaulure , $ orderedRequests , $ orderedResponses );
84
99
}
85
100
86
101
/**
@@ -94,7 +109,7 @@ public function getRequests()
94
109
/**
95
110
* @param array $requests
96
111
*
97
- * @return ClientDataCollector
112
+ * @return ClientDataProvider
98
113
*/
99
114
public function setRequests ($ requests )
100
115
{
@@ -114,7 +129,7 @@ public function getResponses()
114
129
/**
115
130
* @param array $responses
116
131
*
117
- * @return ClientDataCollector
132
+ * @return ClientDataProvider
118
133
*/
119
134
public function setResponses ($ responses )
120
135
{
@@ -152,4 +167,14 @@ public function getResponseStack($idx)
152
167
{
153
168
return $ this ->responses [$ idx ];
154
169
}
170
+
171
+ /**
172
+ * @param int $idx
173
+ *
174
+ * @return array failures
175
+ */
176
+ public function getFailureStack ($ idx )
177
+ {
178
+ return $ this ->failure [$ idx ];
179
+ }
155
180
}
0 commit comments