public function onRequest(Event $event)
 {
     $debug = $event->getApplication()->getServiceManager()->getServiceConfig('debug', false);
     error_reporting($debug ? 7 : 0);
     ini_set('display_errors', $debug ? 'On' : 'Off');
     $event->setDebug($debug);
 }
 public function onRoute(Event $event)
 {
     $serviceManager = $event->getApplication()->getServiceManager();
     $request = $serviceManager->getService('request');
     $router = $serviceManager->getService('router');
     $routeMatch = $router->match($request->getPathinfo());
     $event->setRouteMatch($routeMatch);
 }
 public function onRender(Event $event)
 {
     $serviceManager = $event->getApplication()->getServiceManager();
     $view = $serviceManager->getService('view');
     $viewModel = $event->getViewModel();
     $view->assign($viewModel->getVariables());
     return $view->fetch($viewModel->getTemplate());
 }
 public function onRender(Event $event)
 {
     $locale = $event->getApplication()->getServiceManager()->getService('locale');
     $viewModel = $event->getViewModel();
     $variables = $viewModel->getVariables();
     $variables = array_merge($variables, array('lang' => $locale->getLocale()));
     $viewModel->setVariables($variables);
     $event->setViewModel($viewModel);
 }
 public function onResponse(Event $event)
 {
     $response = $event->getResponse();
     $code = $response->getCode();
     if (false === $event->getDebug()) {
         if ($code == 404) {
             $response->setBody('Page not found.');
         }
         if ($code == 500) {
             $response->setBody('Internal error.');
         }
     }
     $response->send();
 }
 public function onDispatch(Event $event)
 {
     $routeMatch = $event->getRouteMatch();
     $controllerName = $routeMatch['controller'];
     $actionName = $routeMatch['action'];
     $class = 'Controller\\' . $controllerName . 'Controller';
     $action = $actionName . 'Action';
     if (!class_exists($class) || !method_exists($class, $action)) {
         throw new NotFound(sprintf("Controller or action '%s::%s' not found.", $class, $action));
     }
     $reflectionClass = new \ReflectionClass($class);
     if (!$reflectionClass->isSubclassOf('Frame\\Mvc\\Controller\\AbstractController')) {
         throw new \Exception(sprintf("Controller class '%s' must be instance of '%s'.", $class, 'Frame\\Mvc\\Controller\\AbstractController'));
     }
     $controller = new $class($event->getApplication());
     $callback = array($controller, $action);
     if (!is_callable($callback)) {
         throw new \Exception(sprintf("Controller's action '%s::%s' must be public.", $class, $action));
     }
     return call_user_func($callback);
 }