/** * @throws BadResponseTypeException * @throws Exception\RendererException */ public function run() { $router = Service::get('router'); $route = $router->parseRoute(); $renderer = Service::get('renderer'); $renderer->assign(array('user' => Service::get('security')->getUser(), 'flush' => Service::get('session')->getFlush())); require_once '../src/Blog/Controller/PostController.php'; try { $response = $this->processRoute(); if (empty($route)) { throw new HttpNotFoundException('Route not found'); } if (isset($route['security'])) { if (!Service::get('security')->isAuthenticated()) { throw new AuthRequiredException('Please. login first!'); } elseif (!Service::get('security')->isGranted($route['security'])) { throw new AccessDeniedException('Access denied!'); } } $controllerReflection = new \ReflectionClass($route['controller']); $action = $route['action'] . 'Action'; if ($controllerReflection->hasMethod($action)) { $controller = $controllerReflection->newInstance(); // var_dump($controller); die; $actionReflection = $controllerReflection->getMethod($action); $response = $actionReflection->invokeArgs($controller, $route['params']); } } catch (HttpNotFoundException $e) { echo $e->getMessage(); } catch (AuthRequiredException $e) { $url = Service::get('router')->buildRoute(Service::get('security')->getLoginRoute()); $response = new ResponseRedirect($url, null, 'Please, login first!'); // var_dump(Service::get('request')->getUri()); die; $response->setReturnUrl(Service::get('request')->getUri()); } catch (AccessDeniedException $e) { echo $e->getMessage(); } catch (\Exception $e) { $renderer = new Renderer(Service::get('config')->error_500); $renderer->assign(array('message' => $e->getMessage(), 'code' => $e->getCode())); $response = new Response($renderer->render(), $e->getCode(), 'Internal Server Error'); echo $e->getMessage(); } $response->send(); }