From 172ca5bdad9c686005506e30e1bb95baa7da3780 Mon Sep 17 00:00:00 2001 From: Toon Verwerft Date: Fri, 24 May 2024 12:27:22 +0200 Subject: [PATCH] Add additional method metadata --- composer.json | 2 +- src/Locator/Wsdl1SelectedServiceLocator.php | 1 + .../BindingOperationConfigurator.php | 25 +++++++++++++++++++ .../Configurator/Wsdl1Configurator.php | 19 ++++++++++++++ .../Wsdl1SelectedServiceConfigurator.php | 1 + src/Model/Definitions/BindingStyle.php | 7 +++++- src/Model/Definitions/BindingUse.php | 5 ++++ src/Model/Definitions/EncodingStyle.php | 10 ++++++++ .../Implementation/Message/SoapMessage.php | 4 +++ src/Model/Service/Wsdl1SelectedService.php | 2 ++ src/Model/Wsdl1.php | 2 ++ .../Definitions/TargetNamespaceParser.php | 19 ++++++++++++++ src/Parser/Strategy/SoapStrategy.php | 14 ++++++++--- src/Parser/Wsdl1Parser.php | 2 ++ 14 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 src/Metadata/Converter/Methods/Configurator/Wsdl1Configurator.php create mode 100644 src/Model/Definitions/EncodingStyle.php create mode 100644 src/Parser/Definitions/TargetNamespaceParser.php diff --git a/composer.json b/composer.json index 80ab5ae..a8529b0 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "php": "~8.1.0 || ~8.2.0 || ~8.3.0", "ext-dom": "*", "goetas-webservices/xsd-reader": "^0.4.1", - "php-soap/engine": "^2.7", + "php-soap/engine": "^2.8", "php-soap/wsdl": "^1.4", "veewee/xml": "^2.6 || ^3.0", "azjezz/psl": "^2.4", diff --git a/src/Locator/Wsdl1SelectedServiceLocator.php b/src/Locator/Wsdl1SelectedServiceLocator.php index 8b9b965..5cfafe2 100644 --- a/src/Locator/Wsdl1SelectedServiceLocator.php +++ b/src/Locator/Wsdl1SelectedServiceLocator.php @@ -28,6 +28,7 @@ public function __invoke(Wsdl1 $wsdl, ServiceSelectionCriteria $criteria): Wsdl1 if ($portType->isSome()) { return new Wsdl1SelectedService( + wsdl: $wsdl, service: $service, port: $port->unwrap(), binding: $binding->unwrap(), diff --git a/src/Metadata/Converter/Methods/Configurator/BindingOperationConfigurator.php b/src/Metadata/Converter/Methods/Configurator/BindingOperationConfigurator.php index 3768163..822eae5 100644 --- a/src/Metadata/Converter/Methods/Configurator/BindingOperationConfigurator.php +++ b/src/Metadata/Converter/Methods/Configurator/BindingOperationConfigurator.php @@ -23,9 +23,14 @@ public function __invoke(Method $method, BindingOperation $operation): Method fn (MethodMeta $meta): MethodMeta => $meta ->withSoapVersion($implementation->version->value) ->withAction($implementation->action) + ->withOperationName($operation->name) ->withBindingStyle($implementation->style->value) ->withInputBindingUsage($this->collectBindingUsageForMessage($operation->input)) + ->withInputNamespace($this->collectMessageNamespace($operation->input)) + ->withInputEncodingStyle($this->collectMessageEncodingStyle($operation->input)) ->withOutputBindingUsage($this->collectBindingUsageForMessage($operation->output)) + ->withOutputNamespace($this->collectMessageNamespace($operation->input)) + ->withOutputEncodingStyle($this->collectMessageEncodingStyle($operation->output)) ); } @@ -38,4 +43,24 @@ private function collectBindingUsageForMessage(?BindingOperationMessage $message return $implementation->bindingUse->value; } + + private function collectMessageNamespace(?BindingOperationMessage $message): ?string + { + $implementation = $message?->implementation; + if (!$implementation instanceof SoapMessage) { + return null; + } + + return $implementation->namespace?->value(); + } + + private function collectMessageEncodingStyle(?BindingOperationMessage $message): ?string + { + $implementation = $message?->implementation; + if (!$implementation instanceof SoapMessage) { + return null; + } + + return $implementation->encodingStyle?->value; + } } diff --git a/src/Metadata/Converter/Methods/Configurator/Wsdl1Configurator.php b/src/Metadata/Converter/Methods/Configurator/Wsdl1Configurator.php new file mode 100644 index 0000000..e543c9b --- /dev/null +++ b/src/Metadata/Converter/Methods/Configurator/Wsdl1Configurator.php @@ -0,0 +1,19 @@ +withMeta( + static fn (MethodMeta $meta): MethodMeta => $meta + ->withTargetNamespace($wsdl->targetNamespace?->value()) + ); + } +} diff --git a/src/Metadata/Converter/Methods/Configurator/Wsdl1SelectedServiceConfigurator.php b/src/Metadata/Converter/Methods/Configurator/Wsdl1SelectedServiceConfigurator.php index 2089a6c..2cc89fa 100644 --- a/src/Metadata/Converter/Methods/Configurator/Wsdl1SelectedServiceConfigurator.php +++ b/src/Metadata/Converter/Methods/Configurator/Wsdl1SelectedServiceConfigurator.php @@ -14,6 +14,7 @@ public function __invoke(Method $method, Wsdl1SelectedService $service): Method return pipe( static fn (Method $method) => (new BindingConfigurator())($method, $service->binding), static fn (Method $method) => (new PortConfigurator())($method, $service->port), + static fn (Method $method) => (new Wsdl1Configurator())($method, $service->wsdl), )($method); } } diff --git a/src/Model/Definitions/BindingStyle.php b/src/Model/Definitions/BindingStyle.php index e3ac218..66f4255 100644 --- a/src/Model/Definitions/BindingStyle.php +++ b/src/Model/Definitions/BindingStyle.php @@ -6,5 +6,10 @@ enum BindingStyle: string { case DOCUMENT = 'document'; - case RPC = 'RPC'; + case RPC = 'rpc'; + + public static function tryFromCaseInsensitive(string $value): ?self + { + return self::tryFrom(mb_strtolower($value)); + } } diff --git a/src/Model/Definitions/BindingUse.php b/src/Model/Definitions/BindingUse.php index 955ea63..2c10908 100644 --- a/src/Model/Definitions/BindingUse.php +++ b/src/Model/Definitions/BindingUse.php @@ -7,4 +7,9 @@ enum BindingUse: string { case LITERAL = 'literal'; case ENCODED = 'encoded'; + + public static function tryFromCaseInsensitive(string $value): ?self + { + return self::tryFrom(mb_strtolower($value)); + } } diff --git a/src/Model/Definitions/EncodingStyle.php b/src/Model/Definitions/EncodingStyle.php new file mode 100644 index 0000000..37e92d2 --- /dev/null +++ b/src/Model/Definitions/EncodingStyle.php @@ -0,0 +1,10 @@ +locateDocumentElement(); + + return $definitions->hasAttribute('targetNamespace') + ? Xmlns::load($definitions->getAttribute('targetNamespace')) + : null; + } +} diff --git a/src/Parser/Strategy/SoapStrategy.php b/src/Parser/Strategy/SoapStrategy.php index 9b62c2a..5fcaf13 100644 --- a/src/Parser/Strategy/SoapStrategy.php +++ b/src/Parser/Strategy/SoapStrategy.php @@ -6,6 +6,7 @@ use DOMElement; use Soap\WsdlReader\Model\Definitions\BindingStyle; use Soap\WsdlReader\Model\Definitions\BindingUse; +use Soap\WsdlReader\Model\Definitions\EncodingStyle; use Soap\WsdlReader\Model\Definitions\Implementation\Binding\BindingImplementation; use Soap\WsdlReader\Model\Definitions\Implementation\Binding\SoapBinding; use Soap\WsdlReader\Model\Definitions\Implementation\Message\MessageImplementation; @@ -16,6 +17,7 @@ use Soap\WsdlReader\Model\Definitions\TransportType; use Soap\WsdlReader\Parser\Definitions\SoapVersionParser; use VeeWee\Xml\Dom\Document; +use VeeWee\Xml\Xmlns\Xmlns; use function VeeWee\Xml\Dom\Locator\Element\locate_by_tag_name; final class SoapStrategy implements StrategyInterface @@ -33,7 +35,7 @@ public function parseOperationImplementation(Document $wsdl, DOMElement $operati return new SoapOperation( version: $this->parseVersionFromNode($wsdl, $operation), action: $operation->getAttribute('soapAction'), - style: BindingStyle::tryFrom($operation->getAttribute('style')) ?? BindingStyle::DOCUMENT, + style: BindingStyle::tryFromCaseInsensitive($operation->getAttribute('style')) ?? BindingStyle::DOCUMENT, ); } @@ -41,11 +43,17 @@ public function parseMessageImplementation(Document $wsdl, DOMElement $message): { $body = locate_by_tag_name($message, 'body')->item(0); if (!$body) { - return new SoapMessage(bindingUse: BindingUse::LITERAL); + return new SoapMessage( + bindingUse: BindingUse::LITERAL, + namespace: null, + encodingStyle: null + ); } return new SoapMessage( - bindingUse: BindingUse::tryFrom($body->getAttribute('use')) ?? BindingUse::LITERAL, + bindingUse: BindingUse::tryFromCaseInsensitive($body->getAttribute('use')) ?? BindingUse::LITERAL, + namespace: $body->hasAttribute('namespace') ? Xmlns::load($body->getAttribute('namespace')) : null, + encodingStyle: EncodingStyle::tryFrom($body->getAttribute('encodingStyle')), ); } diff --git a/src/Parser/Wsdl1Parser.php b/src/Parser/Wsdl1Parser.php index a271c46..7421119 100644 --- a/src/Parser/Wsdl1Parser.php +++ b/src/Parser/Wsdl1Parser.php @@ -11,6 +11,7 @@ use Soap\WsdlReader\Parser\Definitions\PortTypeParser; use Soap\WsdlReader\Parser\Definitions\SchemaParser; use Soap\WsdlReader\Parser\Definitions\ServiceParser; +use Soap\WsdlReader\Parser\Definitions\TargetNamespaceParser; use VeeWee\Xml\Dom\Document; final class Wsdl1Parser @@ -24,6 +25,7 @@ public function __invoke(Document $wsdl, ParserContext $context): Wsdl1 services: ServiceParser::tryParse($wsdl), schema: SchemaParser::tryParse($wsdl, $context), namespaces: NamespacesParser::tryParse($wsdl), + targetNamespace: TargetNamespaceParser::tryParse($wsdl) ); } }