public function register() { $this->app->bind('oauth/factory/service', function ($app, $params = array()) { $factory = new ServiceFactory(); $factory->setHttpClient($client = new CurlClient()); $client->setCurlParameters((array) $params); return $factory; }); $this->app->bindShared('oauth/factory/extractor', function () { return new ExtractorFactory(); }); $this->app->bind('oauth_extractor', function ($app, $params = array()) { if (!is_array($params)) { $params = array($params); } if (!($service = head($params))) { throw new \InvalidArgumentException('No Service given.'); } $extractor_factory = $app->make('oauth/factory/extractor'); return $extractor_factory->get($service); }); \Route::register('/ccm/system/authentication/oauth2/{type}/{action}', function ($type, $action) { try { $type = \AuthenticationType::getByHandle($type); if ($type && is_object($type) && !$type->isError()) { /** @var GenericOauthTypeController $controller */ $controller = $type->getController(); if ($controller instanceof GenericOauthTypeController) { switch ($action) { case 'attempt_auth': return $controller->handle_authentication_attempt(); break; case 'callback': return $controller->handle_authentication_callback(); break; case 'attempt_attach': return $controller->handle_attach_attempt(); break; case 'attach_callback': return $controller->handle_attach_callback(); break; } } } } catch (\Exception $e) { \Log::addNotice('OAUTH ERROR: ' . $e->getMessage()); } }); }
/** * URL调度 * @access public * * @param $config * * @throws Exception */ public static function dispatch($config) { if (isset($_GET[$config['var_pathinfo']])) { // 判断URL里面是否有兼容模式参数 $_SERVER['PATH_INFO'] = $_GET[$config['var_pathinfo']]; unset($_GET[$config['var_pathinfo']]); } elseif (IS_CLI) { // CLI模式下 index.php module/controller/action/params/... $_SERVER['PATH_INFO'] = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : ''; } // 检测域名部署 if (!IS_CLI && !empty($config['url_domain_deploy'])) { if ($config['url_domain_rules']) { Route::domain($config['url_domain_rules']); } if ($match = Route::checkDomain()) { !defined('BIND_MODULE') && !empty($match[0]) && define('BIND_MODULE', $match[0]); !defined('BIND_CONTROLLER') && !empty($match[1]) && define('BIND_CONTROLLER', $match[1]); !defined('BIND_ACTION') && !empty($match[2]) && define('BIND_ACTION', $match[2]); } } // 监听path_info APP_HOOK && Hook::listen('path_info'); // 分析PATHINFO信息 if (!isset($_SERVER['PATH_INFO'])) { foreach ($config['pathinfo_fetch'] as $type) { if (!empty($_SERVER[$type])) { $_SERVER['PATH_INFO'] = 0 === strpos($_SERVER[$type], $_SERVER['SCRIPT_NAME']) ? substr($_SERVER[$type], strlen($_SERVER['SCRIPT_NAME'])) : $_SERVER[$type]; break; } } } // [模块,控制器,操作] $result = [null, null, null]; if (empty($_SERVER['PATH_INFO'])) { $_SERVER['PATH_INFO'] = ''; define('__INFO__', ''); define('__EXT__', ''); } else { $_SERVER['PATH_INFO'] = trim($_SERVER['PATH_INFO'], '/'); define('__INFO__', $_SERVER['PATH_INFO']); // URL后缀 define('__EXT__', strtolower(pathinfo($_SERVER['PATH_INFO'], PATHINFO_EXTENSION))); if (__INFO__) { if ($config['url_deny_suffix'] && preg_match('/\\.(' . $config['url_deny_suffix'] . ')$/i', __INFO__)) { throw new Exception('url suffix deny'); } // 去除URL后缀 $_SERVER['PATH_INFO'] = preg_replace($config['url_html_suffix'] ? '/\\.(' . trim($config['url_html_suffix'], '.') . ')$/i' : '/\\.' . __EXT__ . '$/i', '', __INFO__); $depr = $config['pathinfo_depr']; // 还原劫持后真实pathinfo $path_info = (defined('BIND_MODULE') ? BIND_MODULE . $depr : '') . (defined('BIND_CONTROLLER') ? BIND_CONTROLLER . $depr : '') . (defined('BIND_ACTION') ? BIND_ACTION . $depr : '') . $_SERVER['PATH_INFO']; // 路由检测 if (!empty($config['url_route_on'])) { // 开启路由 则检测路由配置 Route::register(!empty($config['route']) ? $config['route'] : null); $result = Route::check($path_info, $depr); if (false === $result) { // 路由无效 if ($config['url_route_must']) { throw new Exception('route not define '); } else { // 继续分析URL $result = Route::parseUrl($path_info, $depr); } } } else { // 分析URL地址 $result = Route::parseUrl($path_info, $depr); } } } if (APP_MULTI_MODULE) { $module = strtolower($result[0] ?: $config['default_module']); if ($maps = $config['url_module_map']) { if (isset($maps[$module])) { // 记录当前别名 define('MODULE_ALIAS', $module); // 获取实际的项目名 $module = $maps[MODULE_ALIAS]; } elseif (array_search($module, $maps)) { // 禁止访问原始项目 $module = ''; } } // 获取模块名称 define('MODULE_NAME', defined('BIND_MODULE') ? BIND_MODULE : strip_tags($module)); // 模块初始化 if (MODULE_NAME && !in_array(MODULE_NAME, $config['deny_module_list']) && is_dir(APP_PATH . MODULE_NAME)) { APP_HOOK && Hook::listen('app_begin'); define('MODULE_PATH', APP_PATH . MODULE_NAME . DS); define('VIEW_PATH', MODULE_PATH . VIEW_LAYER . DS); // 初始化模块 self::initModule(MODULE_NAME, $config); } else { throw new Exception('module [ ' . MODULE_NAME . ' ] not exists ', 10005); } } else { define('MODULE_NAME', ''); define('MODULE_PATH', APP_PATH); define('VIEW_PATH', MODULE_PATH . VIEW_LAYER . DS); } // 获取控制器名 $controller = strip_tags(strtolower($result[1] ?: Config::get('default_controller'))); define('CONTROLLER_NAME', defined('BIND_CONTROLLER') ? BIND_CONTROLLER : $controller); // 获取操作名 $action = strip_tags(strtolower($result[2] ?: Config::get('default_action'))); define('ACTION_NAME', defined('BIND_ACTION') ? BIND_ACTION : $action); }
/** * URL路由检测(根据PATH_INFO) * @access public * @param $config * @throws Exception */ public static function route($config) { // 解析PATH_INFO self::parsePathinfo($config); if (empty($_SERVER['PATH_INFO'])) { $_SERVER['PATH_INFO'] = ''; define('__INFO__', ''); define('__EXT__', ''); } else { $_SERVER['PATH_INFO'] = trim($_SERVER['PATH_INFO'], '/'); define('__INFO__', $_SERVER['PATH_INFO']); // URL后缀 define('__EXT__', strtolower(pathinfo($_SERVER['PATH_INFO'], PATHINFO_EXTENSION))); // 检测URL禁用后缀 if ($config['url_deny_suffix'] && preg_match('/\\.(' . $config['url_deny_suffix'] . ')$/i', __INFO__)) { throw new Exception('url suffix deny'); } // 去除正常的URL后缀 $_SERVER['PATH_INFO'] = preg_replace($config['url_html_suffix'] ? '/\\.(' . trim($config['url_html_suffix'], '.') . ')$/i' : '/\\.' . __EXT__ . '$/i', '', __INFO__); } $depr = $config['pathinfo_depr']; // 路由检测 if (!empty($config['url_route_on'])) { // 开启路由 if (!empty($config['route'])) { // 注册路由定义文件 Route::register($config['route']); } // 路由检测(根据路由定义返回不同的URL调度) $result = Route::check($_SERVER['PATH_INFO'], $depr, $config['url_domain_deploy']); if (false === $result) { // 路由无效 if ($config['url_route_must']) { throw new Exception('route not define '); } else { // 继续分析为模块/控制器/操作/参数...方式URL $result = Route::parseUrl($_SERVER['PATH_INFO'], $depr); } } } else { // 分析URL地址 采用 模块/控制器/操作/参数... $result = Route::parseUrl($_SERVER['PATH_INFO'], $depr); } // 注册调度机制 self::dispatch($result); }
/** * URL路由检测(根据PATH_INFO) * @access public * @param array $config * @throws Exception */ public static function route(array $config) { // 解析PATH_INFO self::parsePathinfo($config); if (empty($_SERVER['PATH_INFO'])) { $_SERVER['PATH_INFO'] = ''; define('__INFO__', ''); define('__EXT__', ''); } else { $_SERVER['PATH_INFO'] = trim($_SERVER['PATH_INFO'], '/'); define('__INFO__', $_SERVER['PATH_INFO']); // URL后缀 define('__EXT__', strtolower(pathinfo($_SERVER['PATH_INFO'], PATHINFO_EXTENSION))); // 检测URL禁用后缀 if ($config['url_deny_suffix'] && preg_match('/\\.(' . $config['url_deny_suffix'] . ')$/i', __INFO__)) { throw new Exception('url suffix deny'); } // 去除正常的URL后缀 $_SERVER['PATH_INFO'] = preg_replace($config['url_html_suffix'] ? '/\\.(' . trim($config['url_html_suffix'], '.') . ')$/i' : '/\\.' . __EXT__ . '$/i', '', __INFO__); } $depr = $config['pathinfo_depr']; $result = false; // 路由检测 if (APP_ROUTE_ON && !empty($config['url_route_on'])) { // 开启路由 if (!empty($config['route'])) { // 注册路由定义文件 Route::register($config['route']); } // 路由检测(根据路由定义返回不同的URL调度) $result = Route::check($_SERVER['PATH_INFO'], $depr, !IS_CLI ? $config['url_domain_deploy'] : false); if (APP_ROUTE_MUST && false === $result && $config['url_route_must']) { // 路由无效 throw new Exception('route not define '); } } if (false === $result) { // 路由无效默认分析为模块/控制器/操作/参数...方式URL $result = Route::parseUrl($_SERVER['PATH_INFO'], $depr); } //保证$_REQUEST正常取值 $_REQUEST = array_merge($_POST, $_GET, $_COOKIE); // 注册调度机制 self::dispatch($result); }
protected function registerLegacyRoutes() { \Route::register("/tools/blocks/{btHandle}/{tool}", '\\Concrete\\Core\\Legacy\\Controller\\ToolController::displayBlock', 'blockTool', array('tool' => '[A-Za-z0-9_/.]+')); \Route::register("/tools/{tool}", '\\Concrete\\Core\\Legacy\\Controller\\ToolController::display', ' tool', array('tool' => '[A-Za-z0-9_/.]+')); }
/** * URL路由检测(根据PATH_INFO) * @access public * @param $config * @throws Exception */ public static function route($config) { // 解析PATH_INFO self::parsePathinfo($config); // 检测域名部署 if (!IS_CLI && !empty($config['url_domain_deploy'])) { if ($config['url_domain_rules']) { // 注册域名路由规则 Route::domain($config['url_domain_rules']); } // 检测域名路由 if ($match = Route::checkDomain()) { !defined('BIND_MODULE') && !empty($match[0]) && define('BIND_MODULE', $match[0]); !defined('BIND_CONTROLLER') && !empty($match[1]) && define('BIND_CONTROLLER', $match[1]); !defined('BIND_ACTION') && !empty($match[2]) && define('BIND_ACTION', $match[2]); } } if (empty($_SERVER['PATH_INFO'])) { $_SERVER['PATH_INFO'] = ''; define('__INFO__', ''); define('__EXT__', ''); $result = ['type' => 'module', 'data' => [null, null, null]]; } else { $_SERVER['PATH_INFO'] = trim($_SERVER['PATH_INFO'], '/'); define('__INFO__', $_SERVER['PATH_INFO']); // URL后缀 define('__EXT__', strtolower(pathinfo($_SERVER['PATH_INFO'], PATHINFO_EXTENSION))); // 检测URL禁用后缀 if ($config['url_deny_suffix'] && preg_match('/\\.(' . $config['url_deny_suffix'] . ')$/i', __INFO__)) { throw new Exception('url suffix deny'); } // 去除正常的URL后缀 $_SERVER['PATH_INFO'] = preg_replace($config['url_html_suffix'] ? '/\\.(' . trim($config['url_html_suffix'], '.') . ')$/i' : '/\\.' . __EXT__ . '$/i', '', __INFO__); $depr = $config['pathinfo_depr']; // 还原劫持后真实pathinfo $path_info = (defined('BIND_MODULE') ? BIND_MODULE . $depr : '') . (defined('BIND_CONTROLLER') ? BIND_CONTROLLER . $depr : '') . (defined('BIND_ACTION') ? BIND_ACTION . $depr : '') . $_SERVER['PATH_INFO']; // 路由检测 if (!empty($config['url_route_on'])) { // 开启路由 注册路由定义文件 Route::register(!empty($config['route']) ? $config['route'] : null); // 路由检测(根据路由定义返回不同的URL调度) $result = Route::check($path_info, $depr); if (false === $result) { // 路由无效 if ($config['url_route_must']) { throw new Exception('route not define '); } else { // 继续分析为模块/控制器/操作/参数...方式URL $result = Route::parseUrl($path_info, $depr); } } } else { // 分析URL地址 采用 模块/控制器/操作/参数... $result = Route::parseUrl($path_info, $depr); } } return $result; }
<?php Route::register('default', 'home'); Route::register('home', 'home'); Route::register('news', 'news'); Route::register('search', 'search'); Route::register('login', 'login'); Route::register('register', 'register'); Route::register('account', 'account'); Route::register('channel', 'channel'); Route::register('watch', 'video'); Route::register('feed', 'feed'); Route::register('embed', 'embed'); Route::register('videos', 'video'); Route::register('playlists', 'playlist'); Route::register('channels', 'channel'); Route::register('posts', 'channel_post'); Route::register('comments', 'comment'); Route::register('messages', 'message'); Route::register('conversations', 'conversation'); Route::register('lives', 'live'); Route::register('password', 'password'); Route::register('pages', 'page'); Route::register('upload', 'upload'); Route::register('egg', 'egg'); Route::register('translation', 'translation'); Route::register('admin', 'admin'); Route::register('assistance', 'assist'); Route::register('faq', 'faq');