public function getRedirectResponse() { if (!$this->isRedirect()) { throw new RuntimeException('This response does not support redirection.'); } $output = json_encode($this->getData()); return HttpResponse::create($output); }
/** * creates instance to test * * @param string $response content of response * @return HttpResponse */ private function createResponse(string $response) : HttpResponse { $file = vfsStream::newFile('response')->withContent($response)->at(vfsStream::setup()); return HttpResponse::create(new Stream(fopen($file->url(), 'rb+'))); }
/** * API PHP Exception handler. * This is a generic exception handler for PHP exceptions. This will catch any * uncaught exception, end API execution and return the result to the requestor * as an ErrorResult in the requested format. * * @param Exception $exception Exception * * @return void * @access private */ public function exceptionHandler($exception) { $time = date("Y-m-d H:i:s (T)"); $msg = $exception->getMessage() ?: elgg_echo('Exception:UnknownType'); $code = $exception->getCode() ?: 500; $error = "{$time}: {$msg} in file {$exception->getFile()} (line {$exception->getLine()})"; $this->log($error, "EXCEPTION"); $result = new ErrorResult($msg, $code, $exception); if ($this->router) { $this->router->send($result); } else { $output = elgg_view('graph/output', array('result' => $result)); if (elgg_get_viewtype() === 'default') { $layout = elgg_view_layout('one_column', array('content' => $output)); $output = elgg_view_page('', $layout); } HttpResponse::create($output, $result->getStatusCode())->send(); } }
/** * initializes a put request * * @param int $timeout optional connection timeout, defaults to 30 seconds * @param string|\stubbles\peer\http\HttpVersion $version optional http version, defaults to HTTP/1.1 * @return \stubbles\peer\http\HttpResponse * @since 2.0.0 */ public function delete(int $timeout = 30, $version = HttpVersion::HTTP_1_1) : HttpResponse { $socket = $this->httpUri->openSocket($timeout); $this->processHeader($socket, Http::DELETE, $version); return HttpResponse::create($socket); }