1
0

DataDisplayResponse.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. parent::__construct();
  47. $this->data = $data;
  48. $this->setStatus($statusCode);
  49. $this->setHeaders(array_merge($this->getHeaders(), $headers));
  50. $this->addHeader('Content-Disposition', 'inline; filename=""');
  51. }
  52. /**
  53. * Outputs data. No processing is done.
  54. * @return string
  55. * @since 8.1.0
  56. */
  57. public function render() {
  58. return $this->data;
  59. }
  60. /**
  61. * Sets values in the data
  62. * @param string $data the data to display
  63. * @return DataDisplayResponse Reference to this object
  64. * @since 8.1.0
  65. */
  66. public function setData($data){
  67. $this->data = $data;
  68. return $this;
  69. }
  70. /**
  71. * Used to get the set parameters
  72. * @return string the data
  73. * @since 8.1.0
  74. */
  75. public function getData(){
  76. return $this->data;
  77. }
  78. }