Esempio n. 1
0
 /**
  * Inicia el bootstrap
  */
 public static function init()
 {
     //FIXME dejar esto configurable
     date_default_timezone_set("America/Mexico_City");
     self::$config = (include 'config/application.config.php');
     self::$smConfig = isset($configuration['service_manager']) ? $configuration['service_manager'] : array();
     self::$listeners = isset($configuration['listeners']) ? $configuration['listeners'] : array();
 }
Esempio n. 2
0
 /**
  * @return MetaAbstract
  * */
 public function meta()
 {
     $dsName = $this->_bootstrap->config('app.persist.default');
     $config = $this->_bootstrap->config('app.persist')->toArray();
     $pConfig = PersistConfig::factory($dsName, $config);
     $persist = \br\gov\sial\core\persist\database\Connect::factory($pConfig);
     return MetaAbstract::factory($persist);
 }
Esempio n. 3
0
 /**
  * 重新加载类库
  *
  */
 protected static function reload_all_libraries()
 {
     # 加载类库
     $lib_config = self::$core_config['libraries'];
     # 重置
     self::$include_path['library'] = array();
     foreach (array('autoload', 'cli', 'admin', 'debug', 'rest') as $type) {
         if (!isset($lib_config[$type]) || !$lib_config[$type]) {
             continue;
         }
         if ($type == 'cli') {
             if (!IS_DEBUG) {
                 continue;
             }
         } else {
             if ($type == 'admin') {
                 if (!IS_ADMIN_MODE) {
                     continue;
                 }
             } else {
                 if ($type == 'rest') {
                     if (!IS_REST_MODE) {
                         continue;
                     }
                 } else {
                     if ($type == 'debug') {
                         if (!IS_DEBUG) {
                             continue;
                         }
                     }
                 }
             }
         }
         $libs = array_reverse((array) $lib_config[$type]);
         foreach ($libs as $lib) {
             self::_add_include_path_lib($lib);
         }
     }
     # 处理 library 的config
     $config_files = array();
     self::get_config_file_by_path($config_files, self::$include_path['project'], true);
     self::get_config_file_by_path($config_files, self::$include_path['team-library'], true);
     self::get_config_file_by_path($config_files, self::$include_path['library'], false);
     self::get_config_file_by_path($config_files, self::$include_path['core'], false);
     if ($config_files) {
         # 反向排序,从最后一个开始导入
         $config_files = array_reverse($config_files);
         # 导入config
         self::$config = self::$core_config;
         # 移除特殊的key
         unset(self::$config['core']);
         unset(self::$config['projects']);
         # 载入config
         __include_config_file(self::$config, $config_files);
     }
 }
