|
10 | 10 | use Soap\WsdlReader\Model\Definitions\Implementation\Message\MessageImplementation;
|
11 | 11 | use Soap\WsdlReader\Model\Definitions\Implementation\Operation\HttpOperation;
|
12 | 12 | use Soap\WsdlReader\Model\Definitions\Implementation\Operation\OperationImplementation;
|
| 13 | +use Soap\WsdlReader\Model\Definitions\TransportType; |
13 | 14 | use VeeWee\Xml\Dom\Document;
|
| 15 | +use function VeeWee\Xml\Dom\Locator\Element\children; |
14 | 16 |
|
15 | 17 | final class HttpStrategy implements StrategyInterface
|
16 | 18 | {
|
| 19 | + private const HTTP_NAMESPACE = 'http://schemas.xmlsoap.org/wsdl/http/'; |
| 20 | + private const MIME_NAMESPACE = 'http://schemas.xmlsoap.org/wsdl/mime/'; |
| 21 | + |
17 | 22 | public function parseBindingImplementation(Document $wsdl, DOMElement $binding): BindingImplementation
|
18 | 23 | {
|
19 | 24 | return new HttpBinding(
|
20 |
| - verb: $binding->getAttribute('verb') |
| 25 | + verb: $binding->getAttribute('verb'), |
| 26 | + transport: TransportType::tryFrom((string) $binding->namespaceURI) ?? TransportType::HTTP, |
21 | 27 | );
|
22 | 28 | }
|
23 | 29 |
|
24 | 30 | public function parseOperationImplementation(Document $wsdl, DOMElement $operation): OperationImplementation
|
25 | 31 | {
|
26 | 32 | return new HttpOperation(
|
27 |
| - location: $operation->getAttribute('location') |
| 33 | + location: $operation->getAttribute('location'), |
28 | 34 | );
|
29 | 35 | }
|
30 | 36 |
|
31 | 37 | public function parseMessageImplementation(Document $wsdl, DOMElement $message): MessageImplementation
|
32 | 38 | {
|
33 |
| - return new HttpMessage(); |
| 39 | + $info = children($message)->first(); |
| 40 | + $fallbackImplementation = new HttpMessage( |
| 41 | + contentType: 'application/xml', |
| 42 | + part: null |
| 43 | + ); |
| 44 | + |
| 45 | + if (!$info) { |
| 46 | + return $fallbackImplementation; |
| 47 | + } |
| 48 | + |
| 49 | + return match ($info->namespaceURI) { |
| 50 | + self::HTTP_NAMESPACE => new HttpMessage( |
| 51 | + contentType: 'text/plain', |
| 52 | + part: null |
| 53 | + ), |
| 54 | + self::MIME_NAMESPACE => new HttpMessage( |
| 55 | + contentType: match($info->localName) { |
| 56 | + 'content' => $info->hasAttribute('type') ? $info->getAttribute('type'): 'application/xml', |
| 57 | + 'mimeXml' => 'application/xml', |
| 58 | + 'multipartRelated' => 'Multipart/Related', |
| 59 | + default => 'application/xml' |
| 60 | + }, |
| 61 | + part: $info->hasAttribute('part') ? $info->getAttribute('part') : null, |
| 62 | + ), |
| 63 | + default => $fallbackImplementation, |
| 64 | + }; |
34 | 65 | }
|
35 | 66 | }
|
0 commit comments