|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Freshcells\SoapClientBundle\Plugin; |
|
4
|
|
|
|
|
5
|
|
|
use Freshcells\SoapClientBundle\DataCollector\SoapCallRegistry; |
|
6
|
|
|
use Freshcells\SoapClientBundle\Event\Events; |
|
7
|
|
|
use Freshcells\SoapClientBundle\Event\FaultEvent; |
|
8
|
|
|
use Freshcells\SoapClientBundle\Event\RequestEvent; |
|
9
|
|
|
use Freshcells\SoapClientBundle\Event\ResponseEvent; |
|
10
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
11
|
|
|
|
|
12
|
|
|
class DataCollectorPlugin implements EventSubscriberInterface |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var SoapCallRegistry |
|
16
|
|
|
*/ |
|
17
|
|
|
private $registry; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @param SoapCallRegistry $registry |
|
21
|
|
|
*/ |
|
22
|
9 |
|
public function __construct(SoapCallRegistry $registry) |
|
23
|
|
|
{ |
|
24
|
9 |
|
$this->registry = $registry; |
|
25
|
9 |
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param RequestEvent $event |
|
29
|
|
|
*/ |
|
30
|
6 |
|
public function onClientRequest(RequestEvent $event) |
|
31
|
|
|
{ |
|
32
|
6 |
|
$this->registry->addRequest($event); |
|
33
|
6 |
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param ResponseEvent $event |
|
37
|
|
|
*/ |
|
38
|
6 |
|
public function onClientResponse(ResponseEvent $event) |
|
39
|
|
|
{ |
|
40
|
6 |
|
$this->registry->addResponse($event); |
|
41
|
6 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param FaultEvent $event |
|
45
|
|
|
*/ |
|
46
|
3 |
|
public function onClientFault(FaultEvent $event) |
|
47
|
|
|
{ |
|
48
|
3 |
|
$this->registry->addRequest($event->getRequestEvent()); |
|
49
|
|
|
//todo use a dedicated fault rendering in profiler |
|
50
|
3 |
|
$this->registry->addResponse( |
|
51
|
3 |
|
new ResponseEvent( |
|
52
|
3 |
|
$event->getId(), |
|
53
|
3 |
|
$event->getRequestEvent()->getResource(), |
|
54
|
3 |
|
$event->getRequestEvent()->getRequest(), |
|
55
|
3 |
|
null, |
|
56
|
3 |
|
$event->getException()->getMessage(), |
|
57
|
3 |
|
null |
|
58
|
|
|
) |
|
59
|
|
|
); |
|
60
|
3 |
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* {@inheritdoc} |
|
64
|
|
|
*/ |
|
65
|
3 |
|
public static function getSubscribedEvents() |
|
66
|
|
|
{ |
|
67
|
|
|
return array( |
|
68
|
3 |
|
Events::REQUEST => 'onClientRequest', |
|
69
|
|
|
Events::RESPONSE => 'onClientResponse', |
|
70
|
|
|
Events::FAULT => 'onClientFault' |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|