You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.1 KiB

10 years ago
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bernhard Posselt <dev@bernhard-posselt.com>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Stefan Weil <sw@weilnetz.de>
  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 OC\AppFramework\Http;
  25. use OCP\AppFramework\Http\IOutput;
  26. /**
  27. * Very thin wrapper class to make output testable
  28. */
  29. class Output implements IOutput {
  30. /** @var string */
  31. private $webRoot;
  32. /**
  33. * @param $webRoot
  34. */
  35. public function __construct($webRoot) {
  36. $this->webRoot = $webRoot;
  37. }
  38. /**
  39. * @param string $out
  40. */
  41. public function setOutput($out) {
  42. print($out);
  43. }
  44. /**
  45. * @param string $path
  46. *
  47. * @return bool false if an error occurred
  48. */
  49. public function setReadfile($path) {
  50. return @readfile($path);
  51. }
  52. /**
  53. * @param string $header
  54. */
  55. public function setHeader($header) {
  56. header($header);
  57. }
  58. /**
  59. * @param int $code sets the http status code
  60. */
  61. public function setHttpResponseCode($code) {
  62. http_response_code($code);
  63. }
  64. /**
  65. * @return int returns the current http response code
  66. */
  67. public function getHttpResponseCode() {
  68. return http_response_code();
  69. }
  70. /**
  71. * @param string $name
  72. * @param string $value
  73. * @param int $expire
  74. * @param string $path
  75. * @param string $domain
  76. * @param bool $secure
  77. * @param bool $httpOnly
  78. */
  79. public function setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly) {
  80. $path = $this->webRoot ? : '/';
  81. setcookie($name, $value, $expire, $path, $domain, $secure, $httpOnly);
  82. }
  83. }