/** * Handles the requests * * @param \React\Http\Request $request Request to handle * @param \React\Http\Response $response Prebuilt response object */ public function serverCallback($request, $response) { // Currently the PHP server is readonly if (!in_array(strtoupper($request->getMethod()), array('GET', 'HEAD'))) { $response->writeHead(405, array('Content-type' => 'text/plain')); $response->end('Writing is currently not supported'); return; } $requestPath = $this->sanitizePath($request->getPath()); $requestPath = substr($requestPath, 5); /** @var Request $restRequest */ $restRequest = new Request($request->getMethod(), $requestPath, $request->getQuery(), $request->getHeaders()); $path = '' . strtok($requestPath, '/'); $restRequest->initWithPathAndOriginalPath($path, $path); $this->setServerGlobals($request); /** @var \Bullet\Response $restResponse */ $restResponse = NULL; ob_start(); $this->dispatcher->dispatch($restRequest, $restResponse); $responseString = ob_get_clean(); if (!$restResponse) { $response->writeHead(200); $response->end($responseString); } else { $response->writeHead($restResponse->status(), $this->getHeadersFromResponse($restResponse)); $response->end($restResponse->content()); } unset($restRequest); unset($restResponse); }
/** * Handles the requests * * @param \React\Http\Request $request Request to handle * @param \React\Http\Response $response Prebuilt response object */ public function serverCallback($request, $response) { // Currently the PHP server is readonly if (!in_array(strtoupper($request->getMethod()), array('GET', 'HEAD'))) { $response->writeHead(405, array('Content-type' => 'text/plain')); $response->end('Writing is currently not supported'); return; } /** @var \Cundd\Rest\Request $restRequest */ $restRequest = new \Cundd\Rest\Request($request->getMethod(), $this->sanitizePath($request->getPath())); $this->setServerGlobals($request); /** @var \Bullet\Response $restResponse */ $restResponse = NULL; ob_start(); $this->app->dispatch($restRequest, $restResponse); ob_end_clean(); $response->writeHead($restResponse->status(), $this->getHeadersFromResponse($restResponse)); $response->end($restResponse->content()); unset($restRequest); unset($restResponse); }