DataDownloadResponse.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Georg Ehrke <oc.list@georgehrke.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. * @author Kate Döen <kate.doeen@nextcloud.com>
  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 DataDownloadResponse
  29. *
  30. * @since 8.0.0
  31. * @template S of int
  32. * @template C of string
  33. * @template H of array<string, mixed>
  34. * @template-extends DownloadResponse<int, string, array<string, mixed>>
  35. */
  36. class DataDownloadResponse extends DownloadResponse {
  37. /**
  38. * @var string
  39. */
  40. private $data;
  41. /**
  42. * Creates a response that prompts the user to download the text
  43. * @param string $data text to be downloaded
  44. * @param string $filename the name that the downloaded file should have
  45. * @param C $contentType the mimetype that the downloaded file should have
  46. * @param S $status
  47. * @param H $headers
  48. * @since 8.0.0
  49. */
  50. public function __construct(string $data, string $filename, string $contentType, int $status = Http::STATUS_OK, array $headers = []) {
  51. $this->data = $data;
  52. parent::__construct($filename, $contentType, $status, $headers);
  53. }
  54. /**
  55. * @param string $data
  56. * @since 8.0.0
  57. */
  58. public function setData($data) {
  59. $this->data = $data;
  60. }
  61. /**
  62. * @return string
  63. * @since 8.0.0
  64. */
  65. public function render() {
  66. return $this->data;
  67. }
  68. }