You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

V1Response.php 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * @copyright 2016 Roeland Jago Douma <roeland@famdouma.nl>
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OC\AppFramework\OCS;
  25. use OCP\AppFramework\Http;
  26. use OCP\AppFramework\OCSController;
  27. class V1Response extends BaseResponse {
  28. /**
  29. * The V1 endpoint has very limited http status codes basically everything
  30. * is status 200 except 401
  31. *
  32. * @return int
  33. */
  34. public function getStatus() {
  35. $status = parent::getStatus();
  36. if ($status === Http::STATUS_FORBIDDEN || $status === OCSController::RESPOND_UNAUTHORISED) {
  37. return Http::STATUS_UNAUTHORIZED;
  38. }
  39. return Http::STATUS_OK;
  40. }
  41. /**
  42. * In v1 all OK is 100
  43. *
  44. * @return int
  45. */
  46. public function getOCSStatus() {
  47. $status = parent::getOCSStatus();
  48. if ($status === Http::STATUS_OK) {
  49. return 100;
  50. }
  51. return $status;
  52. }
  53. /**
  54. * Construct the meta part of the response
  55. * And then late the base class render
  56. *
  57. * @return string
  58. */
  59. public function render() {
  60. $meta = [
  61. 'status' => $this->getOCSStatus() === 100 ? 'ok' : 'failure',
  62. 'statuscode' => $this->getOCSStatus(),
  63. 'message' => $this->getOCSStatus() === 100 ? 'OK' : $this->statusMessage,
  64. ];
  65. $meta['totalitems'] = $this->itemsCount !== null ? (string)$this->itemsCount : '';
  66. $meta['itemsperpage'] = $this->itemsPerPage !== null ? (string)$this->itemsPerPage: '';
  67. return $this->renderResult($meta);
  68. }
  69. }