Example #1
0
 private static function __loadControllerAction($controller, $fn = '')
 {
     is_callable($fn) && $fn();
     if (file_exists(self::$_env['controllersDir'] . '/' . $controller . '.php')) {
         include self::$_env['controllersDir'] . '/' . $controller . '.php';
     } elseif (file_exists(self::$_env['controllersDir'] . '/' . $controller . '/index.php')) {
         include self::$_env['controllersDir'] . '/' . $controller . '/index.php';
     } else {
         if ($_dir = strstr($controller, '/', true)) {
             if (file_exists(self::$_env['controllersDir'] . '/' . $_dir . '/index.php')) {
                 self::$_env['action'] = substr(self::$_env['request_uri'], strlen('/' . $_dir) + 1) ?: 'index';
                 self::$_env['controller'] = $_dir;
                 include self::$_env['controllersDir'] . '/' . $_dir . '/index.php';
             }
         } else {
             self::__exception(sprintf("Can't find controller file %s", $controller));
         }
     }
     Route::process();
     exit;
 }
Example #2
0
 public static function process($uri, $params = array())
 {
     $ctx = new Context();
     // if ($ctx->hook('Request.init')) return;
     $ctx->params = $params;
     $ctx->location = strtolower(substr($uri, strlen(conf('http.root'))));
     $ind = strpos($ctx->location, '?');
     if ($ind !== false) {
         $ctx->location = substr($ctx->location, 0, $ind);
     }
     if (substr($ctx->location, -1) == '/') {
         $ctx->location = substr($ctx->location, 0, -1);
     }
     // if ($ctx->hook('Request.process')) return;
     if (Route::process($ctx->location)) {
         return;
     }
     $ctx->resp->error_404();
 }