Sapi.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Robin Appelman <robin@icewind.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 OCA\DAV\Tests\unit\Connector\Sabre\RequestTest;
  24. use Sabre\HTTP\Request;
  25. use Sabre\HTTP\Response;
  26. class Sapi {
  27. /**
  28. * @var \Sabre\HTTP\Request
  29. */
  30. private $request;
  31. /**
  32. * @var \Sabre\HTTP\Response
  33. */
  34. private $response;
  35. /**
  36. * This static method will create a new Request object, based on the
  37. * current PHP request.
  38. *
  39. * @return \Sabre\HTTP\Request
  40. */
  41. public function getRequest() {
  42. return $this->request;
  43. }
  44. public function __construct(Request $request) {
  45. $this->request = $request;
  46. }
  47. /**
  48. * @param \Sabre\HTTP\Response $response
  49. * @return void
  50. */
  51. public function sendResponse(Response $response) {
  52. // we need to copy the body since we close the source stream
  53. $copyStream = fopen('php://temp', 'r+');
  54. if (is_string($response->getBody())) {
  55. fwrite($copyStream, $response->getBody());
  56. } else if (is_resource($response->getBody())) {
  57. stream_copy_to_stream($response->getBody(), $copyStream);
  58. }
  59. rewind($copyStream);
  60. $this->response = new Response($response->getStatus(), $response->getHeaders(), $copyStream);
  61. }
  62. /**
  63. * @return \Sabre\HTTP\Response
  64. */
  65. public function getResponse() {
  66. return $this->response;
  67. }
  68. }