/** * 输出消息 * * @param $code * @param null $tpl * @throws \Cross\Exception\CoreException */ function notice($code, $tpl = null) { $code_text = Loader::read("::config/notice.config.php"); if (isset($code_text[$code])) { $this->text($code_text[$code], $tpl); } else { $this->text('未指明的错误识别码' . $code, $tpl); } }
/** * 初始化框架 * * @param string $app_name 要加载的app名称 * @param array $runtime_config 运行时指定的配置 */ private function __construct($app_name, $runtime_config) { Loader::init($app_name); $this->app_name = $app_name; $this->runtime_config = $runtime_config; $this->config = self::initConfig($app_name, $runtime_config); $this->action_container = new ClosureContainer(); $this->router = new Router($this->config); $this->app = new Application($app_name, $this); }
/** * 读取app配置文件 */ function testReadAppConfig() { $result = $this->getAppResponse('Main:getAppConfig'); $ori_file = Loader::read('::app/test/init.php'); $this->assertJsonStringEqualsJsonString($result, json_encode($ori_file['router'], true), 'read app/init.php error...'); }
/** * 生成连接 * * @param string $app_name * @param bool $check_app_name * @param null|string $controller * @param null|array $params * @param null|bool $sec * @return string * @throws CoreException */ private function makeUri($app_name, $check_app_name, $controller = null, $params = null, $sec = null) { $uri = ''; $enable_controller_cache = false; //在运行过程中,如果url的配置有变化,需要调用cleanLinkCache()来刷新缓存 if (!isset(self::$url_config_cache[$app_name])) { $this_app_name = $app_name; if ($check_app_name) { $this_app_name = $this->getAppName(); } if ($check_app_name && $app_name != $this_app_name) { $config = CrossArray::init(Loader::read(APP_PATH_DIR . $app_name . DIRECTORY_SEPARATOR . 'init.php')); $url_config = $config->get('url'); } else { $url_config = $this->config->get('url'); } self::$url_config_cache[$app_name] = $url_config; } else { $enable_controller_cache = true; $url_config = self::$url_config_cache[$app_name]; } $url_params = ''; $url_controller = $this->makeControllerUri($app_name, $enable_controller_cache, $controller, $url_config); if (!empty($params)) { $url_params = $this->makeParams($params, $url_config, $sec); } if (!empty($url_config['ext']) && !empty($url_controller)) { switch ($url_config['type']) { case 2: $uri .= $url_controller . $url_config['ext'] . $url_params; break; case 1: case 3: case 4: case 5: $uri .= $url_controller . $url_params . $url_config['ext']; break; } } else { $uri .= $url_controller . $url_params; } return $uri; }
/** * 扫描控制器文件 * * @param bool $hashMap * @return array */ private function scanControllers($hashMap = false) { $controller_file = Loader::getFilePath('app::controllers'); $nav_data = array(); foreach (glob(rtrim($controller_file, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '*.php') as $f) { $fi = pathinfo($f); $class_name = $fi['filename']; $ori_nav_data = array('name' => lcfirst($class_name), 'link' => lcfirst($class_name), 'status' => 1); if ($hashMap) { $nav_data[$ori_nav_data['link']] = $ori_nav_data; } else { $nav_data[] = $ori_nav_data; } } return $nav_data; }
/** * @see Loader::parseFileRealPath * @param $file * @return mixed */ static function getFilePath($file) { return current(Loader::parseFileRealPath($file, '')); }
/** * 读取配置 * * @param string $res_file 配置文件绝对路径 * @throws CoreException */ private function __construct($res_file) { $this->config_data = Loader::read($res_file); }
/** * 根据错误码返回错误消息内容 * * @param int $code * @return string */ protected function getStatusMessage($code) { $code_config = Loader::read("::config/notice.config.php"); if (isset($code_config[$code])) { $message = $code_config[$code]; } else { $message = '未知错误 ' . $code; } return $message; }
/** * 读取并解析数据库配置 * * @return CrossArray */ protected function databaseConfig() { if (!self::$module_config) { $link_config_file = $this->getModuleConfigFile(); self::$module_config = CrossArray::init(Loader::read("::config/{$link_config_file}")); } return self::$module_config; }