DataDisplayResponse.php 2.1 KB

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