|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Freshcells\SoapClientBundle\DataCollector; |
|
4
|
|
|
|
|
5
|
|
|
use Freshcells\SoapClientBundle\Event\RequestEvent; |
|
6
|
|
|
use Freshcells\SoapClientBundle\Event\ResponseEvent; |
|
7
|
|
|
|
|
8
|
|
|
class SoapCallRegistry |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var array |
|
12
|
|
|
*/ |
|
13
|
|
|
private $calls = []; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @param RequestEvent $event |
|
17
|
|
|
*/ |
|
18
|
9 |
|
public function addRequest(RequestEvent $event) |
|
19
|
|
|
{ |
|
20
|
|
|
$request = array( |
|
21
|
9 |
|
'resource' => $event->getResource(), |
|
22
|
9 |
|
'request_headers' => '', |
|
23
|
9 |
|
'request_body' => $this->prettyXML($event->getRequest()), |
|
24
|
9 |
|
'response_headers' => '', |
|
25
|
9 |
|
'response_body' => '', |
|
26
|
9 |
|
'start' => microtime(true), |
|
27
|
|
|
); |
|
28
|
9 |
|
$this->calls[$event->getId()] = $request; |
|
29
|
9 |
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param ResponseEvent $event |
|
33
|
|
|
*/ |
|
34
|
9 |
|
public function addResponse(ResponseEvent $event) |
|
35
|
|
|
{ |
|
36
|
9 |
|
$id = $event->getId(); |
|
37
|
9 |
|
$response = $event->getResponseContent() ? |
|
38
|
9 |
|
$this->prettyXML($event->getResponseContent()) : |
|
39
|
9 |
|
$event->getResponseContent(); |
|
40
|
9 |
|
$this->calls[$id]['end'] = microtime(true); |
|
41
|
9 |
|
$this->calls[$id]['request_headers'] = $event->getRequestHeaders(); |
|
42
|
9 |
|
$this->calls[$id]['request_body'] = $this->prettyXML($event->getRequestContent()); |
|
43
|
9 |
|
$this->calls[$id]['response_headers'] = $event->getResponseHeaders(); |
|
44
|
9 |
|
$this->calls[$id]['response_body'] = $response; |
|
45
|
9 |
|
$this->calls[$id]['duration'] = ($this->calls[$id]['end'] - $this->calls[$id]['start']); |
|
46
|
9 |
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param string $xml |
|
50
|
|
|
* @return string |
|
51
|
|
|
*/ |
|
52
|
9 |
|
private function prettyXML(string $xml): string |
|
53
|
|
|
{ |
|
54
|
|
|
try { |
|
55
|
|
|
//nicen |
|
56
|
9 |
|
$doc = new \DomDocument('1.0'); |
|
57
|
9 |
|
$doc->loadXML($xml); |
|
58
|
6 |
|
$doc->formatOutput = true; |
|
59
|
|
|
|
|
60
|
6 |
|
return $doc->saveXML(); |
|
61
|
3 |
|
} catch (\Exception $e) { |
|
62
|
|
|
// probably no xml, just let it pass |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
3 |
|
return $xml; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return array |
|
70
|
|
|
*/ |
|
71
|
6 |
|
public function getCalls(): array |
|
72
|
|
|
{ |
|
73
|
6 |
|
return $this->calls; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|