Esempio n. 4
0
 /**
  * 系统初始化
  *
  * @param boolean $auto_execute 是否自动运行
  */
 public static function setup($auto_execute = true)
 {
     static $run = null;
     if (!$run) {
         $run = true;
         # 注册自动加载类
         spl_autoload_register(array('Bootstrap', 'auto_load'));
         # 读取配置
         if (!is_file(DIR_SYSTEM . 'config' . EXT)) {
             self::show_error('Please rename the file config.new.php to config.php');
         }
         $include_config_file = function (&$config, $file) {
             include $file;
         };
         self::$config = array('core' => array());
         # 读取主配置
         $include_config_file(self::$config['core'], DIR_SYSTEM . 'config' . EXT);
         # 读Debug配置
         if (isset(self::$config['core']['debug_config']) && self::$config['core']['debug_config'] && is_file(DIR_SYSTEM . 'debug.config' . EXT)) {
             $include_config_file(self::$config['core'], DIR_SYSTEM . 'debug.config' . EXT);
         }
         # DEBUG配置
         if (isset(self::$config['core']['local_debug_cfg']) && self::$config['core']['local_debug_cfg']) {
             if (function_exists('get_cfg_var')) {
                 $open_debug = get_cfg_var(self::$config['core']['local_debug_cfg']) ? 1 : 0;
             } else {
                 $open_debug = 0;
             }
         } else {
             $open_debug = 0;
         }
         /**
          * 判断是否开启了在线调试
          *
          * @return boolean
          */
         $is_online_debug = function () {
             if (IS_SYSTEM_MODE) {
                 if (isset($_SERVER['HTTP_X_MYQEE_SYSTEM_DEBUG']) && $_SERVER['HTTP_X_MYQEE_SYSTEM_DEBUG'] == '1') {
                     return true;
                 } else {
                     return false;
                 }
             }
             if (!isset($_COOKIE['_debug_open'])) {
                 return false;
             }
             if (!isset(Bootstrap::$config['core']['debug_open_password'])) {
                 return false;
             }
             if (!is_array(Bootstrap::$config['core']['debug_open_password'])) {
                 return false;
             }
             foreach (Bootstrap::$config['core']['debug_open_password'] as $user => $pass) {
                 if ($_COOKIE['_debug_open'] == Bootstrap::get_debug_hash($user, $pass)) {
                     return true;
                 }
             }
             return false;
         };
         if ($is_online_debug()) {
             $open_debug == 1 << 1 | $open_debug;
         }
         unset($is_online_debug);
         /**
          * 是否开启DEBUG模式
          *
          *     if (IS_DEBUG>>1)
          *     {
          *         //开启了在线调试
          *     }
          *
          *     if (IS_DEBUG & 1)
          *     {
          *         //本地调试打开
          *     }
          *
          *     if (IS_DEBUG)
          *     {
          *         // 开启了调试
          *     }
          *
          * @var int
          */
         define('IS_DEBUG', $open_debug);
         # 请求模式
         $request_mode = '';
         if (IS_CLI) {
             if (!isset($_SERVER["argv"])) {
                 exit('Err Argv');
             }
             $argv = $_SERVER["argv"];
             //$argv[0]为文件名
             if (isset($argv[1]) && $argv[1] && isset(self::$config['core']['projects'][$argv[1]])) {
                 self::$project = $argv[1];
             }
             array_shift($argv);
             //将文件名移除
             array_shift($argv);
             //将项目名移除
             self::$path_info = trim(implode('/', $argv));
             unset($argv);
         } else {
             self::setup_by_url($request_mode);
             if (isset(self::$config['core']['charset'])) {
                 # 输出文件头
                 header('Content-Type: text/html;charset=' . self::$config['core']['charset']);
             }
         }
         # 设置页面错误等级
         if (isset(self::$config['core']['error_reporting'])) {
             error_reporting(self::$config['core']['error_reporting']);
         }
         # 设置时区
         if (isset(self::$config['core']['timezone']) && self::$config['core']['timezone']) {
             date_default_timezone_set(self::$config['core']['timezone']);
         }
         /**
          * 加载类库
          * @var array $arr
          */
         $load_library = function ($arr) {
             # 逆向排序
             rsort($arr);
             foreach ($arr as $library_name) {
                 if (!$library_name) {
                     continue;
                 }
                 try {
                     Bootstrap::import_library($library_name);
                 } catch (Exception $e) {
                     Bootstrap::show_error($e->getMessage());
                 }
             }
         };
         /**
          * 是否后台模式
          *
          * @var boolean
          */
         define('IS_ADMIN_MODE', !IS_CLI && $request_mode == 'admin' ? true : false);
         if (IS_SYSTEM_MODE) {
             # 设置控制器在[system]目录下
             self::$dir_setting['controller'][0] .= DS . '[system]';
         }
         # 如果有autoload目录,则设置加载目录
         if (isset(self::$config['core']['libraries']['autoload']) && is_array(self::$config['core']['libraries']['autoload']) && self::$config['core']['libraries']['autoload']) {
             $load_library(self::$config['core']['libraries']['autoload']);
         }
         if (IS_CLI) {
             # cli模式
             if (isset(self::$config['core']['libraries']['cli']) && is_array(self::$config['core']['libraries']['cli']) && self::$config['core']['libraries']['cli']) {
                 $load_library(self::$config['core']['libraries']['cli']);
             }
             if (!IS_SYSTEM_MODE) {
                 # 控制器在[shell]目录下
                 self::$dir_setting['controller'][0] .= DS . '[shell]';
             }
         } elseif (IS_ADMIN_MODE) {
             # 后台模式
             if (isset(self::$config['core']['libraries']['admin']) && is_array(self::$config['core']['libraries']['admin']) && self::$config['core']['libraries']['admin']) {
                 $load_library(self::$config['core']['libraries']['admin']);
             }
             if (!IS_SYSTEM_MODE) {
                 # 控制器在[admin]目录下
                 self::$dir_setting['controller'][0] .= DS . '[admin]';
             }
         } elseif ($request_mode == 'app') {
             # APP模式
             if (isset(self::$config['core']['libraries']['app']) && is_array(self::$config['core']['libraries']['app']) && self::$config['core']['libraries']['app']) {
                 $load_library(self::$config['core']['libraries']['app']);
             }
         }
         if (IS_DEBUG) {
             # 加载debug类库
             if (isset(self::$config['core']['libraries']['debug']) && is_array(self::$config['core']['libraries']['debug']) && self::$config['core']['libraries']['debug']) {
                 $load_library(self::$config['core']['libraries']['debug']);
             }
             # 输出一些系统信息
             Core::debug()->group('include path');
             foreach (self::$include_path as $value) {
                 Core::debug()->log(Core::debug_path($value));
             }
             Core::debug()->groupEnd();
             if (self::$project) {
                 Core::debug()->info('project: ' . self::$project);
             } elseif ($request_mode == 'app') {
                 Core::debug()->info('app mode');
             } else {
                 Core::debug()->info('default application');
             }
             if (IS_ADMIN_MODE) {
                 Core::debug()->info('admin mode');
             }
         }
         unset($load_library);
         Core::setup();
     }
     # 直接执行
     if ($auto_execute) {
         if (IS_CLI || IS_SYSTEM_MODE) {
             self::execute(self::$path_info);
         } else {
             ob_start();
             try {
                 self::execute(self::$path_info);
             } catch (Exception $e) {
                 $code = $e->getCode();
                 if (404 === $code || E_PAGE_NOT_FOUND === $code) {
                     Core::show_404($e->getMessage());
                 } elseif (500 === $code) {
                     Core::show_500($e->getMessage());
                 } else {
                     Core::show_500($e->getMessage(), $code);
                 }
             }
             HttpIO::$body = ob_get_clean();
         }
         # 全部全部连接
         Core::close_all_connect();
     }
 }
