public function testArrayToXmlWithNestedArray() { $array = array('key1' => 'value1', 'key2' => array('key3' => 'value2')); $xml = Utilities::arrayToXml($array); $obj = $this->parseXmlString($xml); $this->assertObjectHasAttribute('key1', $obj); $this->assertObjectHasAttribute('key2', $obj); $this->assertObjectHasAttribute('key3', $obj->key2); $this->assertEquals($array['key1'], $obj->key1); $this->assertEquals($array['key2']['key3'], $obj->key2->key3); }
public function sendData($data) { $this->header_manager->addHeader("Cache-Control", "no-cache, must-revalidate"); $this->header_manager->addHeader("Expires", 0); $this->header_manager->addHeader('Content-Type', $this->getFormat()); if ($this->getFormat() == Format::XML) { $output = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n"; $output .= "<result>" . Utilities::arrayToXml($data) . '</result>'; $data = $output; unset($output); } else { $data = json_encode($data); if ($this->getFormat() == Format::JSONP) { if (isset($_GET['callback']) && preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $_GET['callback'])) { $data = $_GET['callback'] . '(' . $data . ')'; } else { throw new RestException(HttpStatusCodes::BAD_REQUEST, 'No callback given.'); } } } $this->header_manager->sendAllHeaders(); echo $data; }