1
0

DataDisplayResponse.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCP\AppFramework\Http;
  8. use OCP\AppFramework\Http;
  9. /**
  10. * Class DataDisplayResponse
  11. *
  12. * @since 8.1.0
  13. * @template S of int
  14. * @template H of array<string, mixed>
  15. * @template-extends Response<int, array<string, mixed>>
  16. */
  17. class DataDisplayResponse extends Response {
  18. /**
  19. * response data
  20. * @var string
  21. */
  22. protected $data;
  23. /**
  24. * @param string $data the data to display
  25. * @param S $statusCode the Http status code, defaults to 200
  26. * @param H $headers additional key value based headers
  27. * @since 8.1.0
  28. */
  29. public function __construct(string $data = '', int $statusCode = Http::STATUS_OK, array $headers = []) {
  30. parent::__construct($statusCode, $headers);
  31. $this->data = $data;
  32. $this->addHeader('Content-Disposition', 'inline; filename=""');
  33. }
  34. /**
  35. * Outputs data. No processing is done.
  36. * @return string
  37. * @since 8.1.0
  38. */
  39. public function render() {
  40. return $this->data;
  41. }
  42. /**
  43. * Sets values in the data
  44. * @param string $data the data to display
  45. * @return DataDisplayResponse Reference to this object
  46. * @since 8.1.0
  47. */
  48. public function setData($data) {
  49. $this->data = $data;
  50. return $this;
  51. }
  52. /**
  53. * Used to get the set parameters
  54. * @return string the data
  55. * @since 8.1.0
  56. */
  57. public function getData() {
  58. return $this->data;
  59. }
  60. }