Skip to content

Commit 7143e02

Browse files
authored
Merge pull request #29 from veewee/allow-empty-return-types
Allow empty return types
2 parents df16b8a + b4c2ac3 commit 7143e02

File tree

5 files changed

+54
-23
lines changed

5 files changed

+54
-23
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"goetas-webservices/xsd-reader": "^0.4.1",
1919
"php-soap/engine": "^2.8",
2020
"php-soap/wsdl": "^1.4",
21+
"php-soap/xml": "^1.6.0",
2122
"veewee/xml": "^2.6 || ^3.0",
2223
"azjezz/psl": "^2.4",
2324
"symfony/console": "^5.4 || ^6.0 || ^7.0"

src/Metadata/Converter/Methods/Converter/MessageToMetadataTypesConverter.php

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Soap\WsdlReader\Model\Definitions\Namespaces;
1313
use Soap\WsdlReader\Model\Definitions\Part;
1414
use Soap\WsdlReader\Model\Definitions\QNamed;
15+
use Soap\Xml\Xmlns;
1516
use function Psl\Dict\pull;
1617

1718
final class MessageToMetadataTypesConverter
@@ -29,13 +30,17 @@ public function __invoke(Message $message): array
2930
{
3031
return pull(
3132
$message->parts->items,
32-
fn (Part $part): XsdType => $this->findXsdType($part->element),
33+
fn (Part $part): XsdType => $this->findXsdType($part->element)->withXmlTargetNodeName($part->name),
3334
static fn (Part $message): string => $message->name
3435
);
3536
}
3637

37-
private function findXsdType(QNamed $type): XsdType
38+
private function findXsdType(?QNamed $type): XsdType
3839
{
40+
if ($type === null) {
41+
return $this->createAnyType();
42+
}
43+
3944
$namespace = $this->namespaces->lookupNamespaceByQname($type);
4045

4146
try {
@@ -44,14 +49,38 @@ private function findXsdType(QNamed $type): XsdType
4449
fn (): EngineType => $this->knownTypes->fetchFirstByName($type->localName),
4550
)->unwrap()->getXsdType();
4651
} catch (MetadataException $e) {
47-
// Proxy to simple/base type ...
48-
return XsdType::guess($type->localName)
49-
->withXmlNamespaceName($type->prefix)
50-
->withXmlNamespace($namespace->unwrapOr(''))
51-
->withXmlTypeName($type->localName)
52-
->withMeta(
53-
static fn (TypeMeta $meta): TypeMeta => $meta->withIsSimple(true)
54-
);
52+
return $this->createSimpleTypeByQNamed($type);
5553
}
5654
}
55+
56+
private function createSimpleTypeByQNamed(QNamed $type): XsdType
57+
{
58+
$namespace = $this->namespaces->lookupNamespaceByQname($type);
59+
60+
return XsdType::guess($type->localName)
61+
->withXmlNamespaceName($type->prefix)
62+
->withXmlNamespace($namespace->unwrapOr(''))
63+
->withXmlTypeName($type->localName)
64+
->withMeta(
65+
static fn (TypeMeta $meta): TypeMeta => $meta
66+
->withIsSimple(true)
67+
->withIsElement(true)
68+
);
69+
}
70+
71+
private function createAnyType(): XsdType
72+
{
73+
$namespace = Xmlns::xsd()->value();
74+
75+
return XsdType::guess('anyType')
76+
->withXmlTypeName('anyType')
77+
->withXmlNamespaceName($this->namespaces->lookupNameFromNamespace($namespace)->unwrapOr(''))
78+
->withXmlNamespace($namespace)
79+
->withXmlTypeName('anyType')
80+
->withMeta(
81+
static fn (TypeMeta $meta): TypeMeta => $meta
82+
->withIsSimple(true)
83+
->withIsElement(true)
84+
);
85+
}
5786
}

src/Metadata/Converter/Wsdl1ToMethodsConverter.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Soap\Engine\Metadata\Collection\ParameterCollection;
88
use Soap\Engine\Metadata\Model\Method;
99
use Soap\Engine\Metadata\Model\Parameter;
10-
use Soap\Engine\Metadata\Model\TypeMeta;
1110
use Soap\Engine\Metadata\Model\XsdType;
1211
use Soap\WsdlReader\Locator\Wsdl1SelectedServiceLocator;
1312
use Soap\WsdlReader\Metadata\Converter\Methods\Configurator\BindingOperationConfigurator;
@@ -51,13 +50,7 @@ private function parseMethod(Wsdl1SelectedService $service, BindingOperation $bi
5150
$parameters = $inputMessage->map($convertMessageToTypesDict)->mapOr(
5251
static fn (array $types) => map_with_key(
5352
$types,
54-
static fn (string $name, XsdType $type) => new Parameter(
55-
$name,
56-
// Make sure the target type encodes into an **element** that is **named like the parameter part**.
57-
$type
58-
->withXmlTargetNodeName($name)
59-
->withMeta(static fn (TypeMeta $meta): TypeMeta => $meta->withIsElement(true))
60-
)
53+
static fn (string $name, XsdType $type) => new Parameter($name, $type)
6154
),
6255
[]
6356
);

src/Model/Definitions/Part.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ final class Part
77
{
88
public function __construct(
99
public readonly string $name,
10-
public readonly QNamed $element,
10+
public readonly ?QNamed $element,
1111
) {
1212
}
1313
}

src/Parser/Definitions/MessageParser.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,18 @@ public function __invoke(Document $wsdl, DOMElement $message): Message
2424
...$xpath->query('./wsdl:part', $message)
2525
->expectAllOfType(DOMElement::class)
2626
->map(
27-
static fn (DOMElement $part) => new Part(
28-
name: $part->getAttribute('name'),
29-
element: QNamed::parse($part->getAttribute('element') ?: $part->getAttribute('type'))
30-
)
27+
static function (DOMElement $part) {
28+
$element = match (true) {
29+
$part->hasAttribute('element') => QNamed::parse($part->getAttribute('element')),
30+
$part->hasAttribute('type') => QNamed::parse($part->getAttribute('type')),
31+
default => null
32+
};
33+
34+
return new Part(
35+
name: $part->getAttribute('name'),
36+
element: $element,
37+
);
38+
}
3139
)
3240
)
3341
);

0 commit comments

Comments
 (0)