Beispiel #1
0
 /**
  * 
  * @param SimpleXMLElement $xml
  * @param PiBX_AST_Structure $ast
  * @param object $parentObject
  */
 private function parseStructure(SimpleXMLElement $xml, PiBX_AST_Structure $ast, $parentObject)
 {
     $name = $ast->getName();
     $type = $ast->getType();
     if ($type == '') {
         if ($ast->getStructureType() === PiBX_AST_StructureType::CHOICE()) {
             return $this->parseChoiceStructure($xml, $ast, $parentObject);
         } elseif ($ast->getStructureType() === PiBX_AST_StructureType::ORDERED()) {
             throw new RuntimeException('Not supported yet.');
         } else {
             throw new RuntimeException('Invalid <structure>.');
         }
     } else {
         // a structure with a type is a reference to the type
         if (!PiBX_ParseTree_BaseType::isBaseType($type)) {
             $structAst = $this->binding->getASTForClass($type);
             $newObject = new $type();
             $parsedObject = $this->parseXml($xml, $structAst, $newObject);
             $setter = $ast->getSetMethod();
             $parentObject->{$setter}($parsedObject);
         } else {
             return $parentObject;
         }
     }
 }
Beispiel #2
0
 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;
 }