Exemplo n.º 1
0
 /**
  * 解析router别名配置
  *
  * @param array $request
  * @throws CoreException
  * @internal param $router
  */
 private function initRouter($request)
 {
     $_controller = array_shift($request);
     $this->config->set('url', array('ori_controller' => $_controller));
     $combine_alias_key = '';
     if (isset($request[0])) {
         $combine_alias_key = $_controller . ':' . $request[0];
     }
     $controller_alias = '';
     $router_config = $this->config->get('router');
     if (isset($router_config[$combine_alias_key])) {
         array_shift($request);
         $controller_alias = $router_config[$combine_alias_key];
     } elseif (isset($router_config[$_controller])) {
         $controller_alias = $router_config[$_controller];
     }
     if (!empty($controller_alias)) {
         if (false !== strpos($controller_alias, ':')) {
             list($_controller, $_action) = explode(':', $controller_alias);
         } else {
             $_controller = $controller_alias;
         }
     }
     if (!isset($_action)) {
         if (isset($request[0])) {
             $_action = array_shift($request);
             $this->config->set('url', array('ori_action' => $_action));
         } else {
             $_action = self::$default_action;
         }
     }
     $this->setController($_controller);
     $this->setAction($_action);
     $this->setParams($request);
 }
Exemplo n.º 2
0
 /**
  * 初始化App配置
  * @param string $app_name
  * @param array $runtime_config
  * @return $this
  * @throws \Cross\Exception\FrontException
  */
 private static function initConfig($app_name, $runtime_config)
 {
     $config = Config::load(APP_PATH_DIR . $app_name . DIRECTORY_SEPARATOR . 'init.php')->parse($runtime_config);
     $request = Request::getInstance();
     $host = $request->getHostInfo();
     $index_name = $request->getIndexName();
     $request_url = $request->getBaseUrl();
     $base_script_path = $request->getScriptFilePath();
     //设置app名称和路径
     $config->set('app', array('name' => $app_name, 'path' => APP_PATH_DIR . $app_name . DIRECTORY_SEPARATOR));
     //静态文件url和绝对路径
     $config->set('static', array('url' => $host . $request_url . '/static/', 'path' => $base_script_path . DIRECTORY_SEPARATOR . 'static' . DIRECTORY_SEPARATOR));
     //url相关设置
     $config->set('url', array('index' => $index_name, 'host' => $host, 'request' => $request_url, 'full_request' => $host . $request_url));
     return $config;
 }