Beispiel #1
0
 /**
  * 
  * @param SimpleXMLElement $xml
  * @param PiBX_AST_Collection $ast
  * @param <type> $parentObject
  * @return mixed[] The collection entries
  */
 private function parseAnonymCollection(SimpleXMLElement $xml, PiBX_AST_Collection $ast, $parentObject)
 {
     $count = $ast->countChildren();
     $list = array();
     for ($i = 0; $i < $count; $i++) {
         $child = $ast->get($i);
         if ($child instanceof PiBX_AST_Structure) {
             $name = $child->getName();
             $structAst = $this->binding->getASTForName($name);
             $class = $structAst->getType();
             // somehow xpath didn't work well with node names containing a dash
             // so fetch the nodes with "{}", e.g. "{'node-containing-a-dash'}"
             $itemCount = count($xml->{$name});
             if ($itemCount > 0) {
                 // collection items/nodes are directly in the current node
                 for ($j = 0; $j < $itemCount; $j++) {
                     $newObject = new $class();
                     $listNode = $xml->{$name}[$j];
                     $list[] = $this->parseXml($listNode, $structAst, $newObject);
                 }
             }
         } else {
             throw new RuntimeException('Invalid <collection>');
         }
     }
     return $list;
 }