response = $response; $this->request = $request; } /** * Get PSR response * @return ResponseInterface */ public function response(): ResponseInterface { if (!($this->response instanceof ResponseInterface)) { $stream = new Stream(Stream::TEMP); $this->response = new Response($stream); } return $this->response; } /** * Get PSR request * @return ServerRequestInterface */ public function request(): ServerRequestInterface { if (!($this->request instanceof ServerRequestInterface)) { $env = new Environment(); $this->request = new ServerRequest(new Uri($env->getUriParts()), $env); } return $this->request; } /** * Inherit or create new stream instance from PSR-7 * @param mixed|null $stream * @param string $permission * @return StreamInterface */ public function stream(mixed $stream = null, string $permission = "r+"): StreamInterface { if ($stream !== null) { return new Stream($stream, $permission); } return $this->response()->getBody(); } }