From cbd3d5d153c3e5d7878e57303d1ba0f3424486fe Mon Sep 17 00:00:00 2001 From: Toon Verwerft Date: Fri, 25 Oct 2024 07:38:30 +0200 Subject: [PATCH] Add support for simple element return types in soap methods --- .../CodeGenerator/Model/ReturnTypeSpec.php | 28 +++++++++++++++++++ .../CodeGenerator/Model/ReturnType.php | 7 +++++ 2 files changed, 35 insertions(+) diff --git a/spec/Phpro/SoapClient/CodeGenerator/Model/ReturnTypeSpec.php b/spec/Phpro/SoapClient/CodeGenerator/Model/ReturnTypeSpec.php index 38aca94f..d1ff1235 100644 --- a/spec/Phpro/SoapClient/CodeGenerator/Model/ReturnTypeSpec.php +++ b/spec/Phpro/SoapClient/CodeGenerator/Model/ReturnTypeSpec.php @@ -31,6 +31,34 @@ function it_has_a_type() $this->getType()->shouldReturn('\\My\\Namespace\\Type'); } + function it_can_fall_back_to_mixed_on_unkown_extension_of_simple_type() + { + $this->beConstructedWith( + 'Type', + 'My\Namespace', + XsdType::create('Type') + ->withMeta(static fn (TypeMeta $meta) => $meta->withIsSimple(true)) + ); + + $this->getType()->shouldReturn('mixed'); + } + + function it_can_fall_back_to_simple_type() + { + $this->beConstructedWith( + 'Type', + 'My\Namespace', + XsdType::create('Type') + ->withMeta(static fn (TypeMeta $meta) => $meta->withIsSimple(true)->withExtends([ + 'isSimple' => true, + 'type' => 'string', + 'namespace' => 'http://www.w3.org/2001/XMLSchema', + ])) + ); + + $this->getType()->shouldReturn('string'); + } + public function it_has_type_meta(): void { $this->getMeta()->shouldBeLike(new TypeMeta()); diff --git a/src/Phpro/SoapClient/CodeGenerator/Model/ReturnType.php b/src/Phpro/SoapClient/CodeGenerator/Model/ReturnType.php index 16813f25..c9d5e194 100644 --- a/src/Phpro/SoapClient/CodeGenerator/Model/ReturnType.php +++ b/src/Phpro/SoapClient/CodeGenerator/Model/ReturnType.php @@ -66,6 +66,13 @@ public function getType(): string if (Normalizer::isKnownType($this->type)) { return $this->type; } + + if ($this->meta->isSimple()->unwrapOr(false)) { + return $this->meta->extends() + ->filter(static fn (array $extends): bool => $extends['isSimple']) + ->map(static fn (array $extends): string => $extends['type']) + ->unwrapOr('mixed'); + } return '\\'.$this->namespace.'\\'.Normalizer::normalizeClassname($this->type); }