OCSResponse.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bernhard Posselt <dev@bernhard-posselt.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  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, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. /**
  25. * Public interface of ownCloud for apps to use.
  26. * AppFramework\HTTP\JSONResponse class
  27. */
  28. namespace OCP\AppFramework\Http;
  29. /**
  30. * A renderer for OCS responses
  31. * @since 8.1.0
  32. * @deprecated 9.2.0 To implement an OCS endpoint extend the OCSController
  33. */
  34. class OCSResponse extends Response {
  35. private $data;
  36. private $format;
  37. private $statuscode;
  38. private $message;
  39. private $itemscount;
  40. private $itemsperpage;
  41. /**
  42. * generates the xml or json response for the API call from an multidimenional data array.
  43. * @param string $format
  44. * @param int $statuscode
  45. * @param string $message
  46. * @param array $data
  47. * @param int|string $itemscount
  48. * @param int|string $itemsperpage
  49. * @since 8.1.0
  50. * @deprecated 9.2.0 To implement an OCS endpoint extend the OCSController
  51. */
  52. public function __construct($format, $statuscode, $message,
  53. $data=[], $itemscount='',
  54. $itemsperpage='') {
  55. $this->format = $format;
  56. $this->statuscode = $statuscode;
  57. $this->message = $message;
  58. $this->data = $data;
  59. $this->itemscount = $itemscount;
  60. $this->itemsperpage = $itemsperpage;
  61. // set the correct header based on the format parameter
  62. if ($format === 'json') {
  63. $this->addHeader(
  64. 'Content-Type', 'application/json; charset=utf-8'
  65. );
  66. } else {
  67. $this->addHeader(
  68. 'Content-Type', 'application/xml; charset=utf-8'
  69. );
  70. }
  71. }
  72. /**
  73. * @return string
  74. * @since 8.1.0
  75. * @deprecated 9.2.0 To implement an OCS endpoint extend the OCSController
  76. * @suppress PhanDeprecatedClass
  77. */
  78. public function render() {
  79. $r = new \OC\OCS\Result($this->data, $this->statuscode, $this->message);
  80. $r->setTotalItems($this->itemscount);
  81. $r->setItemsPerPage($this->itemsperpage);
  82. return \OC_API::renderResult($this->format, $r->getMeta(), $r->getData());
  83. }
  84. }