1 | <?php |
||
13 | class ClientDataCollector |
||
14 | { |
||
15 | /** |
||
16 | * A multidimensional array with requests. |
||
17 | * $requests[0][0] is the first request before all plugins. |
||
18 | * $requests[0][1] is the first request after the first plugin. |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | private $requests; |
||
23 | |||
24 | /** |
||
25 | * A multidimensional array with responses. |
||
26 | * $responses[0][0] is the first responses before all plugins. |
||
27 | * $responses[0][1] is the first responses after the first plugin. |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | private $responses; |
||
32 | |||
33 | /** |
||
34 | * @param array $requests |
||
35 | * @param array $responses |
||
36 | */ |
||
37 | public function __construct(array $requests, array $responses) |
||
38 | { |
||
39 | $this->requests = $requests; |
||
40 | $this->responses = $responses; |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Create an array of ClientDataCollector from collected data. |
||
45 | * |
||
46 | * @param array $data |
||
47 | * |
||
48 | * @return ClientDataCollector[] |
||
49 | */ |
||
50 | public static function createFromCollectedData(array $data) |
||
51 | { |
||
52 | $clientData = []; |
||
53 | foreach ($data as $clientName => $messages) { |
||
54 | $clientData[$clientName] = static::createOne($messages); |
||
|
|||
55 | } |
||
56 | |||
57 | return $clientData; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * @param array $messages is an array with keys 'request' and 'response' which hold requests for each call to |
||
62 | * sendRequest and for each depth. |
||
63 | * |
||
64 | * @return ClientDataCollector |
||
65 | */ |
||
66 | private static function createOne($messages) |
||
67 | { |
||
68 | $orderedRequests = []; |
||
69 | $orderedResponses = []; |
||
70 | |||
71 | foreach ($messages['request'] as $depth => $requests) { |
||
72 | foreach ($requests as $idx => $request) { |
||
73 | $orderedRequests[$idx][$depth] = $request; |
||
74 | } |
||
75 | } |
||
76 | |||
77 | foreach ($messages['response'] as $depth => $responses) { |
||
78 | foreach ($responses as $idx => $response) { |
||
79 | $orderedResponses[$idx][$depth] = $response; |
||
80 | } |
||
81 | } |
||
82 | |||
83 | return new self($orderedRequests, $orderedResponses); |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * @return array |
||
88 | */ |
||
89 | public function getRequests() |
||
93 | |||
94 | /** |
||
95 | * @param array $requests |
||
96 | * |
||
97 | * @return ClientDataCollector |
||
98 | */ |
||
99 | public function setRequests($requests) |
||
105 | |||
106 | /** |
||
107 | * @return array |
||
108 | */ |
||
109 | public function getResponses() |
||
113 | |||
114 | /** |
||
115 | * @param array $responses |
||
116 | * |
||
117 | * @return ClientDataCollector |
||
118 | */ |
||
119 | public function setResponses($responses) |
||
125 | |||
126 | /** |
||
127 | * Get the index keys for the request and response stacks. |
||
128 | * |
||
129 | * @return array |
||
130 | */ |
||
131 | public function getStackIndexKeys() |
||
135 | |||
136 | /** |
||
137 | * @param int $idx |
||
138 | * |
||
139 | * @return array responses |
||
140 | */ |
||
141 | public function getRequstStack($idx) |
||
145 | |||
146 | /** |
||
147 | * @param int $idx |
||
148 | * |
||
149 | * @return array responses |
||
150 | */ |
||
151 | public function getResponseStack($idx) |
||
155 | } |
||
156 |
Let’s assume you have a class which uses late-static binding:
}
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: