private function parseChoiceStructure(SimpleXMLElement $xml, PiBX_AST_Structure $ast, $parentObject) { $choiceCount = $ast->countChildren(); for ($i = 0; $i < $choiceCount; $i++) { $child = $ast->get($i); $name = $child->getName(); if ($xml->{$name}) { // choice in XML found $newObject = $this->parseXml($xml->{$name}, $child, $parentObject); $setter = $child->getSetMethod(); $parentObject->{$setter}($newObject); break; } } return $parentObject; }
private function marshalStructure($object, PiBX_AST_Structure $ast) { $lastNode = $this->parentDomNode; if ($ast->getStructureType() === PiBX_AST_StructureType::CHOICE()) { $this->parentDomNode = $this->currentDomNode; if ($ast->hasChildren()) { $childrenCount = $ast->countChildren(); $currentChoice = null; for ($i = 0; $i < $childrenCount; $i++) { $child = $ast->get($i); $testMethod = $child->getTestMethod(); if ($object->{$testMethod}()) { $currentChoice = $child; break; } } $this->marshalObject($object, $currentChoice); } } elseif ($ast->getStructureType() === PiBX_AST_StructureType::ORDERED()) { throw new RuntimeException('Currently not supported.'); } else { $this->parentDomNode->removeChild($this->currentDomNode); // when a structure has no type, it is a referenced complex-type // used as a type-attribute $getter = $ast->getGetMethod(); $obj = $object->{$getter}(); $classname = $this->binding->getClassnameForName($ast->getName()); $structureAst = $this->binding->getASTForClass($classname); $this->marshalObject($obj, $structureAst); } $this->parentDomNode = $lastNode; }