DataDisplayResponse.php 2.2 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. * @author Kate Döen <kate.doeen@nextcloud.com>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OCP\AppFramework\Http;
  27. use OCP\AppFramework\Http;
  28. /**
  29. * Class DataDisplayResponse
  30. *
  31. * @since 8.1.0
  32. * @template S of int
  33. * @template H of array<string, mixed>
  34. * @template-extends Response<int, array<string, mixed>>
  35. */
  36. class DataDisplayResponse extends Response {
  37. /**
  38. * response data
  39. * @var string
  40. */
  41. protected $data;
  42. /**
  43. * @param string $data the data to display
  44. * @param S $statusCode the Http status code, defaults to 200
  45. * @param H $headers additional key value based headers
  46. * @since 8.1.0
  47. */
  48. public function __construct(string $data = '', int $statusCode = Http::STATUS_OK, array $headers = []) {
  49. parent::__construct($statusCode, $headers);
  50. $this->data = $data;
  51. $this->addHeader('Content-Disposition', 'inline; filename=""');
  52. }
  53. /**
  54. * Outputs data. No processing is done.
  55. * @return string
  56. * @since 8.1.0
  57. */
  58. public function render() {
  59. return $this->data;
  60. }
  61. /**
  62. * Sets values in the data
  63. * @param string $data the data to display
  64. * @return DataDisplayResponse Reference to this object
  65. * @since 8.1.0
  66. */
  67. public function setData($data) {
  68. $this->data = $data;
  69. return $this;
  70. }
  71. /**
  72. * Used to get the set parameters
  73. * @return string the data
  74. * @since 8.1.0
  75. */
  76. public function getData() {
  77. return $this->data;
  78. }
  79. }