Skip to content

Commit

Permalink
Add additional method metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
veewee committed May 24, 2024
1 parent 32d32e0 commit 172ca5b
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/Locator/Wsdl1SelectedServiceLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
);
}

Expand All @@ -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;
}
}
19 changes: 19 additions & 0 deletions src/Metadata/Converter/Methods/Configurator/Wsdl1Configurator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);

namespace Soap\WsdlReader\Metadata\Converter\Methods\Configurator;

use Soap\Engine\Metadata\Model\Method;
use Soap\Engine\Metadata\Model\MethodMeta;
use Soap\WsdlReader\Model\Wsdl1;

final class Wsdl1Configurator
{
public function __invoke(Method $method, Wsdl1 $wsdl): Method
{
return $method->withMeta(
static fn (MethodMeta $meta): MethodMeta => $meta
->withTargetNamespace($wsdl->targetNamespace?->value())
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
7 changes: 6 additions & 1 deletion src/Model/Definitions/BindingStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
5 changes: 5 additions & 0 deletions src/Model/Definitions/BindingUse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
10 changes: 10 additions & 0 deletions src/Model/Definitions/EncodingStyle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);

namespace Soap\WsdlReader\Model\Definitions;

enum EncodingStyle: string
{
case SOAP_11 = 'http://schemas.xmlsoap.org/soap/encoding/';
case SOAP_12 = 'http://www.w3.org/2001/12/soap-encoding';
}
4 changes: 4 additions & 0 deletions src/Model/Definitions/Implementation/Message/SoapMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
namespace Soap\WsdlReader\Model\Definitions\Implementation\Message;

use Soap\WsdlReader\Model\Definitions\BindingUse;
use Soap\WsdlReader\Model\Definitions\EncodingStyle;
use VeeWee\Xml\Xmlns\Xmlns;

final class SoapMessage implements MessageImplementation
{
public function __construct(
public readonly BindingUse $bindingUse,
public readonly ?Xmlns $namespace,
public readonly ?EncodingStyle $encodingStyle
) {
}
}
2 changes: 2 additions & 0 deletions src/Model/Service/Wsdl1SelectedService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
use Soap\WsdlReader\Model\Definitions\Port;
use Soap\WsdlReader\Model\Definitions\PortType;
use Soap\WsdlReader\Model\Definitions\Service;
use Soap\WsdlReader\Model\Wsdl1;

final class Wsdl1SelectedService
{
public function __construct(
public readonly Wsdl1 $wsdl,
public readonly Service $service,
public readonly Port $port,
public readonly Binding $binding,
Expand Down
2 changes: 2 additions & 0 deletions src/Model/Wsdl1.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Soap\WsdlReader\Model\Definitions\Namespaces;
use Soap\WsdlReader\Model\Definitions\PortTypes;
use Soap\WsdlReader\Model\Definitions\Services;
use VeeWee\Xml\Xmlns\Xmlns;

final class Wsdl1
{
Expand All @@ -19,6 +20,7 @@ public function __construct(
public readonly Services $services,
public readonly Schema $schema,
public readonly Namespaces $namespaces,
public readonly ?Xmlns $targetNamespace,
) {
}
}
19 changes: 19 additions & 0 deletions src/Parser/Definitions/TargetNamespaceParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);

namespace Soap\WsdlReader\Parser\Definitions;

use VeeWee\Xml\Dom\Document;
use VeeWee\Xml\Xmlns\Xmlns;

final class TargetNamespaceParser
{
public static function tryParse(Document $wsdl): ?Xmlns
{
$definitions = $wsdl->locateDocumentElement();

return $definitions->hasAttribute('targetNamespace')
? Xmlns::load($definitions->getAttribute('targetNamespace'))
: null;
}
}
14 changes: 11 additions & 3 deletions src/Parser/Strategy/SoapStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -33,19 +35,25 @@ 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,
);
}

public function parseMessageImplementation(Document $wsdl, DOMElement $message): MessageImplementation
{
$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')),
);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Parser/Wsdl1Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
);
}
}

0 comments on commit 172ca5b

Please sign in to comment.