request)) { throw new \LogicException("Request not set, the controller has not been invoked"); } return $this->request; } /** * Get response. set for controller * * @return ResponseInterface */ public function getResponse() { if (!isset($this->response)) { throw new \LogicException("Response not set, the controller has not been invoked"); } return $this->response; } /** * Get response. set for controller * * @param ResponseInterface $response */ public function setResponse(ResponseInterface $response) { $this->response = $response; } /** * Run the controller * * @return ResponseInterface */ abstract public function run(); /** * Run the controller as function * * @param ServerRequestInterface $request * @param ResponseInterface $response * @return ResponseInterface */ public function __invoke(ServerRequestInterface $request, ResponseInterface $response) { $this->request = $request; $this->response = $response; if (method_exists($this, 'useSession')) { $this->useSession(); } $this->run(); return $this->getResponse(); } }