dmt-software /
insolvency-client
| 1 | <?php |
||
| 2 | |||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 3 | namespace DMT\Insolvency\Soap\Serializer; |
||
| 4 | |||
| 5 | use JMS\Serializer\EventDispatcher\EventSubscriberInterface; |
||
| 6 | use JMS\Serializer\EventDispatcher\ObjectEvent; |
||
| 7 | use JMS\Serializer\SerializationContext; |
||
| 8 | use JMS\Serializer\XmlSerializationVisitor; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * Class SoapAddressingEventSubscriber |
||
| 12 | */ |
||
|
0 ignored issues
–
show
|
|||
| 13 | class SoapAddressingEventSubscriber implements EventSubscriberInterface |
||
| 14 | { |
||
| 15 | /** @var string $action */ |
||
|
0 ignored issues
–
show
|
|||
| 16 | protected $action = 'http://www.rechtspraak.nl/namespaces/cir01/%s'; |
||
| 17 | |||
| 18 | /** @var string $endPoint */ |
||
|
0 ignored issues
–
show
|
|||
| 19 | protected $endPoint = 'https://webservice.rechtspraak.nl/cir.asmx'; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * SoapAddressingEventSubscriber constructor. |
||
| 23 | * @param string|null $action |
||
|
0 ignored issues
–
show
|
|||
| 24 | * @param string|null $endPoint |
||
|
0 ignored issues
–
show
|
|||
| 25 | */ |
||
| 26 | 13 | public function __construct(string $action = null, string $endPoint = null) |
|
| 27 | { |
||
| 28 | 13 | if ($action) { |
|
| 29 | $this->action = $action; |
||
| 30 | } |
||
| 31 | 13 | if ($endPoint) { |
|
| 32 | $this->endPoint = $endPoint; |
||
| 33 | } |
||
| 34 | 13 | } |
|
| 35 | |||
| 36 | /** |
||
|
0 ignored issues
–
show
|
|||
| 37 | * @return array |
||
| 38 | */ |
||
| 39 | 12 | public static function getSubscribedEvents() |
|
| 40 | { |
||
| 41 | return [ |
||
| 42 | [ |
||
| 43 | 12 | 'event' => 'serializer.post_serialize', |
|
| 44 | 'method' => 'addAddressing', |
||
| 45 | 'format' => 'soap', |
||
| 46 | ] |
||
| 47 | ]; |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
|
0 ignored issues
–
show
|
|||
| 51 | * @param ObjectEvent $event |
||
|
0 ignored issues
–
show
|
|||
| 52 | */ |
||
|
0 ignored issues
–
show
|
|||
| 53 | 12 | public function addAddressing(ObjectEvent $event) |
|
| 54 | { |
||
| 55 | /** @var SerializationContext $context */ |
||
|
0 ignored issues
–
show
|
|||
| 56 | 12 | $context = $event->getContext(); |
|
| 57 | /** @var XmlSerializationVisitor $visitor */ |
||
|
0 ignored issues
–
show
|
|||
| 58 | 12 | $visitor = $event->getVisitor(); |
|
| 59 | |||
| 60 | 12 | $document = $visitor->getDocument(); |
|
| 61 | 12 | $xpath = new \DOMXPath($document); |
|
| 62 | 12 | $query = '//*[local-name()="Action" and namespace-uri()="http://schemas.xmlsoap.org/ws/2004/08/addressing"]'; |
|
| 63 | 12 | $namespace = $document->lookupNamespaceUri('soap'); |
|
| 64 | |||
| 65 | if ( |
||
|
0 ignored issues
–
show
|
|||
| 66 | 12 | $context->getDepth() > 0 |
|
|
0 ignored issues
–
show
|
|||
| 67 | 12 | || $document->getElementsByTagNameNS($namespace, 'Body')->length == 0 |
|
| 68 | 12 | || $document->getElementsByTagNameNS($namespace, 'Header')->length == 0 |
|
| 69 | 12 | || $xpath->query($query)->length > 0 |
|
| 70 | ) { |
||
| 71 | 11 | return; |
|
| 72 | } |
||
| 73 | |||
| 74 | 12 | $action = sprintf( |
|
| 75 | 12 | $this->action, |
|
| 76 | 12 | $document->getElementsByTagNameNS($namespace, 'Body')[0]->firstChild->localName |
|
| 77 | ); |
||
| 78 | |||
| 79 | /** @var \DOMElement $element */ |
||
|
0 ignored issues
–
show
|
|||
| 80 | 12 | $element = $document->getElementsByTagNameNS($namespace, 'Header')[0]; |
|
| 81 | 12 | $element->appendChild( |
|
| 82 | 12 | $document->createElementNS('http://schemas.xmlsoap.org/ws/2004/08/addressing', 'Action', $action) |
|
| 83 | ); |
||
| 84 | 12 | $element->appendChild( |
|
| 85 | 12 | $document->createElementNS('http://schemas.xmlsoap.org/ws/2004/08/addressing', 'To', $this->endPoint) |
|
| 86 | ); |
||
| 87 | } |
||
| 88 | } |