withResponse(function (ResponseInterface $response) use ($obj, $options, $depth) { return $response->withHeader('Content-Type', 'application/json') ->withBody(stream_for(json_encode($obj, $options, $depth))); }); } public function redirect($to, $status = 302): void { $this->withResponse(function (ResponseInterface $response) use ($to, $status) { return $response->withStatus($status)->withHeader('Location', $to); }); } public function getSetCookies(): SetCookies { if ($this->setCookies === null) { $this->setCookies = SetCookies::fromResponse($this->getResponse()); } return $this->setCookies; } public function setCookie($name, $value) { $this->addCookie(SetCookie::create($name, $value)); } public function addCookie(SetCookie $cookie) { $this->setCookies = $this->setCookies->with($cookie); } public function renderResponse() { return $this->setCookies->renderIntoSetCookieHeader(parent::renderResponse()); } }