Sapi.php 2.0 KB

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