2015-08-07 10:04:27 -04:00
|
|
|
<?php
|
2024-05-28 06:34:11 -04:00
|
|
|
|
2015-08-07 10:04:27 -04:00
|
|
|
/**
|
2024-05-28 06:34:11 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-08-07 10:04:27 -04:00
|
|
|
*/
|
2016-05-25 10:04:15 -04:00
|
|
|
namespace OCA\DAV\Tests\unit\Connector\Sabre\RequestTest;
|
2015-08-07 10:04:27 -04:00
|
|
|
|
|
|
|
|
use Sabre\HTTP\Request;
|
|
|
|
|
use Sabre\HTTP\Response;
|
|
|
|
|
|
|
|
|
|
class Sapi {
|
|
|
|
|
/**
|
|
|
|
|
* @var \Sabre\HTTP\Response
|
|
|
|
|
*/
|
|
|
|
|
private $response;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This static method will create a new Request object, based on the
|
|
|
|
|
* current PHP request.
|
|
|
|
|
*
|
|
|
|
|
* @return \Sabre\HTTP\Request
|
|
|
|
|
*/
|
|
|
|
|
public function getRequest() {
|
|
|
|
|
return $this->request;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-18 06:04:22 -04:00
|
|
|
public function __construct(
|
|
|
|
|
private Request $request,
|
|
|
|
|
) {
|
2015-08-07 10:04:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param \Sabre\HTTP\Response $response
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2023-01-20 02:38:43 -05:00
|
|
|
public function sendResponse(Response $response): void {
|
2015-09-14 09:34:28 -04:00
|
|
|
// we need to copy the body since we close the source stream
|
|
|
|
|
$copyStream = fopen('php://temp', 'r+');
|
|
|
|
|
if (is_string($response->getBody())) {
|
|
|
|
|
fwrite($copyStream, $response->getBody());
|
2020-04-10 04:35:09 -04:00
|
|
|
} elseif (is_resource($response->getBody())) {
|
2015-09-14 09:34:28 -04:00
|
|
|
stream_copy_to_stream($response->getBody(), $copyStream);
|
|
|
|
|
}
|
|
|
|
|
rewind($copyStream);
|
|
|
|
|
$this->response = new Response($response->getStatus(), $response->getHeaders(), $copyStream);
|
2015-08-07 10:04:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return \Sabre\HTTP\Response
|
|
|
|
|
*/
|
|
|
|
|
public function getResponse() {
|
|
|
|
|
return $this->response;
|
|
|
|
|
}
|
|
|
|
|
}
|