DataResponse.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. parent::__construct();
  49. $this->data = $data;
  50. $this->setStatus($statusCode);
  51. $this->setHeaders(array_merge($this->getHeaders(), $headers));
  52. }
  53. /**
  54. * Sets values in the data json array
  55. * @param array|object $data an array or object which will be transformed
  56. * @return DataResponse Reference to this object
  57. * @since 8.0.0
  58. */
  59. public function setData($data){
  60. $this->data = $data;
  61. return $this;
  62. }
  63. /**
  64. * Used to get the set parameters
  65. * @return array the data
  66. * @since 8.0.0
  67. */
  68. public function getData(){
  69. return $this->data;
  70. }
  71. }