Пример #1
0
 public function run()
 {
     $this->initDatabase();
     $this->initRoutes();
     $loader = new \Twig_Loader_Filesystem(array(SITE_PATH . '/src/twigs/', SITE_PATH . '/vendor/johsbk/penguin/src/twigs/'));
     $twig = new \Twig_Environment($loader, array('cache' => SITE_PATH . '/cache/', 'debug' => true));
     Registry::getInstance()->twig = $twig;
     try {
         $route = isset($_GET['rt']) ? $_GET['rt'] : '';
         unset($_GET['rt']);
         session_start();
         $twig->addGlobal('URL_PATH', URL_PATH);
         $twig->addGlobal('MEDIA_PATH', MEDIA_PATH);
         $twig->addGlobal('request', $_REQUEST);
         $twig->addGlobal('loggedin', Auth::isLoggedin());
         $twig->addGlobal('current_user', Auth::$profile);
         if ($this->preparetwig) {
             $fn = $this->preparetwig;
             $fn($twig);
         }
         $reg = \penguin\mvc\Registry::getInstance();
         $reg->project = $this;
         $reg->template = new \penguin\mvc\Template();
         $reg->router = new \penguin\mvc\Router();
         $reg->starttime = $reg->endtime = microtime(true);
         ob_start();
         if (!isset(\penguin\mvc\SessionRegistry::getInstance()->locale)) {
             $this->loadLocale();
         }
         $twig->addGlobal('locale', \penguin\mvc\SessionRegistry::getInstance()->locale);
         $reg->router->loader($route);
         ob_end_flush();
     } catch (\Exception $e) {
         $this->handleException($route, $e);
     }
     \penguin\db\DB::logout();
 }