aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/api.php
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-08-03 21:03:11 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2015-08-03 21:03:11 +0200
commit649cc2fa898968b78e249d594e846c84c3695d8d (patch)
tree69d42f0eabaf11ce18ad14acd223553c424c93db /lib/private/api.php
parentcd1bfd7eb67e95d5fcd3336b8a4d4109459f27d4 (diff)
downloadnextcloud-server-649cc2fa898968b78e249d594e846c84c3695d8d.tar.gz
nextcloud-server-649cc2fa898968b78e249d594e846c84c3695d8d.zip
Remove duplicate and unused code
Diffstat (limited to 'lib/private/api.php')
-rw-r--r--lib/private/api.php50
1 files changed, 30 insertions, 20 deletions
diff --git a/lib/private/api.php b/lib/private/api.php
index 125c547aebf..6f44401576b 100644
--- a/lib/private/api.php
+++ b/lib/private/api.php
@@ -357,24 +357,9 @@ class OC_API {
}
}
- $response = array(
- 'ocs' => array(
- 'meta' => $result->getMeta(),
- 'data' => $result->getData(),
- ),
- );
- if ($format == 'json') {
- 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);
- }
+ self::setContentType($format);
+ $body = self::renderResult($result, $format);
+ echo $body;
}
/**
@@ -411,8 +396,8 @@ class OC_API {
/**
* Based on the requested format the response content type is set
*/
- public static function setContentType() {
- $format = self::requestedFormat();
+ public static function setContentType($format = null) {
+ $format = is_null($format) ? self::requestedFormat() : $format;
if ($format === 'xml') {
header('Content-type: text/xml; charset=UTF-8');
return;
@@ -464,4 +449,29 @@ class OC_API {
}
return null;
}
+
+ /**
+ * @param OC_OCS_Result $result
+ * @param string $format
+ * @return string
+ */
+ public static function renderResult($result, $format) {
+ $response = array(
+ 'ocs' => array(
+ 'meta' => $result->getMeta(),
+ 'data' => $result->getData(),
+ ),
+ );
+ if ($format == 'json') {
+ return OC_JSON::encode($response);
+ }
+
+ $writer = new XMLWriter();
+ $writer->openMemory();
+ $writer->setIndent(true);
+ $writer->startDocument();
+ self::toXML($response, $writer);
+ $writer->endDocument();
+ return $writer->outputMemory(true);
+ }
}