33namespace Http \HttplugBundle \Collector ;
44
55/**
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.
77 *
88 * The Request object at $requests[0][2] is the state of the object between the third
99 * and the fourth plugin. The response after that plugin is found in $responses[0][2].
1010 *
1111 * @author Tobias Nyholm <[email protected] > 1212 */
13- class ClientDataCollector
13+ class ClientDataProvider
1414{
15+ /**
16+ * Array that tell if a request errored or not. true = success, false = failure.
17+ * @var array
18+ */
19+ private $ failure ;
20+
1521 /**
1622 * A multidimensional array with requests.
1723 * $requests[0][0] is the first request before all plugins.
@@ -31,11 +37,13 @@ class ClientDataCollector
3137 private $ responses ;
3238
3339 /**
40+ * @param array $failure if the response was successful or not
3441 * @param array $requests
3542 * @param array $responses
3643 */
37- public function __construct (array $ requests , array $ responses )
44+ public function __construct (array $ failure , array $ requests , array $ responses )
3845 {
46+ $ this ->failure = $ failure ;
3947 $ this ->requests = $ requests ;
4048 $ this ->responses = $ responses ;
4149 }
@@ -45,7 +53,7 @@ public function __construct(array $requests, array $responses)
4553 *
4654 * @param array $data
4755 *
48- * @return ClientDataCollector []
56+ * @return ClientDataProvider []
4957 */
5058 public static function createFromCollectedData (array $ data )
5159 {
@@ -58,16 +66,23 @@ public static function createFromCollectedData(array $data)
5866 }
5967
6068 /**
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
6270 * sendRequest and for each depth.
6371 *
64- * @return ClientDataCollector
72+ * @return ClientDataProvider
6573 */
6674 private static function createOne ($ messages )
6775 {
76+ $ orderedFaulure = [];
6877 $ orderedRequests = [];
6978 $ orderedResponses = [];
7079
80+ foreach ($ messages ['failure ' ] as $ depth => $ failures ) {
81+ foreach ($ failures as $ idx => $ failure ) {
82+ $ orderedFaulure [$ idx ][$ depth ] = $ failure ;
83+ }
84+ }
85+
7186 foreach ($ messages ['request ' ] as $ depth => $ requests ) {
7287 foreach ($ requests as $ idx => $ request ) {
7388 $ orderedRequests [$ idx ][$ depth ] = $ request ;
@@ -80,7 +95,7 @@ private static function createOne($messages)
8095 }
8196 }
8297
83- return new self ($ orderedRequests , $ orderedResponses );
98+ return new self ($ orderedFaulure , $ orderedRequests , $ orderedResponses );
8499 }
85100
86101 /**
@@ -94,7 +109,7 @@ public function getRequests()
94109 /**
95110 * @param array $requests
96111 *
97- * @return ClientDataCollector
112+ * @return ClientDataProvider
98113 */
99114 public function setRequests ($ requests )
100115 {
@@ -114,7 +129,7 @@ public function getResponses()
114129 /**
115130 * @param array $responses
116131 *
117- * @return ClientDataCollector
132+ * @return ClientDataProvider
118133 */
119134 public function setResponses ($ responses )
120135 {
@@ -152,4 +167,14 @@ public function getResponseStack($idx)
152167 {
153168 return $ this ->responses [$ idx ];
154169 }
170+
171+ /**
172+ * @param int $idx
173+ *
174+ * @return array failures
175+ */
176+ public function getFailureStack ($ idx )
177+ {
178+ return $ this ->failure [$ idx ];
179+ }
155180}
0 commit comments