/** * * @param SimpleXMLElement $xml * @param PiBX_AST_Collection $ast * @param <type> $parentObject * @return mixed[] The collection entries */ private function parseNamedCollection(SimpleXMLElement $xml, PiBX_AST_Collection $ast, $parentObject) { $count = $ast->countChildren(); $list = array(); $collectionName = $ast->getName(); 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->{$collectionName}->{$name}); if ($itemCount > 0) { // collection items/nodes are directly in the current node for ($j = 0; $j < $itemCount; $j++) { $newObject = new $class(); $listNode = $xml->{$collectionName}->{$name}[$j]; $list[] = $this->parseXml($listNode, $structAst, $newObject); } } } elseif ($child instanceof PiBX_AST_CollectionItem) { $name = $child->getName(); $itemCount = count($xml->{$collectionName}->{$name}); if ($itemCount > 0) { for ($j = 0; $j < $itemCount; $j++) { $listNode = $xml->{$collectionName}->{$name}[$j]; $list[] = $this->parseXml($listNode, $ast, $parentObject); } } } else { throw new RuntimeException('Invalid <collection>'); } } return $list; }