Esempio n. 5
0
 /**
  * 设置项目
  * 可重新设置新项目已实现程序内项目切换,但需谨慎使用
  * @param string $project
  */
 public static function set_project($project)
 {
     if (self::$project == $project) {
         return true;
     }
     static $core_config = null;
     if (null === $core_config) {
         # 记录原始Core配置
         $core_config = self::$config['core'];
     }
     if (!isset($core_config['projects'][$project])) {
         self::_throw_sys_error_msg(__('not found the project: :project.', array(':project' => $project)));
     }
     if (!$core_config['projects'][$project]['isuse']) {
         self::_throw_sys_error_msg(__('the project: :project is not open.', array(':project' => '$project')));
     }
     # 获取core里项目配置
     $project_config = $core_config['projects'][$project];
     # 项目路径
     $project_dir = realpath(DIR_PROJECT . $project_config['dir']);
     if (!$project_dir || !is_dir($project_dir)) {
         self::_throw_sys_error_msg(__('the project dir :dir is not exist.', array(':dir' => $project_config['dir'])));
     }
     $project_dir .= DS;
     self::$project_dir = $project_dir;
     # 记录所有项目设置,当切换回项目时,使用此设置还原
     static $all_prjects_setting = array();
     if (self::$project) {
         # 记录上一个项目设置
         $all_prjects_setting[self::$project] = array('config' => self::$config, 'project_config' => self::$project_config, 'include_path' => self::$include_path, 'file_list' => self::$file_list);
     }
     # 设为当前项目
     self::$project = $project;
     # 记录debug信息
     if (class_exists('Core', false)) {
         Core::debug()->info('程序已切换到了新项目:' . $project);
     }
     if (isset($all_prjects_setting[$project])) {
         # 还原配置
         self::$config = $all_prjects_setting[$project]['config'];
         self::$project_config = $all_prjects_setting[$project]['project_config'];
         self::$include_path = $all_prjects_setting[$project]['include_path'];
         self::$file_list = $all_prjects_setting[$project]['file_list'];
     } else {
         # 合并配置
         $config = $core_config['projects'][$project] + self::$config['core'];
         # 读取项目配置
         if (is_file($project_dir . 'config' . EXT)) {
             self::_include_config_file($config, $project_dir . 'config' . EXT);
         }
         # 读取DEBUG配置
         if (isset(self::$config['core']['debug_config']) && self::$config['core']['debug_config'] && is_file($project_dir . 'debug.config' . EXT)) {
             self::_include_config_file($config, $project_dir . 'debug.config' . EXT);
         }
         # 清理项目配置
         self::$project_config = $config;
         self::$config = array('core' => &self::$project_config);
         unset($config);
         # Builder构建,处理 self::$file_list
         if (self::$project_config['use_bulider'] === 'auto') {
             if (IS_DEBUG) {
                 $usebulider = false;
             } else {
                 $usebulider = true;
             }
         } else {
             $usebulider = (bool) self::$project_config['use_bulider'];
         }
         $project_filelist = DIR_BULIDER . self::$project . DS . 'project_all_files_list' . EXT;
         if (true === $usebulider && !IS_CLI && is_file($project_filelist)) {
             # 读取文件列表
             self::_include_config_file(self::$file_list, $project_filelist);
         }
         # 设置包含目录
         self::$include_path = self::get_project_include_path($project);
     }
     if (isset(self::$project_config['error_reporting'])) {
         error_reporting(self::$project_config['error_reporting']);
     }
     # 时区设置
     if (isset(self::$project_config['timezone'])) {
         date_default_timezone_set(self::$project_config['timezone']);
     }
     if (class_exists('Core', false)) {
         # 输出调试信息
         if (IS_DEBUG) {
             Core::debug()->group('当前加载目录');
             foreach (self::$include_path as $value) {
                 Core::debug()->log(Core::debug_path($value));
             }
             Core::debug()->groupEnd();
         }
         Core::ini_library();
     }
 }