Skip to content

Commit

Permalink
Allow empty return types
Browse files Browse the repository at this point in the history
  • Loading branch information
veewee committed May 24, 2024
1 parent df16b8a commit 8786152
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 22 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"goetas-webservices/xsd-reader": "^0.4.1",
"php-soap/engine": "^2.8",
"php-soap/wsdl": "^1.4",
"php-soap/xml": "^1.6.0",
"veewee/xml": "^2.6 || ^3.0",
"azjezz/psl": "^2.4",
"symfony/console": "^5.4 || ^6.0 || ^7.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Soap\WsdlReader\Model\Definitions\Namespaces;
use Soap\WsdlReader\Model\Definitions\Part;
use Soap\WsdlReader\Model\Definitions\QNamed;
use Soap\Xml\Xmlns;
use function Psl\Dict\pull;

final class MessageToMetadataTypesConverter
Expand All @@ -29,13 +30,17 @@ public function __invoke(Message $message): array
{
return pull(
$message->parts->items,
fn (Part $part): XsdType => $this->findXsdType($part->element),
fn (Part $part): XsdType => $this->findXsdType($part->element)->withXmlTargetNodeName($part->name),
static fn (Part $message): string => $message->name
);
}

private function findXsdType(QNamed $type): XsdType
private function findXsdType(?QNamed $type): XsdType
{
if ($type === null) {
return $this->createAnyType();
}

$namespace = $this->namespaces->lookupNamespaceByQname($type);

try {
Expand All @@ -44,14 +49,38 @@ private function findXsdType(QNamed $type): XsdType
fn (): EngineType => $this->knownTypes->fetchFirstByName($type->localName),
)->unwrap()->getXsdType();
} catch (MetadataException $e) {
// Proxy to simple/base type ...
return XsdType::guess($type->localName)
->withXmlNamespaceName($type->prefix)
->withXmlNamespace($namespace->unwrapOr(''))
->withXmlTypeName($type->localName)
->withMeta(
static fn (TypeMeta $meta): TypeMeta => $meta->withIsSimple(true)
);
return $this->createSimpleTypeByQNamed($type);
}
}

private function createSimpleTypeByQNamed(QNamed $type): XsdType
{
$namespace = $this->namespaces->lookupNamespaceByQname($type);

return XsdType::guess($type->localName)
->withXmlNamespaceName($type->prefix)
->withXmlNamespace($namespace->unwrapOr(''))
->withXmlTypeName($type->localName)
->withMeta(
static fn (TypeMeta $meta): TypeMeta => $meta
->withIsSimple(true)
->withIsElement(true)
);
}

private function createAnyType(): XsdType
{
$namespace = Xmlns::xsd()->value();

return XsdType::guess('anyType')
->withXmlTypeName('anyType')
->withXmlNamespaceName($this->namespaces->lookupNameFromNamespace($namespace)->unwrapOr(''))
->withXmlNamespace($namespace)
->withXmlTypeName('anyType')
->withMeta(
static fn (TypeMeta $meta): TypeMeta => $meta
->withIsSimple(true)
->withIsElement(true)
);
}
}
8 changes: 1 addition & 7 deletions src/Metadata/Converter/Wsdl1ToMethodsConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,7 @@ private function parseMethod(Wsdl1SelectedService $service, BindingOperation $bi
$parameters = $inputMessage->map($convertMessageToTypesDict)->mapOr(
static fn (array $types) => map_with_key(
$types,
static fn (string $name, XsdType $type) => new Parameter(
$name,
// Make sure the target type encodes into an **element** that is **named like the parameter part**.
$type
->withXmlTargetNodeName($name)
->withMeta(static fn (TypeMeta $meta): TypeMeta => $meta->withIsElement(true))
)
static fn (string $name, XsdType $type) => new Parameter($name, $type)
),
[]
);
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Definitions/Part.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ final class Part
{
public function __construct(
public readonly string $name,
public readonly QNamed $element,
public readonly ?QNamed $element,
) {
}
}
16 changes: 12 additions & 4 deletions src/Parser/Definitions/MessageParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@ public function __invoke(Document $wsdl, DOMElement $message): Message
...$xpath->query('./wsdl:part', $message)
->expectAllOfType(DOMElement::class)
->map(
static fn (DOMElement $part) => new Part(
name: $part->getAttribute('name'),
element: QNamed::parse($part->getAttribute('element') ?: $part->getAttribute('type'))
)
static function (DOMElement $part) {
$element = match (true) {
$part->hasAttribute('element') => QNamed::parse($part->getAttribute('element')),
$part->hasAttribute('type') => QNamed::parse($part->getAttribute('type')),
default => null
};

return new Part(
name: $part->getAttribute('name'),
element: $element,
);
}
)
)
);
Expand Down

0 comments on commit 8786152

Please sign in to comment.