Skip to content

Stormware's Pohoda schema ready #191

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
45 changes: 32 additions & 13 deletions src/Php/PhpConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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\Element\GroupRef;
use GoetasWebservices\XML\XSDReader\Schema\Item;
use GoetasWebservices\XML\XSDReader\Schema\Schema;
use GoetasWebservices\XML\XSDReader\Schema\Type\BaseComplexType;
Expand Down Expand Up @@ -131,14 +132,19 @@ private function visitTypeBase(PHPClass $class, Type $type): void
*/
private function visitSequence(PHPClass $class, Schema $schema, Sequence $sequence): void
{
foreach ($this->filterElements($sequence) as $childSequence) {
if ($childSequence instanceof Group) {
$this->visitGroup($class, $schema, $childSequence);
} elseif ($childSequence instanceof Choice) {
$this->visitChoice($class, $schema, $childSequence);
} else {
$property = $this->visitElement($class, $schema, $childSequence);
foreach ($this->filterElements($sequence) as $child) {
if ($child instanceof Group) {
$this->visitGroup($class, $schema, $child);
} elseif ($child instanceof Choice) {
$this->visitChoice($class, $schema, $child);
} elseif ($child instanceof ElementSingle) {
$property = $this->visitElement($class, $schema, $child);
$class->addProperty($property);
} elseif ($child instanceof GroupRef) {
// Recursively process GroupRef
$this->visitGroup($class, $schema, $child->getGroup());
} else {
throw new \InvalidArgumentException('Unsupported element type: ' . get_class($child));
}
}
}
Expand All @@ -160,21 +166,33 @@ private function visitChoice(PHPClass $class, Schema $schema, Choice $choice): v
foreach ($this->filterElements($choice) as $choiceOption) {
if ($choiceOption instanceof Sequence) {
$this->visitSequence($class, $schema, $choiceOption);
} else {
} elseif ($choiceOption instanceof Group) {
$this->visitGroup($class, $schema, $choiceOption);
} elseif ($choiceOption instanceof ElementSingle) {
$property = $this->visitElement($class, $schema, $choiceOption);
$class->addProperty($property);
} elseif ($choiceOption instanceof GroupRef) {
// Recursively process GroupRef
$this->visitGroup($class, $schema, $choiceOption->getGroup());
} else {
throw new \InvalidArgumentException('Unsupported element type: ' . get_class($choiceOption));
}
}
}

private function visitGroup(PHPClass $class, Schema $schema, Group $group): void
{
foreach ($this->filterElements($group) as $childGroup) {
if ($childGroup instanceof Group) {
$this->visitGroup($class, $schema, $childGroup);
} else {
$property = $this->visitElement($class, $schema, $childGroup);
foreach ($this->filterElements($group) as $child) {
if ($child instanceof Group) {
$this->visitGroup($class, $schema, $child);
} elseif ($child instanceof ElementSingle) {
$property = $this->visitElement($class, $schema, $child);
$class->addProperty($property);
} elseif ($child instanceof GroupRef) {
// Recursively process GroupRef
$this->visitGroup($class, $schema, $child->getGroup());
} else {
throw new \InvalidArgumentException('Unsupported element type: ' . get_class($child));
}
}
}
Expand Down Expand Up @@ -593,4 +611,5 @@ private function findPHPElementClassName(PHPClass $class, ElementItem $element)

return $this->findPHPClass($class, $element);
}

}