DataDisplayResponse.php 2.0 KB

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