core = $core; $this->setRequest($request); $this->setResponse($response); $this->setContainer($container); } /** * @return Core */ protected function getCore() { return $this->core; } /** * @return Response|void */ public function beforeHandle() { } /** * @return Response */ public function handle() { return $this->getResponse(); } /** * @return Response */ public function getResponse() { return $this->response; } /** * @param Response $response */ public function setResponse($response) { $this->response = $response; } /** * @return Request */ public function getRequest() { return $this->request; } /** * @param Request $request */ public function setRequest($request) { $this->request = $request; } /** * @param string $template * @param array $context * @return Response */ public function render($template, $context = []) { $core = $this->getCore(); $twig = $core->getTwig(); /** @var TwigVars */ $twigVars = $this->get('twig-vars'); return $this->getResponse()->write($twig->render($template, $twigVars->getVars() + $context)); } /** * @param string $name * @return string */ public function post($name) { $request = $this->getRequest(); return $request->getParsedBodyParam($name); } public function redirect($url) { $response = $this->getResponse(); return $response->withRedirect($url); } /** * @param array $array * @return Response */ public function json($array) { return $this->getResponse() ->withHeader('Content-Type', 'application/json') ->write(json_encode($array)); } /** * @param string $name * @return string */ public function attr($name) { return $this->getRequest()->getAttribute($name); } }