本文整理匯總了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();