Sapi.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\DAV\Tests\unit\Connector\Sabre\RequestTest;
  8. use Sabre\HTTP\Request;
  9. use Sabre\HTTP\Response;
  10. class Sapi {
  11. /**
  12. * @var \Sabre\HTTP\Response
  13. */
  14. private $response;
  15. /**
  16. * This static method will create a new Request object, based on the
  17. * current PHP request.
  18. *
  19. * @return \Sabre\HTTP\Request
  20. */
  21. public function getRequest() {
  22. return $this->request;
  23. }
  24. public function __construct(
  25. private Request $request,
  26. ) {
  27. }
  28. /**
  29. * @param \Sabre\HTTP\Response $response
  30. * @return void
  31. */
  32. public function sendResponse(Response $response): void {
  33. // we need to copy the body since we close the source stream
  34. $copyStream = fopen('php://temp', 'r+');
  35. if (is_string($response->getBody())) {
  36. fwrite($copyStream, $response->getBody());
  37. } elseif (is_resource($response->getBody())) {
  38. stream_copy_to_stream($response->getBody(), $copyStream);
  39. }
  40. rewind($copyStream);
  41. $this->response = new Response($response->getStatus(), $response->getHeaders(), $copyStream);
  42. }
  43. /**
  44. * @return \Sabre\HTTP\Response
  45. */
  46. public function getResponse() {
  47. return $this->response;
  48. }
  49. }