/**
  * Returns flush messages
  *
  * @access public
  *
  * @return array
  */
 public function getMessages()
 {
     $flush = array();
     if ($this->session->has('flush')) {
         $flush = $this->session->get('flush');
         $this->session->unsetParam('flush');
     }
     return $flush;
 }
 /**
  * Checks authentication
  *
  * @access public
  *
  * @return bool
  * @throws SecurityException
  */
 public function isAuthenticated()
 {
     if (!is_null($user = $this->session->get('user'))) {
         if (!$user instanceof UserInterface) {
             throw new SecurityException("Your \"user class\" must to be instance of\n                    Framework\\Security\\Model\\UserInterface");
         }
         $fields = $user->getFieldsNames();
         foreach ($fields as $field) {
             if (is_null($user->{$field})) {
                 return false;
             }
         }
         return true;
     }
     return false;
 }
 /**
  * Application constructor
  *
  * @access public
  *
  * @param $config
  */
 public function __construct($config)
 {
     try {
         Service::setSimple('config', $this->config = (require_once $config));
         Service::set('request', 'Framework\\Request\\Request');
         Service::setSingleton('router', $this->router = new Router());
         Service::setSingleton('session', Sessions::getInstance());
         Service::setSingleton('dataBase', DataBase::getInstance());
         Service::set('security', 'Framework\\Security\\Security');
         Service::setSingleton('flushMessenger', 'Framework\\FlushMessenger\\FlushMessenger');
         Service::set('app', $this);
     } catch (ServiceException $e) {
     } catch (\Exception $e) {
     } finally {
         if (isset($e)) {
             $code = isset($code) ? $code : 500;
             $errorMessage = isset($errorMessage) ? $errorMessage : 'Sorry for the inconvenience. We are working
             to resolve this issue. Thank you for your patience.';
             $responce = MainException::handleForUser($e, array('code' => $code, 'message' => $errorMessage));
             $responce->send();
         }
     }
 }