增加控制台配置

This commit is contained in:
yunwuxin
2018-01-26 17:32:19 +08:00
parent 554817c045
commit d0ca837a2c
2 changed files with 325 additions and 299 deletions

View File

@@ -1,289 +1,296 @@
<?php <?php
return [ return [
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 应用设置 // | 应用设置
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// 默认Host地址 // 默认Host地址
'app_host' => '', 'app_host' => '',
// 应用调试模式 // 应用调试模式
'app_debug' => false, 'app_debug' => false,
// 应用Trace // 应用Trace
'app_trace' => false, 'app_trace' => false,
// 应用模式状态 // 应用模式状态
'app_status' => '', 'app_status' => '',
// 是否支持多模块 // 是否支持多模块
'app_multi_module' => true, 'app_multi_module' => true,
// 入口自动绑定模块 // 入口自动绑定模块
'auto_bind_module' => false, 'auto_bind_module' => false,
// 注册的根命名空间 // 注册的根命名空间
'root_namespace' => [], 'root_namespace' => [],
// 扩展函数文件 // 扩展函数文件
'extra_file_list' => [THINK_PATH . 'helper' . EXT], 'extra_file_list' => [THINK_PATH . 'helper' . EXT],
// 默认输出类型 // 默认输出类型
'default_return_type' => 'html', 'default_return_type' => 'html',
// 默认AJAX 数据返回格式,可选json xml ... // 默认AJAX 数据返回格式,可选json xml ...
'default_ajax_return' => 'json', 'default_ajax_return' => 'json',
// 默认JSONP格式返回的处理方法 // 默认JSONP格式返回的处理方法
'default_jsonp_handler' => 'jsonpReturn', 'default_jsonp_handler' => 'jsonpReturn',
// 默认JSONP处理方法 // 默认JSONP处理方法
'var_jsonp_handler' => 'callback', 'var_jsonp_handler' => 'callback',
// 默认时区 // 默认时区
'default_timezone' => 'PRC', 'default_timezone' => 'PRC',
// 是否开启多语言 // 是否开启多语言
'lang_switch_on' => false, 'lang_switch_on' => false,
// 默认全局过滤方法 用逗号分隔多个 // 默认全局过滤方法 用逗号分隔多个
'default_filter' => '', 'default_filter' => '',
// 默认语言 // 默认语言
'default_lang' => 'zh-cn', 'default_lang' => 'zh-cn',
// 应用类库后缀 // 应用类库后缀
'class_suffix' => false, 'class_suffix' => false,
// 控制器类后缀 // 控制器类后缀
'controller_suffix' => false, 'controller_suffix' => false,
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 模块设置 // | 模块设置
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// 默认模块名 // 默认模块名
'default_module' => 'index', 'default_module' => 'index',
// 禁止访问模块 // 禁止访问模块
'deny_module_list' => ['common'], 'deny_module_list' => ['common'],
// 默认控制器名 // 默认控制器名
'default_controller' => 'Index', 'default_controller' => 'Index',
// 默认操作名 // 默认操作名
'default_action' => 'index', 'default_action' => 'index',
// 默认验证器 // 默认验证器
'default_validate' => '', 'default_validate' => '',
// 默认的空控制器名 // 默认的空控制器名
'empty_controller' => 'Error', 'empty_controller' => 'Error',
// 操作方法前缀 // 操作方法前缀
'use_action_prefix' => false, 'use_action_prefix' => false,
// 操作方法后缀 // 操作方法后缀
'action_suffix' => '', 'action_suffix' => '',
// 自动搜索控制器 // 自动搜索控制器
'controller_auto_search' => false, 'controller_auto_search' => false,
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | URL设置 // | URL设置
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// PATHINFO变量名 用于兼容模式 // PATHINFO变量名 用于兼容模式
'var_pathinfo' => 's', 'var_pathinfo' => 's',
// 兼容PATH_INFO获取 // 兼容PATH_INFO获取
'pathinfo_fetch' => ['ORIG_PATH_INFO', 'REDIRECT_PATH_INFO', 'REDIRECT_URL'], 'pathinfo_fetch' => ['ORIG_PATH_INFO', 'REDIRECT_PATH_INFO', 'REDIRECT_URL'],
// pathinfo分隔符 // pathinfo分隔符
'pathinfo_depr' => '/', 'pathinfo_depr' => '/',
// HTTPS代理标识 // HTTPS代理标识
'https_agent_name' => '', 'https_agent_name' => '',
// URL伪静态后缀 // URL伪静态后缀
'url_html_suffix' => 'html', 'url_html_suffix' => 'html',
// URL普通方式参数 用于自动生成 // URL普通方式参数 用于自动生成
'url_common_param' => false, 'url_common_param' => false,
// URL参数方式 0 按名称成对解析 1 按顺序解析 // URL参数方式 0 按名称成对解析 1 按顺序解析
'url_param_type' => 0, 'url_param_type' => 0,
// 是否开启路由 // 是否开启路由
'url_route_on' => true, 'url_route_on' => true,
// 路由配置文件(支持配置多个) // 路由配置文件(支持配置多个)
'route_config_file' => ['route'], 'route_config_file' => ['route'],
// 路由使用完整匹配 // 路由使用完整匹配
'route_complete_match' => false, 'route_complete_match' => false,
// 是否强制使用路由 // 是否强制使用路由
'url_route_must' => false, 'url_route_must' => false,
// 域名部署 // 域名部署
'url_domain_deploy' => false, 'url_domain_deploy' => false,
// 域名根如thinkphp.cn // 域名根如thinkphp.cn
'url_domain_root' => '', 'url_domain_root' => '',
// 是否自动转换URL中的控制器和操作名 // 是否自动转换URL中的控制器和操作名
'url_convert' => true, 'url_convert' => true,
// 默认的访问控制器层 // 默认的访问控制器层
'url_controller_layer' => 'controller', 'url_controller_layer' => 'controller',
// 表单请求类型伪装变量 // 表单请求类型伪装变量
'var_method' => '_method', 'var_method' => '_method',
// 表单ajax伪装变量 // 表单ajax伪装变量
'var_ajax' => '_ajax', 'var_ajax' => '_ajax',
// 表单pjax伪装变量 // 表单pjax伪装变量
'var_pjax' => '_pjax', 'var_pjax' => '_pjax',
// 是否开启请求缓存 true自动缓存 支持设置请求缓存规则 // 是否开启请求缓存 true自动缓存 支持设置请求缓存规则
'request_cache' => false, 'request_cache' => false,
// 请求缓存有效期 // 请求缓存有效期
'request_cache_expire' => null, 'request_cache_expire' => null,
// 全局请求缓存排除规则 // 全局请求缓存排除规则
'request_cache_except' => [], 'request_cache_except' => [],
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 模板设置 // | 模板设置
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
'template' => [ 'template' => [
// 模板引擎类型 支持 php think 支持扩展 // 模板引擎类型 支持 php think 支持扩展
'type' => 'Think', 'type' => 'Think',
// 视图基础目录,配置目录为所有模块的视图起始目录 // 视图基础目录,配置目录为所有模块的视图起始目录
'view_base' => '', 'view_base' => '',
// 当前模板的视图目录 留空为自动获取 // 当前模板的视图目录 留空为自动获取
'view_path' => '', 'view_path' => '',
// 模板后缀 // 模板后缀
'view_suffix' => 'html', 'view_suffix' => 'html',
// 模板文件名分隔符 // 模板文件名分隔符
'view_depr' => DS, 'view_depr' => DS,
// 模板引擎普通标签开始标记 // 模板引擎普通标签开始标记
'tpl_begin' => '{', 'tpl_begin' => '{',
// 模板引擎普通标签结束标记 // 模板引擎普通标签结束标记
'tpl_end' => '}', 'tpl_end' => '}',
// 标签库标签开始标记 // 标签库标签开始标记
'taglib_begin' => '{', 'taglib_begin' => '{',
// 标签库标签结束标记 // 标签库标签结束标记
'taglib_end' => '}', 'taglib_end' => '}',
], ],
// 视图输出字符串内容替换 // 视图输出字符串内容替换
'view_replace_str' => [], 'view_replace_str' => [],
// 默认跳转页面对应的模板文件 // 默认跳转页面对应的模板文件
'dispatch_success_tmpl' => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl', 'dispatch_success_tmpl' => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl',
'dispatch_error_tmpl' => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl', 'dispatch_error_tmpl' => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl',
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 异常及错误设置 // | 异常及错误设置
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// 异常页面的模板文件 // 异常页面的模板文件
'exception_tmpl' => THINK_PATH . 'tpl' . DS . 'think_exception.tpl', 'exception_tmpl' => THINK_PATH . 'tpl' . DS . 'think_exception.tpl',
// 错误显示信息,非调试模式有效 // 错误显示信息,非调试模式有效
'error_message' => '页面错误!请稍后再试~', 'error_message' => '页面错误!请稍后再试~',
// 显示错误信息 // 显示错误信息
'show_error_msg' => false, 'show_error_msg' => false,
// 异常处理handle类 留空使用 \think\exception\Handle // 异常处理handle类 留空使用 \think\exception\Handle
'exception_handle' => '', 'exception_handle' => '',
// 是否记录trace信息到日志 // 是否记录trace信息到日志
'record_trace' => false, 'record_trace' => false,
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 日志设置 // | 日志设置
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
'log' => [ 'log' => [
// 日志记录方式,内置 file socket 支持扩展 // 日志记录方式,内置 file socket 支持扩展
'type' => 'File', 'type' => 'File',
// 日志保存目录 // 日志保存目录
'path' => LOG_PATH, 'path' => LOG_PATH,
// 日志记录级别 // 日志记录级别
'level' => [], 'level' => [],
], ],
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | Trace设置 开启 app_trace 后 有效 // | Trace设置 开启 app_trace 后 有效
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
'trace' => [ 'trace' => [
// 内置Html Console 支持扩展 // 内置Html Console 支持扩展
'type' => 'Html', 'type' => 'Html',
], ],
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 缓存设置 // | 缓存设置
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
'cache' => [ 'cache' => [
// 驱动方式 // 驱动方式
'type' => 'File', 'type' => 'File',
// 缓存保存目录 // 缓存保存目录
'path' => CACHE_PATH, 'path' => CACHE_PATH,
// 缓存前缀 // 缓存前缀
'prefix' => '', 'prefix' => '',
// 缓存有效期 0表示永久缓存 // 缓存有效期 0表示永久缓存
'expire' => 0, 'expire' => 0,
], ],
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 会话设置 // | 会话设置
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
'session' => [ 'session' => [
'id' => '', 'id' => '',
// SESSION_ID的提交变量,解决flash上传跨域 // SESSION_ID的提交变量,解决flash上传跨域
'var_session_id' => '', 'var_session_id' => '',
// SESSION 前缀 // SESSION 前缀
'prefix' => 'think', 'prefix' => 'think',
// 驱动方式 支持redis memcache memcached // 驱动方式 支持redis memcache memcached
'type' => '', 'type' => '',
// 是否自动开启 SESSION // 是否自动开启 SESSION
'auto_start' => true, 'auto_start' => true,
'httponly' => true, 'httponly' => true,
'secure' => false, 'secure' => false,
], ],
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | Cookie设置 // | Cookie设置
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
'cookie' => [ 'cookie' => [
// cookie 名称前缀 // cookie 名称前缀
'prefix' => '', 'prefix' => '',
// cookie 保存时间 // cookie 保存时间
'expire' => 0, 'expire' => 0,
// cookie 保存路径 // cookie 保存路径
'path' => '/', 'path' => '/',
// cookie 有效域名 // cookie 有效域名
'domain' => '', 'domain' => '',
// cookie 启用安全传输 // cookie 启用安全传输
'secure' => false, 'secure' => false,
// httponly设置 // httponly设置
'httponly' => '', 'httponly' => '',
// 是否使用 setcookie // 是否使用 setcookie
'setcookie' => true, 'setcookie' => true,
], ],
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 数据库设置 // | 数据库设置
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
'database' => [ 'database' => [
// 数据库类型 // 数据库类型
'type' => 'mysql', 'type' => 'mysql',
// 数据库连接DSN配置 // 数据库连接DSN配置
'dsn' => '', 'dsn' => '',
// 服务器地址 // 服务器地址
'hostname' => '127.0.0.1', 'hostname' => '127.0.0.1',
// 数据库名 // 数据库名
'database' => '', 'database' => '',
// 数据库用户名 // 数据库用户名
'username' => 'root', 'username' => 'root',
// 数据库密码 // 数据库密码
'password' => '', 'password' => '',
// 数据库连接端口 // 数据库连接端口
'hostport' => '', 'hostport' => '',
// 数据库连接参数 // 数据库连接参数
'params' => [], 'params' => [],
// 数据库编码默认采用utf8 // 数据库编码默认采用utf8
'charset' => 'utf8', 'charset' => 'utf8',
// 数据库表前缀 // 数据库表前缀
'prefix' => '', 'prefix' => '',
// 数据库调试模式 // 数据库调试模式
'debug' => false, 'debug' => false,
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
'deploy' => 0, 'deploy' => 0,
// 数据库读写是否分离 主从式有效 // 数据库读写是否分离 主从式有效
'rw_separate' => false, 'rw_separate' => false,
// 读写分离后 主服务器数量 // 读写分离后 主服务器数量
'master_num' => 1, 'master_num' => 1,
// 指定从服务器序号 // 指定从服务器序号
'slave_no' => '', 'slave_no' => '',
// 是否严格检查字段是否存在 // 是否严格检查字段是否存在
'fields_strict' => true, 'fields_strict' => true,
// 数据集返回类型 // 数据集返回类型
'resultset_type' => 'array', 'resultset_type' => 'array',
// 自动写入时间戳字段 // 自动写入时间戳字段
'auto_timestamp' => false, 'auto_timestamp' => false,
// 时间字段取出后的默认时间格式 // 时间字段取出后的默认时间格式
'datetime_format' => 'Y-m-d H:i:s', 'datetime_format' => 'Y-m-d H:i:s',
// 是否需要进行SQL性能分析 // 是否需要进行SQL性能分析
'sql_explain' => false, 'sql_explain' => false,
], ],
//分页配置 //分页配置
'paginate' => [ 'paginate' => [
'type' => 'bootstrap', 'type' => 'bootstrap',
'var_page' => 'page', 'var_page' => 'page',
'list_rows' => 15, 'list_rows' => 15,
], ],
]; //控制台配置
'console' => [
'name' => 'Think Console',
'version' => '0.1',
'user' => null
]
];

