API: Complete respond function
This commit is contained in:
parent
c11c2d0fd4
commit
93daa9e247
25
lib/api.php
25
lib/api.php
|
@ -115,13 +115,32 @@ class OC_API {
|
|||
*/
|
||||
private static function respond($response, $format='json'){
|
||||
if ($format == 'json') {
|
||||
echo json_encode($response);
|
||||
//} else if ($format == 'xml') {
|
||||
// TODO array to xml
|
||||
OC_JSON::encodedPrint($response);
|
||||
} else if ($format == 'xml') {
|
||||
header('Content-type: text/xml; charset=UTF-8');
|
||||
$writer = new XMLWriter();
|
||||
$writer->openMemory();
|
||||
$writer->setIndent( true );
|
||||
$writer->startDocument();
|
||||
self::toXML($response, $writer);
|
||||
$writer->endDocument();
|
||||
echo $writer->outputMemory(true);
|
||||
} else {
|
||||
var_dump($format, $response);
|
||||
}
|
||||
}
|
||||
|
||||
private static function toXML($array, $writer){
|
||||
foreach($array as $k => $v) {
|
||||
if (is_array($v)) {
|
||||
$writer->startElement($k);
|
||||
self::toXML($v, $writer);
|
||||
$writer->endElement();
|
||||
} else {
|
||||
$writer->writeElement($k, $v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the user is authenticated
|
||||
|
|
Loading…
Reference in New Issue