public function testRender()
 {
     $XmlToArrayNode = new XmlToArrayNode($this->_name, $this->_attributes);
     $mockFalseXmlToArrayNode = new XmlToArrayNode($this->_name, false);
     $XmlToArrayNode->addChild($mockFalseXmlToArrayNode);
     $mockXmlToArrayNode = new XmlToArrayNode($this->_name, $this->_attributes);
     $XmlToArrayNode->addChild($mockXmlToArrayNode);
     $this->assertEquals(array('name' => array('name' => array(0 => '', 1 => ''))), $XmlToArrayNode->render('struct'));
     $XmlToArrayNode = new XmlToArrayNode($this->_name, $this->_attributes);
     $XmlToArrayNode->addChild($mockXmlToArrayNode);
     $this->assertEquals(array('name' => array('name' => '')), $XmlToArrayNode->render('struct'));
     $this->assertEquals(array('name' => array('name' => array('name' => array('@data' => '', '@attributes' => array('attribute1' => 'val1', 'attribute2' => 'val2'))), '@data' => '', '@attributes' => array('attribute1' => 'val1', 'attribute2' => 'val2'))), $XmlToArrayNode->render(FALSE));
     $this->assertEquals(array('name' => array('name' => '')), $XmlToArrayNode->render(TRUE));
     $mock2XmlToArrayNode = new XmlToArrayNode($this->_name, array());
     $XmlToArrayNode = new XmlToArrayNode($this->_name, $this->_attributes);
     $mockXmlToArrayNode->addChild($mock2XmlToArrayNode);
     $XmlToArrayNode->addChild($mockXmlToArrayNode);
     $XmlToArrayNode->addChild($mockXmlToArrayNode);
     $this->assertEquals(array('name' => array('name' => array(0 => array('name' => array('name' => '')), 1 => array('name' => array('name' => ''))))), $XmlToArrayNode->render('struct'));
 }
Ejemplo n.º 2
0
 /**
  * Handler for start tags
  * @param resource $parser a resource handle of the XML parser
  * @param string $name
  * @param array $attributes
  * @return void
  */
 private function _start($parser, $name, $attributes)
 {
     $this->_tagStack[] = $name;
     if ($this->_maxDepth && count($this->_tagStack) > $this->_maxDepth) {
         throw new XmlToArrayException('Parse Error: max depth exceeded.', '7005');
     }
     $XmlToArrayNode = new XmlToArrayNode($name, $attributes);
     if ($this->_CurrentXmlToArrayNode instanceof XmlToArrayNode && $this->_CurrentXmlToArrayNode->isOpen()) {
         $this->_CurrentXmlToArrayNode->addChild($XmlToArrayNode);
         $XmlToArrayNode->setParentXmlToArrayNode($this->_CurrentXmlToArrayNode);
     }
     $this->_CurrentXmlToArrayNode = $XmlToArrayNode;
 }