From f702c79381c9c525759acd69a8a6c089a843710f Mon Sep 17 00:00:00 2001 From: Cybervitexus Date: Sat, 14 Oct 2023 08:57:56 +0200 Subject: [PATCH] Update PhpConverter.php Fix #163 - The Choice element was missing in process --- src/Php/PhpConverter.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Php/PhpConverter.php b/src/Php/PhpConverter.php index e825cc7..1d48fe7 100644 --- a/src/Php/PhpConverter.php +++ b/src/Php/PhpConverter.php @@ -11,6 +11,7 @@ use GoetasWebservices\XML\XSDReader\Schema\Element\ElementRef; use GoetasWebservices\XML\XSDReader\Schema\Element\ElementSingle; use GoetasWebservices\XML\XSDReader\Schema\Element\Group; +use GoetasWebservices\XML\XSDReader\Schema\Element\Choice; use GoetasWebservices\XML\XSDReader\Schema\Item; use GoetasWebservices\XML\XSDReader\Schema\Schema; use GoetasWebservices\XML\XSDReader\Schema\Type\BaseComplexType; @@ -118,6 +119,21 @@ private function visitTypeBase(PHPClass $class, Type $type) } } + /** + * Process xsd:complexType xsd:choice xsd:element + * + * @param PHPClass $class + * @param Schema $schema + * @param Choice $choice + */ + private function visitChoice(PHPClass $class, Schema $schema, Choice $choice) + { + foreach ($choice->getElements() as $choiceOption) { + $property = $this->visitElement($class, $schema, $choiceOption); + $class->addProperty($property); + } + } + private function visitGroup(PHPClass $class, Schema $schema, Group $group) { foreach ($group->getElements() as $childGroup) { @@ -304,7 +320,9 @@ private function visitComplexType(PHPClass $class, ComplexType $type) { $schema = $type->getSchema(); foreach ($type->getElements() as $element) { - if ($element instanceof Group) { + if ($element instanceof Choice) { + $this->visitChoice($class, $schema, $element); + } elseif ($element instanceof Group) { $this->visitGroup($class, $schema, $element); } else { $property = $this->visitElement($class, $schema, $element);