DataResponse.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. /**
  24. * Public interface of ownCloud for apps to use.
  25. * AppFramework\HTTP\DataResponse class
  26. */
  27. namespace OCP\AppFramework\Http;
  28. use OCP\AppFramework\Http;
  29. /**
  30. * A generic DataResponse class that is used to return generic data responses
  31. * for responders to transform
  32. * @since 8.0.0
  33. */
  34. class DataResponse extends Response {
  35. /**
  36. * response data
  37. * @var array|object
  38. */
  39. protected $data;
  40. /**
  41. * @param array|object $data the object or array that should be transformed
  42. * @param int $statusCode the Http status code, defaults to 200
  43. * @param array $headers additional key value based headers
  44. * @since 8.0.0
  45. */
  46. public function __construct($data=array(), $statusCode=Http::STATUS_OK,
  47. array $headers=array()) {
  48. $this->data = $data;
  49. $this->setStatus($statusCode);
  50. $this->setHeaders(array_merge($this->getHeaders(), $headers));
  51. }
  52. /**
  53. * Sets values in the data json array
  54. * @param array|object $data an array or object which will be transformed
  55. * @return DataResponse Reference to this object
  56. * @since 8.0.0
  57. */
  58. public function setData($data){
  59. $this->data = $data;
  60. return $this;
  61. }
  62. /**
  63. * Used to get the set parameters
  64. * @return array the data
  65. * @since 8.0.0
  66. */
  67. public function getData(){
  68. return $this->data;
  69. }
  70. }