本文整理汇总了PHP中core\Router::init方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::init方法的具体用法?PHP Router::init怎么用?PHP Router::init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core\Router
的用法示例。
在下文中一共展示了Router::init方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: start
/**
* 启动程序
* @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);
}
}
示例2: run
public function run($config)
{
$this->extr($config);
//раскручиваем конфиг
Router::init()->run();
//вызываем роутер
}
示例3: 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;
}
示例4: getCollection
{
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();