Skip to content

Commit

Permalink
Merge pull request #171 from romanatteamnet/master
Browse files Browse the repository at this point in the history
Add basic xsd:sequence support to PhpConverter
  • Loading branch information
goetas authored Sep 19, 2024
2 parents 95db4b6 + bba3d45 commit 2b91509
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions src/Php/PhpConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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\Element\Sequence;
use GoetasWebservices\XML\XSDReader\Schema\Item;
use GoetasWebservices\XML\XSDReader\Schema\Schema;
use GoetasWebservices\XML\XSDReader\Schema\Type\BaseComplexType;
Expand Down Expand Up @@ -118,19 +119,42 @@ private function visitTypeBase(PHPClass $class, Type $type)
$this->visitComplexType($class, $type);
}
}


/**
* Process xsd:complexType xsd:sequence xsd:element
*
* @param PHPClass $class
* @param Schema $schema
* @param Sequence $sequence
*/
private function visitSequence(PHPClass $class, Schema $schema, Sequence $sequence)
{
foreach ($sequence->getElements() as $childSequence) {
if ($childSequence instanceof Group) {
$this->visitGroup($class, $schema, $childSequence);
} else {
$property = $this->visitElement($class, $schema, $childSequence);
$class->addProperty($property);
}
}
}

/**
* 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);
if ($choiceOption instanceof Sequence) {
$this->visitSequence($class, $schema, $choiceOption);
} else {
$property = $this->visitElement($class, $schema, $choiceOption);
$class->addProperty($property);
}
}
}

Expand Down Expand Up @@ -320,7 +344,9 @@ private function visitComplexType(PHPClass $class, ComplexType $type)
{
$schema = $type->getSchema();
foreach ($type->getElements() as $element) {
if ($element instanceof Choice) {
if ($element instanceof Sequence) {
$this->visitSequence($class, $schema, $element);
} elseif ($element instanceof Choice) {
$this->visitChoice($class, $schema, $element);
} elseif ($element instanceof Group) {
$this->visitGroup($class, $schema, $element);
Expand Down

0 comments on commit 2b91509

Please sign in to comment.