DataDisplayResponse.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Julius Härtl <jus@bitgrid.net>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCP\AppFramework\Http;
  26. use OCP\AppFramework\Http;
  27. /**
  28. * Class DataDisplayResponse
  29. *
  30. * @since 8.1.0
  31. */
  32. class DataDisplayResponse extends Response {
  33. /**
  34. * response data
  35. * @var string
  36. */
  37. protected $data;
  38. /**
  39. * @param string $data the data to display
  40. * @param int $statusCode the Http status code, defaults to 200
  41. * @param array $headers additional key value based headers
  42. * @since 8.1.0
  43. */
  44. public function __construct($data = '', $statusCode = Http::STATUS_OK,
  45. $headers = []) {
  46. parent::__construct();
  47. $this->data = $data;
  48. $this->setStatus($statusCode);
  49. $this->setHeaders(array_merge($this->getHeaders(), $headers));
  50. $this->addHeader('Content-Disposition', 'inline; filename=""');
  51. }
  52. /**
  53. * Outputs data. No processing is done.
  54. * @return string
  55. * @since 8.1.0
  56. */
  57. public function render() {
  58. return $this->data;
  59. }
  60. /**
  61. * Sets values in the data
  62. * @param string $data the data to display
  63. * @return DataDisplayResponse Reference to this object
  64. * @since 8.1.0
  65. */
  66. public function setData($data) {
  67. $this->data = $data;
  68. return $this;
  69. }
  70. /**
  71. * Used to get the set parameters
  72. * @return string the data
  73. * @since 8.1.0
  74. */
  75. public function getData() {
  76. return $this->data;
  77. }
  78. }