function handleRequest(RequestInterface $request) { $sabreRequest = \Sabre\HTTP\Sapi::createFromServerArray($request->getParams()); $sabreRequest->setBody($request->getStdin()); if ($sabreRequest->getMethod() === 'POST' && $sabreRequest->getHeader('Content-Type') === 'application/x-www-form-urlencoded') { parse_str($sabreRequest->getBodyAsString(), $postData); $sabreRequest->setPostData($postData); } $sabreResponse = new \Sabre\HTTP\Response(); $this->server->httpRequest = $sabreRequest; $this->server->httpResponse = $sabreResponse; $this->server->exec(); $body = $sabreResponse->getBody(); if (is_scalar($body) || is_null($body)) { $newBody = fopen('php://memory', 'r+'); fwrite($newBody, (string) $body); rewind($newBody); $body = $newBody; } // Turning sabre into psr-7 response. $psr7Response = new ZendResponse($body, $sabreResponse->getStatus(), $sabreResponse->getHeaders()); return $psr7Response; }