Esempio n. 1
0
 /**
  * Iterates over a set of data and builds it as XML
  *
  * @param \DOMDocument $doc The document being built
  * @param String $parent The tag name of the parent element
  * @param Array|\Traversable $data An array or a traversable object
  * @param Boolean $root Whether the data being parsed is at the root level
  * @return DOMNode Returns the built node
  */
 protected function iterate(\DOMDocument $doc, $parent, &$data, $root = FALSE)
 {
     if (!$root && is_array($data) && \r8\ary\isList($data)) {
         $node = $doc->createDocumentFragment();
         foreach ($data as $value) {
             $node->appendChild($this->build($doc, $parent, $value, FALSE));
         }
     } else {
         $node = $this->createElement($doc, $parent);
         foreach ($data as $key => $value) {
             $node->appendChild($this->build($doc, $key, $value, FALSE));
         }
     }
     return $node;
 }
Esempio n. 2
0
 public function testIsList()
 {
     $this->assertTrue(\r8\ary\isList(array("one", "two")));
     $this->assertFalse(\r8\ary\isList(array(5 => "one", 10 => "two")));
     $this->assertFalse(\r8\ary\isList(array("one" => "once", "two" => "twice")));
     $this->assertTrue(\r8\ary\isList(array()));
 }