Example #1
0
 public static function dispatch()
 {
     lib('lang')->locale('web');
     $controller = isAke(static::$route, 'controller', false);
     $action = isAke(static::$route, 'action', false);
     $file = APPLICATION_PATH . DS . 'front' . DS . 'controllers' . DS . $controller . '.php';
     $tpl = APPLICATION_PATH . DS . 'front' . DS . 'views' . DS . $controller . DS . $action . '.phtml';
     if (!File::exists($file)) {
         static::is404();
     }
     require_once $file;
     $class = 'Thin\\' . ucfirst($controller) . 'Controller';
     $i = new $class();
     if (File::exists($tpl)) {
         $i->view = new Container();
         if (static::$pjax) {
             $i->view->partial = function ($partial) {
                 return true;
             };
         } else {
             $i->view->partial = function ($partial) use($i) {
                 $tpl = APPLICATION_PATH . DS . 'front' . DS . 'views' . DS . 'partials' . DS . $partial . '.phtml';
                 if (File::exists($tpl)) {
                     $code = View::lng(File::read($tpl));
                     $code = str_replace('$this', '$i->view', $code);
                     eval('; ?>' . $code . '<?php ;');
                 }
             };
         }
     }
     $methods = get_class_methods($i);
     $call = strtolower(static::$method) . ucfirst($action);
     if (!Arrays::in($call, $methods)) {
         static::is404();
     }
     if (Arrays::in('init', $methods)) {
         $i->init();
     }
     $i->{$call}();
     if (Arrays::in('after', $methods)) {
         $i->after();
     }
     if (File::exists($tpl)) {
         $code = View::lng(File::read($tpl));
         $code = str_replace('$this', '$i->view', $code);
         header("HTTP/1.0 200 OK");
         eval('; ?>' . $code . '<?php ;');
         exit;
     }
 }