diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2016-09-05 21:00:53 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2016-09-06 11:57:39 +0200 |
commit | 3c55fe6bab73dabfb92e95e26f205fbb7b5781ec (patch) | |
tree | 4ee9ae8be1e3046cb98b0bd92e800853fdd5eaa8 /lib/public | |
parent | 314afcecf9080c78f485039852e30efee2e112c6 (diff) | |
download | nextcloud-server-3c55fe6bab73dabfb92e95e26f205fbb7b5781ec.tar.gz nextcloud-server-3c55fe6bab73dabfb92e95e26f205fbb7b5781ec.zip |
Split OCS version handling
This cleans up a bit the OCSController/Middleware. Since the 2 versions
of OCS differ a bit. Moved a lot of stuff internal since it is of no
concern to the outside.
Diffstat (limited to 'lib/public')
-rw-r--r-- | lib/public/AppFramework/OCSController.php | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/lib/public/AppFramework/OCSController.php b/lib/public/AppFramework/OCSController.php index 6036fc6a5a8..5f18ba0807a 100644 --- a/lib/public/AppFramework/OCSController.php +++ b/lib/public/AppFramework/OCSController.php @@ -42,6 +42,9 @@ use OCP\IRequest; */ abstract class OCSController extends ApiController { + /** @var int */ + private $ocsVersion; + /** * constructor of the controller * @param string $appName the name of the app @@ -72,6 +75,15 @@ abstract class OCSController extends ApiController { } /** + * @param int $version + * @since 9.2.0 + * @internal + */ + public function setOCSVersion($version) { + $this->ocsVersion = $version; + } + + /** * Since the OCS endpoints default to XML we need to find out the format * again * @param mixed $response the value that was returned from a controller and @@ -90,22 +102,16 @@ abstract class OCSController extends ApiController { * @param string $format json or xml * @param DataResponse $data the data which should be transformed * @since 8.1.0 - * @return OCSResponse + * @return \OC\AppFramework\OCS\BaseResponse */ private function buildOCSResponse($format, DataResponse $data) { - $params = [ - 'statuscode' => 100, - 'message' => 'OK', - 'data' => $data->getData(), - 'itemscount' => '', - 'itemsperpage' => '' - ]; + if ($this->ocsVersion === 1) { + $response = new \OC\AppFramework\OCS\V1Response($data, $format); + } else { + $response = new \OC\AppFramework\OCS\V2Response($data, $format); + } - return new OCSResponse( - $format, $params['statuscode'], - $params['message'], $params['data'], - $params['itemscount'], $params['itemsperpage'] - ); + return $response; } } |