Output.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * @author Bernhard Posselt <dev@bernhard-posselt.com>
  4. * @author Lukas Reschke <lukas@owncloud.com>
  5. *
  6. * @copyright Copyright (c) 2016, ownCloud, Inc.
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OC\AppFramework\Http;
  23. use OCP\AppFramework\Http\IOutput;
  24. /**
  25. * Very thin wrapper class to make output testable
  26. */
  27. class Output implements IOutput {
  28. /** @var string */
  29. private $webRoot;
  30. /**
  31. * @param $webRoot
  32. */
  33. public function __construct($webRoot) {
  34. $this->webRoot = $webRoot;
  35. }
  36. /**
  37. * @param string $out
  38. */
  39. public function setOutput($out) {
  40. print($out);
  41. }
  42. /**
  43. * @param string $path
  44. *
  45. * @return bool false if an error occurred
  46. */
  47. public function setReadfile($path) {
  48. return @readfile($path);
  49. }
  50. /**
  51. * @param string $header
  52. */
  53. public function setHeader($header) {
  54. header($header);
  55. }
  56. /**
  57. * @param int $code sets the http status code
  58. */
  59. public function setHttpResponseCode($code) {
  60. http_response_code($code);
  61. }
  62. /**
  63. * @return int returns the current http response code
  64. */
  65. public function getHttpResponseCode() {
  66. return http_response_code();
  67. }
  68. /**
  69. * @param string $name
  70. * @param string $value
  71. * @param int $expire
  72. * @param string $path
  73. * @param string $domain
  74. * @param bool $secure
  75. * @param bool $httpOnly
  76. */
  77. public function setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly) {
  78. $path = $this->webRoot ? : '/';
  79. setcookie($name, $value, $expire, $path, $domain, $secure, $httpOnly);
  80. }
  81. }