View File

@@ -79,14 +79,19 @@ class Console
/** /**
* Console constructor. * Console constructor.
* @access public * @access public
* @param string $name 名称 * @param string $name 名称
* @param string $version 版本 * @param string $version 版本
* @param null|string $user 执行用户
*/ */
public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN', $user = null)
{ {
$this->name = $name; $this->name = $name;
$this->version = $version; $this->version = $version;
if ($user) {
$this->setUser($user);
}
$this->defaultCommand = 'list'; $this->defaultCommand = 'list';
$this->definition = $this->getDefaultInputDefinition(); $this->definition = $this->getDefaultInputDefinition();
@@ -95,6 +100,19 @@ class Console
} }
} }
/**
* 设置执行用户
* @param $user
*/
public function setUser($user)
{
$user = posix_getpwnam($user);
if ($user) {
posix_setuid($user['uid']);
posix_setgid($user['gid']);
}
}
/** /**
* 初始化 Console * 初始化 Console
* @access public * @access public
@@ -106,8 +124,9 @@ class Console
static $console; static $console;
if (!$console) { if (!$console) {
$config = Config::get('console');
// 实例化 console // 实例化 console
$console = new self('Think Console', '0.1'); $console = new self($config['name'], $config['version'], $config['user']);
// 读取指令集 // 读取指令集
if (is_file(CONF_PATH . 'command' . EXT)) { if (is_file(CONF_PATH . 'command' . EXT)) {
@@ -479,7 +498,7 @@ class Console
}, $namespace); }, $namespace);
$allNamespaces = $this->getNamespaces(); $allNamespaces = $this->getNamespaces();
$namespaces = preg_grep('{^' . $expr . '}', $allNamespaces); $namespaces = preg_grep('{^' . $expr . '}', $allNamespaces);
if (empty($namespaces)) { if (empty($namespaces)) {
$message = sprintf( $message = sprintf(
@@ -527,7 +546,7 @@ class Console
}, $name); }, $name);
$allCommands = array_keys($this->commands); $allCommands = array_keys($this->commands);
$commands = preg_grep('{^' . $expr . '}', $allCommands); $commands = preg_grep('{^' . $expr . '}', $allCommands);
if (empty($commands) || count(preg_grep('{^' . $expr . '$}', $commands)) < 1) { if (empty($commands) || count(preg_grep('{^' . $expr . '$}', $commands)) < 1) {
if (false !== ($pos = strrpos($name, ':'))) { if (false !== ($pos = strrpos($name, ':'))) {
@@ -550,7 +569,7 @@ class Console
if (count($commands) > 1) { if (count($commands) > 1) {
$commandList = $this->commands; $commandList = $this->commands;
$commands = array_filter($commands, function ($nameOrAlias) use ($commandList, $commands) { $commands = array_filter($commands, function ($nameOrAlias) use ($commandList, $commands) {
$commandName = $commandList[$nameOrAlias]->getName(); $commandName = $commandList[$nameOrAlias]->getName();
return $commandName === $nameOrAlias || !in_array($commandName, $commands); return $commandName === $nameOrAlias || !in_array($commandName, $commands);
@@ -601,7 +620,7 @@ class Console
$abbrevs = []; $abbrevs = [];
foreach ($names as $name) { foreach ($names as $name) {
for ($len = strlen($name); $len > 0; --$len) { for ($len = strlen($name); $len > 0; --$len) {
$abbrev = substr($name, 0, $len); $abbrev = substr($name, 0, $len);
$abbrevs[$abbrev][] = $name; $abbrevs[$abbrev][] = $name;
} }
} }
@@ -754,8 +773,8 @@ class Console
*/ */
private function findAlternatives($name, $collection) private function findAlternatives($name, $collection)
{ {
$threshold = 1e3; $threshold = 1e3;
$alternatives = []; $alternatives = [];
$collectionParts = []; $collectionParts = [];
foreach ($collection as $item) { foreach ($collection as $item) {