public function handle(Request $request, array $args) : \Generator { $article = $this->app->getArticleStore()->getBySlug(substr($request->getUri()->getPath(), 1)); $html = $this->app->getRenderer()->render('article', ['article' => $article]); $sink = new MemorySink(); yield from $sink->end($html); return new BasicResponse(200, ['Content-Type' => 'text/html', 'Content-Length' => $sink->getLength()], $sink); }
public function onRequest(Request $request, Socket $socket) { $path = $request->getUri()->getPath(); if ($path == "/") { return yield from $this->onHttp($request, $socket); } if ($path == "/socket") { return yield from $this->onSocket($request, $socket); } return yield from $this->onError(404, $socket); }