/** * 启动程序 * @return [type] [description] */ public function start() { $this->init(); //数据库初使化 DB::init(); //路由初使化 Router::init(); //TODO:: 还需要支持自定义的路由 if (file_exists(APP_PATH . 'config/Router.php')) { } //调用控制器 $controllerFile = APP_PATH . MODULE . 'controller/' . CONTROLLER . CLASS_EXT; if (file_exists($controllerFile)) { include_once $controllerFile; $controller = MODULE ? MODULE : "Controller" . '\\' . CONTROLLER; $action = ACTION; $obj = new $controller(); if (method_exists($obj, $action)) { $obj->{$action}(); } else { throw new \Exception("非法操作: " . ACTION); } } else { throw new \Exception("无法加载控制器: " . CONTROLLER); } }
public function run($config) { $this->extr($config); //раскручиваем конфиг Router::init()->run(); //вызываем роутер }
public function run() { error_reporting(Config::get('app.debug') ? E_ALL : 0); //Set Date Timezone date_default_timezone_set(Config::get('app.timezone')); //Set Cache Ctatus ini_set('opcache.revalidate_freq', Config::get('app.cache') ? '0' : '1'); try { static::stripTraillingSlash(); $this->session->start(); Router::init(); $routerParams = Router::getParams(); $this->handleMiddlewares($routerParams); $controllerParams = []; foreach ($routerParams as $paramName => $paramValue) { if (substr($paramName, 0, 1) != '_') { $controllerParams[$paramName] = $paramValue; } } if (isset($routerParams['_params']) && is_array($routerParams['_params'])) { foreach ($routerParams['_params'] as $paramName => $paramValue) { $controllerParams[$paramName] = $paramValue; } } $controllerFullName = '\\App\\Controllers\\' . $routerParams['_controller']; try { return $this->di->call($controllerFullName . '::' . $routerParams['_method'], $controllerParams); } catch (Exception $e) { new ExceptionHandler($e); } } catch (Exception $e) { new ExceptionHandler($e); } return true; }
{ static $init = false; if (!$init) { self::includeRoutes(); $init = true; } return $init; } /** * Return router collection. * * @return RouteCollection */ public function getCollection() { return $this->routeColletion; } /** * @param $params * @param $closure */ public function group($params, $closure) { $oldMiddlewares = $this->middlewares; $this->middlewares = array_merge($this->middlewares, isset($params['middleware']) ? $params['middleware'] : []); $closure($this); $this->middlewares = $oldMiddlewares; } } Router::init();