Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow empty return types #29

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
);
}
}
9 changes: 1 addition & 8 deletions src/Metadata/Converter/Wsdl1ToMethodsConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Soap\Engine\Metadata\Collection\ParameterCollection;
use Soap\Engine\Metadata\Model\Method;
use Soap\Engine\Metadata\Model\Parameter;
use Soap\Engine\Metadata\Model\TypeMeta;
use Soap\Engine\Metadata\Model\XsdType;
use Soap\WsdlReader\Locator\Wsdl1SelectedServiceLocator;
use Soap\WsdlReader\Metadata\Converter\Methods\Configurator\BindingOperationConfigurator;
Expand Down Expand Up @@ -51,13 +50,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