Пример #1
0
 static function make_i18n_cache($cache_key)
 {
     $langs = array();
     foreach (new RecursiveFileFilterIterator(APP_PATH, CURRENT_LANGUAGE . ".yml") as $item) {
         $app = lcfirst(basename(dirname(dirname($item))));
         $langs[$app] = parse_yml($item);
     }
     S($cache_key, $langs);
     return $langs;
 }
Пример #2
0
 public static function getSchemaByApp($app)
 {
     $cache_key = "schema/" . $app;
     $schemas = (array) S($cache_key);
     if (DEBUG || !$schemas) {
         $path = sprintf("%s%s/Schema", APP_PATH, ucfirst($app));
         foreach (new RecursiveFileFilterIterator($path, null, "yml") as $item) {
             $schemas = array_merge($schemas, (array) parse_yml($item));
         }
         // 需返回的数据表
         $tables = I("get.table") ? explode(".", I("get.table")) : array_keys($schemas);
         $schemas = Schema::parse($app, $schemas, $tables);
         S($cache_key, $schemas);
     }
     return $schemas;
 }
Пример #3
0
 public function __construct()
 {
     //支持方法
     if (!$this->allowMethod) {
         $this->allowMethod = explode(",", strtolower(SUPPORTED_METHOD));
     }
     //session token
     if (I('server.HTTP_TOKEN')) {
         session(array('id' => I("server.HTTP_TOKEN"), 'expire' => 1800));
         session('[start]');
         $this->user = I("session.user");
         $this->is_super_user = $this->user['is_super_user'];
         if (isset($_SESSION['user']) && (!get_current_company_id() || !get_current_user_id())) {
             return $this->login_required();
         }
     }
     tag('before_controller_construct');
     parent::__construct();
     // 当前请求 =》 auth_node
     $this->current_action_all = sprintf("%s.%s.%s.%s", lcfirst(MODULE_NAME), lcfirst(CONTROLLER_NAME), lcfirst(ACTION_NAME), $this->_method);
     //当前用户所属公司
     if ($this->user or true) {
         $this->company = D("Account/Company")->relation(true)->find(get_current_company_id());
     }
     //当前公司启用应用
     $this->activeApps = $this->baseApps;
     if ($this->company) {
         $this->activeApps = array_merge($this->activeApps, get_array_by_field($this->company['apps'], "alias"));
     }
     //启用应用
     AppService::active($this->activeApps, $this->baseApps);
     //当前模块前端别名
     $this->module_alias = __(sprintf('%s.%s', lcfirst(MODULE_NAME), lcfirst(CONTROLLER_NAME)));
     //导入非当前应用的插件及函数等信息
     foreach ($this->activeApps as $app) {
         $app = ucfirst($app);
         if ($app == APP_NAME or $app == "common") {
             continue;
         }
         // 插件
         if (is_file(APPLICATION_PATH . $app . '/Conf/tags.php')) {
             \Think\Hook::import(require APPLICATION_PATH . $app . '/Conf/tags.php');
         }
         // 函数
         if (is_file(APPLICATION_PATH . $app . '/Common/function.php')) {
             require_once APPLICATION_PATH . $app . '/Common/function.php';
         }
     }
     //基本运行配置
     $this->bootstrapConfigs = parse_yml(ENTRY_PATH . '/config.yaml');
     //当前接口版本
     if (I('server.HTTP_API_VERSION')) {
         define('API_VERSION', I('server.HTTP_API_VERSION'));
     } else {
         define('API_VERSION', false);
     }
     //当前语言
     $this->currentLanguage = $this->bootstrapConfigs["default_language"] ? $this->bootstrapConfigs["default_language"] : 'zh-cn';
     if (I("server.HTTP_CLIENT_LANGUAGE")) {
         $this->currentLanguage = I("server.HTTP_CLIENT_LANGUAGE");
     }
     if (I('get.lang')) {
         $this->currentLanguage = I('get.lang');
     }
     define('CURRENT_LANGUAGE', $this->currentLanguage);
     /*
      * 解析应用配置
      * * */
     $cachedAppConfig = S("configs/app/all");
     if (DEBUG or !$cachedAppConfig) {
         foreach (new RecursiveFileFilterIterator(APP_PATH, "config.yml") as $item) {
             $app = lcfirst(basename(dirname($item)));
             $this->appConfigs[$app] = parse_yml($item);
         }
         S("configs/app/all", $this->appConfigs);
     } else {
         if (!DEBUG && $cachedAppConfig) {
             $this->appConfigs = $cachedAppConfig;
         }
     }
     AppService::$allAppConfigs = $this->appConfigs;
     foreach ($this->appConfigs as $app => $config) {
         $this->bootstrapConfigs['auth_dont_need_login'] = array_merge_recursive($this->bootstrapConfigs['auth_dont_need_login'], (array) $config['auth_dont_need_login']);
         $this->bootstrapConfigs['auth_dont_need_check'] = array_merge_recursive($this->bootstrapConfigs['auth_dont_need_check'], (array) $config['auth_dont_need_check']);
     }
     // 当前表名
     if (!$this->model_name) {
         $this->model_name = ucfirst(CONTROLLER_NAME);
     }
     // 获得用户已授权节点
     $authed_nodes = session('authed_nodes');
     if (DEBUG || !$authed_nodes) {
         $authed_nodes = D('Account/Authorize')->get_authed_nodes();
         session('authed_nodes', $authed_nodes);
     }
     self::$authed_nodes = $authed_nodes;
     AuthorizeService::set_authed_nodes($authed_nodes);
     //当前动作权限检测
     // @todo event, event_get
     $current_node_auth_flag = DEBUG ? 1 : $this->check_permission();
     if (substr($this->_method, 0, 5) !== 'event' && false === $current_node_auth_flag) {
         $node_lang = __(lcfirst(MODULE_NAME) . '.METHODS.' . $this->_method) . ' ' . __(lcfirst(MODULE_NAME) . '.' . ucfirst(CONTROLLER_NAME));
         return $this->httpError(403, __("common.Permission Denied") . ": " . $node_lang . "({$this->current_action_all})");
     }
     $this->current_node_auth_flag = (int) $current_node_auth_flag;
     tag('after_controller_construct');
 }