DataDownloadResponse.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 DataDownloadResponse
  11. *
  12. * @since 8.0.0
  13. * @template S of int
  14. * @template C of string
  15. * @template H of array<string, mixed>
  16. * @template-extends DownloadResponse<int, string, array<string, mixed>>
  17. */
  18. class DataDownloadResponse extends DownloadResponse {
  19. /**
  20. * @var string
  21. */
  22. private $data;
  23. /**
  24. * Creates a response that prompts the user to download the text
  25. * @param string $data text to be downloaded
  26. * @param string $filename the name that the downloaded file should have
  27. * @param C $contentType the mimetype that the downloaded file should have
  28. * @param S $status
  29. * @param H $headers
  30. * @since 8.0.0
  31. */
  32. public function __construct(string $data, string $filename, string $contentType, int $status = Http::STATUS_OK, array $headers = []) {
  33. $this->data = $data;
  34. parent::__construct($filename, $contentType, $status, $headers);
  35. }
  36. /**
  37. * @param string $data
  38. * @since 8.0.0
  39. */
  40. public function setData($data) {
  41. $this->data = $data;
  42. }
  43. /**
  44. * @return string
  45. * @since 8.0.0
  46. */
  47. public function render() {
  48. return $this->data;
  49. }
  50. }