diff --git a/.gitignore b/.gitignore
index 210547b..a3d20e0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
-.idea
-composer.lock
+/.idea
+/.vscode
+/vendor
*.log
-nbproject
-.git
+thinkphp
+.env
\ No newline at end of file
diff --git a/README.md b/README.md
index acf2d0c..b540dd7 100644
--- a/README.md
+++ b/README.md
@@ -1,144 +1,23 @@
-ThinkPHP 5.1
+ThinkPHP 6.0
===============
-ThinkPHP5.1对底层架构做了进一步的改进,减少依赖,其主要特性包括:
-
- + 采用容器统一管理对象
- + 支持Facade
- + 注解路由支持
- + 路由跨域请求支持
- + 配置和路由目录独立
- + 取消系统常量
- + 助手函数增强
- + 类库别名机制
- + 增加条件查询
- + 改进查询机制
- + 配置采用二级
- + 依赖注入完善
+> 运行环境要求PHP7.1+。
-> ThinkPHP5的运行环境要求PHP5.6以上。
-
-
-## 目录结构
-
-初始的目录结构如下:
+## 安装
~~~
-www WEB部署目录(或者子目录)
-├─application 应用目录
-│ ├─common 公共模块目录(可以更改)
-│ ├─module_name 模块目录
-│ │ ├─common.php 模块函数文件
-│ │ ├─controller 控制器目录
-│ │ ├─model 模型目录
-│ │ ├─view 视图目录
-│ │ └─ ... 更多类库目录
-│ │
-│ ├─command.php 命令行定义文件
-│ ├─common.php 公共函数文件
-│ └─tags.php 应用行为扩展定义文件
-│
-├─config 应用配置目录
-│ ├─module_name 模块配置目录
-│ │ ├─database.php 数据库配置
-│ │ ├─cache 缓存配置
-│ │ └─ ...
-│ │
-│ ├─app.php 应用配置
-│ ├─cache.php 缓存配置
-│ ├─cookie.php Cookie配置
-│ ├─database.php 数据库配置
-│ ├─log.php 日志配置
-│ ├─session.php Session配置
-│ ├─template.php 模板引擎配置
-│ └─trace.php Trace配置
-│
-├─route 路由定义目录
-│ ├─route.php 路由定义
-│ └─... 更多
-│
-├─public WEB目录(对外访问目录)
-│ ├─index.php 入口文件
-│ ├─router.php 快速测试文件
-│ └─.htaccess 用于apache的重写
-│
-├─thinkphp 框架系统目录
-│ ├─lang 语言文件目录
-│ ├─library 框架类库目录
-│ │ ├─think Think类库包目录
-│ │ └─traits 系统Trait目录
-│ │
-│ ├─tpl 系统模板目录
-│ ├─base.php 基础定义文件
-│ ├─console.php 控制台入口文件
-│ ├─convention.php 框架惯例配置文件
-│ ├─helper.php 助手函数文件
-│ ├─phpunit.xml phpunit配置文件
-│ └─start.php 框架入口文件
-│
-├─extend 扩展类库目录
-├─runtime 应用的运行时目录(可写,可定制)
-├─vendor 第三方类库目录(Composer依赖库)
-├─build.php 自动生成定义文件(参考)
-├─composer.json composer 定义文件
-├─LICENSE.txt 授权说明文件
-├─README.md README 文件
-├─think 命令行入口文件
+composer create-project topthink/think tp 6.0.*-dev
~~~
-> router.php用于php自带webserver支持,可用于快速测试
-> 切换到public目录后,启动命令:php -S localhost:8888 router.php
-> 上面的目录结构和名称是可以改变的,这取决于你的入口文件和配置参数。
-
-## 升级指导
-
-原有下面系统类库的命名空间需要调整:
-
-* think\App => think\facade\App (或者 App )
-* think\Cache => think\facade\Cache (或者 Cache )
-* think\Config => think\facade\Config (或者 Config )
-* think\Cookie => think\facade\Cookie (或者 Cookie )
-* think\Debug => think\facade\Debug (或者 Debug )
-* think\Hook => think\facade\Hook (或者 Hook )
-* think\Lang => think\facade\Lang (或者 Lang )
-* think\Log => think\facade\Log (或者 Log )
-* think\Request => think\facade\Request (或者 Request )
-* think\Response => think\facade\Reponse (或者 Reponse )
-* think\Route => think\facade\Route (或者 Route )
-* think\Session => think\facade\Session (或者 Session )
-* think\Url => think\facade\Url (或者 Url )
-
-原有的配置文件config.php 拆分为app.php cache.php 等独立配置文件 放入config目录。
-原有的路由定义文件route.php 移动到route目录
-
-## 命名规范
-
-`ThinkPHP5`遵循PSR-2命名规范和PSR-4自动加载规范,并且注意如下规范:
-
-### 目录和文件
-
-* 目录不强制规范,驼峰和小写+下划线模式均支持;
-* 类库、函数文件统一以`.php`为后缀;
-* 类的文件名均以命名空间定义,并且命名空间的路径和类库文件所在路径一致;
-* 类名和类文件名保持一致,统一采用驼峰法命名(首字母大写);
-
-### 函数和类、属性命名
-* 类的命名采用驼峰法,并且首字母大写,例如 `User`、`UserType`,默认不需要添加后缀,例如`UserController`应该直接命名为`User`;
-* 函数的命名使用小写字母和下划线(小写字母开头)的方式,例如 `get_client_ip`;
-* 方法的命名使用驼峰法,并且首字母小写,例如 `getUserName`;
-* 属性的命名使用驼峰法,并且首字母小写,例如 `tableName`、`instance`;
-* 以双下划线“__”打头的函数或方法作为魔法方法,例如 `__call` 和 `__autoload`;
-
-### 常量和配置
-* 常量以大写字母和下划线命名,例如 `APP_PATH`和 `THINK_PATH`;
-* 配置参数以小写字母和下划线命名,例如 `url_route_on` 和`url_convert`;
-
-### 数据表和字段
-* 数据表和字段采用小写加下划线方式命名,并注意字段名不要以下划线开头,例如 `think_user` 表和 `user_name`字段,不建议使用驼峰和中文作为数据表字段命名。
+如果需要更新框架使用
+~~~
+composer update topthink/framework
+~~~
## 参与开发
-请参阅 [ThinkPHP5 核心框架包](https://github.com/top-think/framework)。
+
+请参阅 [ThinkPHP 核心框架包](https://github.com/top-think/framework)。
## 版权信息
@@ -146,7 +25,7 @@ ThinkPHP遵循Apache2开源协议发布,并提供免费使用。
本项目包含的第三方源码和二进制文件之版权信息另行标注。
-版权所有Copyright © 2006-2018 by ThinkPHP (http://thinkphp.cn)
+版权所有Copyright © 2006-2019 by ThinkPHP (http://thinkphp.cn)
All rights reserved。
diff --git a/application/.htaccess b/app/.htaccess
similarity index 100%
rename from application/.htaccess
rename to app/.htaccess
diff --git a/application/common.php b/app/common.php
similarity index 100%
rename from application/common.php
rename to app/common.php
diff --git a/app/controller/Index.php b/app/controller/Index.php
new file mode 100644
index 0000000..bff26d6
--- /dev/null
+++ b/app/controller/Index.php
@@ -0,0 +1,15 @@
+*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }
:)
ThinkPHP V6
13载初心不改 - 你值得信赖的PHP框架
';
+ }
+
+ public function hello($name = 'ThinkPHP6')
+ {
+ return 'hello,' . $name;
+ }
+}
diff --git a/route/route.php b/app/event.php
similarity index 65%
rename from route/route.php
rename to app/event.php
index 1a44c5e..c3918f2 100644
--- a/route/route.php
+++ b/app/event.php
@@ -9,14 +9,19 @@
// | Author: liu21st
// +----------------------------------------------------------------------
-//Route::get('think', function () {
-// return 'hello,ThinkPHP5!';
-//});
-
-Route::get('hello/:name', 'index/hello');
-
-Route::get('news', 'news/test/hello');
-
+// 事件定义文件
return [
-
+ 'bind' => [
+ ],
+ 'listen' => [
+ 'AppInit' => [],
+ 'AppBegin' => [],
+ 'AppEnd' => [],
+ 'LogLevel' => [],
+ 'LogWrite' => [],
+ 'ResponseSend' => [],
+ 'ResponseEnd' => [],
+ ],
+ 'subscribe' => [
+ ],
];
diff --git a/app/middleware.php b/app/middleware.php
new file mode 100644
index 0000000..4b351a2
--- /dev/null
+++ b/app/middleware.php
@@ -0,0 +1,8 @@
+
-// +----------------------------------------------------------------------
-
-return [];
diff --git a/application/index/behavior/test.php b/application/index/behavior/test.php
deleted file mode 100644
index 9ec4839..0000000
--- a/application/index/behavior/test.php
+++ /dev/null
@@ -1,23 +0,0 @@
-';
- }
-
- //若位置名称对应的方法不存在,则执行这个
- public function run($params)
- {
- echo 'run参数'.$params;
- }
-
- //根据执行的位置名称,方法名 对应位置名称,若存在下划线将去掉下划线
- public function appInit($params)
- {
- echo 'appInit参数';
- }
-}
diff --git a/application/index/controller/Index.php b/application/index/controller/Index.php
deleted file mode 100644
index 2c4ed42..0000000
--- a/application/index/controller/Index.php
+++ /dev/null
@@ -1,15 +0,0 @@
-*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px } :) 2018新年快乐
ThinkPHP V5.1
12载初心不改(2006-2018) - 你值得信赖的PHP框架
';
- }
-
- public function hello($name = 'ThinkPHP5')
- {
- return 'hello,' . $name;
- }
-}
diff --git a/application/news/controller/Index.php b/application/news/controller/Index.php
deleted file mode 100644
index 759895c..0000000
--- a/application/news/controller/Index.php
+++ /dev/null
@@ -1,15 +0,0 @@
-
-// +----------------------------------------------------------------------
-
-// 应用行为扩展定义文件
-return [
- // 应用初始化
- 'app_init' => [
-// function($ddd){echo 'app_init闭包函数
'.$ddd[0].'
'.$ddd[1].'
';},
-// 'app\\index\\behavior\\test'
- ],
- // 应用开始
- 'app_begin' => [],
- // 模块初始化
- 'module_init' => [],
- // 操作开始执行
- 'action_begin' => [],
- // 视图内容过滤
- 'view_filter' => [],
- // 日志写入
- 'log_write' => [],
- // 应用结束
- 'app_end' => [],
-];
diff --git a/composer.json b/composer.json
index 361d6f6..05b4556 100644
--- a/composer.json
+++ b/composer.json
@@ -16,18 +16,25 @@
}
],
"require": {
- "php": ">=5.6.0",
- "topthink/framework": "5.1.*"
+ "php": ">=7.1.0",
+ "topthink/framework": "6.0.*-dev",
+ "topthink/think-view": "^1.0"
},
"autoload": {
"psr-4": {
- "app\\": "application"
+ "app\\": "app"
+ },
+ "psr-0": {
+ "": "extend/"
}
},
- "extra": {
- "think-path": "thinkphp"
- },
"config": {
"preferred-install": "dist"
+ },
+ "scripts": {
+ "post-autoload-dump": [
+ "@php think service:discover",
+ "@php think vendor:publish"
+ ]
}
}
diff --git a/config/app.php b/config/app.php
index dd3da23..d09fd2f 100644
--- a/config/app.php
+++ b/config/app.php
@@ -14,125 +14,42 @@
// +----------------------------------------------------------------------
return [
- // 应用名称
- 'app_name' => '',
// 应用地址
- 'app_host' => '',
- // 应用调试模式
- 'app_debug' => false,
- // 应用Trace
- 'app_trace' => false,
- // 应用模式状态
- 'app_status' => '',
- // 是否支持多模块
- 'app_multi_module' => true,
- // 入口自动绑定模块
- 'auto_bind_module' => false,
- // 注册的根命名空间
- 'root_namespace' => [],
- // 默认输出类型
- 'default_return_type' => 'html',
- // 默认AJAX 数据返回格式,可选json xml ...
- 'default_ajax_return' => 'json',
- // 默认JSONP格式返回的处理方法
- 'default_jsonp_handler' => 'jsonpReturn',
- // 默认JSONP处理方法
- 'var_jsonp_handler' => 'callback',
+ 'app_host' => '',
+ // 应用Trace(环境变量优先读取)
+ 'app_trace' => false,
+ // 应用的命名空间
+ 'app_namespace' => '',
+ // 是否启用路由
+ 'with_route' => true,
+ // 是否启用事件
+ 'with_event' => true,
+ // 自动多应用模式
+ 'auto_multi_app' => false,
+ // 应用映射(自动多应用模式有效)
+ 'app_map' => [],
+ // 域名绑定(自动多应用模式有效)
+ 'domain_bind' => [],
+ // 默认应用
+ 'default_app' => 'index',
// 默认时区
- 'default_timezone' => 'PRC',
+ 'default_timezone' => 'Asia/Shanghai',
// 是否开启多语言
- 'lang_switch_on' => false,
- // 默认全局过滤方法 用逗号分隔多个
- 'default_filter' => '',
+ 'lang_switch_on' => false,
// 默认语言
- 'default_lang' => 'zh-cn',
- // 应用类库后缀
- 'class_suffix' => false,
- // 控制器类后缀
- 'controller_suffix' => false,
-
- // +----------------------------------------------------------------------
- // | 模块设置
- // +----------------------------------------------------------------------
-
- // 默认模块名
- 'default_module' => 'index',
- // 禁止访问模块
- 'deny_module_list' => ['common'],
- // 默认控制器名
- 'default_controller' => 'Index',
- // 默认操作名
- 'default_action' => 'index',
+ 'default_lang' => 'zh-cn',
// 默认验证器
- 'default_validate' => '',
- // 默认的空模块名
- 'empty_module' => '',
- // 默认的空控制器名
- 'empty_controller' => 'Error',
- // 操作方法前缀
- 'use_action_prefix' => false,
- // 操作方法后缀
- 'action_suffix' => '',
- // 自动搜索控制器
- 'controller_auto_search' => false,
-
- // +----------------------------------------------------------------------
- // | URL设置
- // +----------------------------------------------------------------------
-
- // PATHINFO变量名 用于兼容模式
- 'var_pathinfo' => 's',
- // 兼容PATH_INFO获取
- 'pathinfo_fetch' => ['ORIG_PATH_INFO', 'REDIRECT_PATH_INFO', 'REDIRECT_URL'],
- // pathinfo分隔符
- 'pathinfo_depr' => '/',
- // HTTPS代理标识
- 'https_agent_name' => '',
- // URL伪静态后缀
- 'url_html_suffix' => 'html',
- // URL普通方式参数 用于自动生成
- 'url_common_param' => false,
- // URL参数方式 0 按名称成对解析 1 按顺序解析
- 'url_param_type' => 0,
- // 是否开启路由延迟解析
- 'url_lazy_route' => false,
- // 是否强制使用路由
- 'url_route_must' => true,
- // 路由是否完全匹配
- 'route_complete_match' => false,
- // 使用注解路由
- 'route_annotation' => false,
- // 域名根,如thinkphp.cn
- 'url_domain_root' => 'www.a.com',
- // 是否自动转换URL中的控制器和操作名
- 'url_convert' => true,
- // 默认的访问控制器层
- 'url_controller_layer' => 'controller',
- // 表单请求类型伪装变量
- 'var_method' => '_method',
- // 表单ajax伪装变量
- 'var_ajax' => '_ajax',
- // 表单pjax伪装变量
- 'var_pjax' => '_pjax',
- // 是否开启请求缓存 true自动缓存 支持设置请求缓存规则
- 'request_cache' => true,
- // 请求缓存有效期
- 'request_cache_expire' => null,
- // 全局请求缓存排除规则
- 'request_cache_except' => [],
+ 'default_validate' => '',
// 默认跳转页面对应的模板文件
- 'dispatch_success_tmpl' => Env::get('think_path') . 'tpl/dispatch_jump.tpl',
- 'dispatch_error_tmpl' => Env::get('think_path') . 'tpl/dispatch_jump.tpl',
+ 'dispatch_success_tmpl' => app()->getThinkPath() . 'tpl/dispatch_jump.tpl',
+ 'dispatch_error_tmpl' => app()->getThinkPath() . 'tpl/dispatch_jump.tpl',
// 异常页面的模板文件
- 'exception_tmpl' => Env::get('think_path') . 'tpl/think_exception.tpl',
+ 'exception_tmpl' => app()->getThinkPath() . 'tpl/think_exception.tpl',
// 错误显示信息,非调试模式有效
- 'error_message' => '页面错误!请稍后再试~',
+ 'error_message' => '页面错误!请稍后再试~',
// 显示错误信息
- 'show_error_msg' => false,
- // 异常处理handle类 留空使用 \think\exception\Handle
- 'exception_handle' => '',
-
+ 'show_error_msg' => false,
];
diff --git a/route/routet.php b/config/console.php
similarity index 68%
rename from route/routet.php
rename to config/console.php
index eb326a7..cf6b4ec 100644
--- a/route/routet.php
+++ b/config/console.php
@@ -9,8 +9,13 @@
// | Author: liu21st
// +----------------------------------------------------------------------
+// +----------------------------------------------------------------------
+// | 控制台配置
+// +----------------------------------------------------------------------
return [
- 'test' => [
- 'news/test/index',[]
- ]
+ // 执行用户(Windows下无效)
+ 'user' => null,
+ // 指令定义
+ 'commands' => [
+ ],
];
diff --git a/config/cookie.php b/config/cookie.php
index 1de0708..95bff33 100644
--- a/config/cookie.php
+++ b/config/cookie.php
@@ -24,7 +24,7 @@ return [
// cookie 启用安全传输
'secure' => false,
// httponly设置
- 'httponly' => '',
+ 'httponly' => false,
// 是否使用 setcookie
'setcookie' => true,
];
diff --git a/config/database.php b/config/database.php
index ecfcd03..a0196db 100644
--- a/config/database.php
+++ b/config/database.php
@@ -50,6 +50,12 @@ return [
'datetime_format' => 'Y-m-d H:i:s',
// 是否需要进行SQL性能分析
'sql_explain' => false,
+ // Builder类
+ 'builder' => '',
// Query类
'query' => '\\think\\db\\Query',
+ // 是否需要断线重连
+ 'break_reconnect' => false,
+ // 断线标识字符串
+ 'break_match_str' => [],
];
diff --git a/config/log.php b/config/log.php
index 54e81ba..b3d87b4 100644
--- a/config/log.php
+++ b/config/log.php
@@ -14,9 +14,17 @@
// +----------------------------------------------------------------------
return [
// 日志记录方式,内置 file socket 支持扩展
- 'type' => 'File',
+ 'type' => 'File',
// 日志保存目录
- 'path' => '',
+ 'path' => '',
// 日志记录级别
- 'level' => [],
+ 'level' => [],
+ // 单文件日志写入
+ 'single' => false,
+ // 独立日志级别
+ 'apart_level' => [],
+ // 最大日志文件数量
+ 'max_files' => 0,
+ // 是否关闭日志写入
+ 'close' => false,
];
diff --git a/config/route.php b/config/route.php
new file mode 100644
index 0000000..4ef85d3
--- /dev/null
+++ b/config/route.php
@@ -0,0 +1,79 @@
+
+// +----------------------------------------------------------------------
+
+// +----------------------------------------------------------------------
+// | 应用设置
+// +----------------------------------------------------------------------
+
+return [
+ // PATHINFO变量名 用于兼容模式
+ 'var_pathinfo' => 's',
+ // 兼容PATH_INFO获取
+ 'pathinfo_fetch' => ['ORIG_PATH_INFO', 'REDIRECT_PATH_INFO', 'REDIRECT_URL'],
+ // pathinfo分隔符
+ 'pathinfo_depr' => '/',
+ // HTTPS代理标识
+ 'https_agent_name' => '',
+ // URL伪静态后缀
+ 'url_html_suffix' => 'html',
+ // URL普通方式参数 用于自动生成
+ 'url_common_param' => false,
+ // 是否开启路由延迟解析
+ 'url_lazy_route' => false,
+ // 是否强制使用路由
+ 'url_route_must' => false,
+ // 合并路由规则
+ 'route_rule_merge' => false,
+ // 路由是否完全匹配
+ 'route_complete_match' => false,
+ // 使用注解路由
+ 'route_annotation' => false,
+ // 是否开启路由缓存
+ 'route_check_cache' => false,
+ // 路由缓存连接参数
+ 'route_cache_option' => [],
+ // 路由缓存Key
+ 'route_check_cache_key' => '',
+ // 访问控制器层名称
+ 'controller_layer' => 'controller',
+ // 空控制器名
+ 'empty_controller' => 'Error',
+ // 是否使用控制器后缀
+ 'controller_suffix' => false,
+ // 默认的路由变量规则
+ 'default_route_pattern' => '[\w\.]+',
+ // 域名根,如thinkphp.cn
+ 'url_domain_root' => '',
+ // 是否自动转换URL中的控制器和操作名
+ 'url_convert' => true,
+ // 表单请求类型伪装变量
+ 'var_method' => '_method',
+ // 表单ajax伪装变量
+ 'var_ajax' => '_ajax',
+ // 表单pjax伪装变量
+ 'var_pjax' => '_pjax',
+ // 是否开启请求缓存 true自动缓存 支持设置请求缓存规则
+ 'request_cache' => false,
+ // 请求缓存有效期
+ 'request_cache_expire' => null,
+ // 全局请求缓存排除规则
+ 'request_cache_except' => [],
+ // 默认控制器名
+ 'default_controller' => 'Index',
+ // 默认操作名
+ 'default_action' => 'index',
+ // 操作方法后缀
+ 'action_suffix' => '',
+ // 默认JSONP格式返回的处理方法
+ 'default_jsonp_handler' => 'jsonpReturn',
+ // 默认JSONP处理方法
+ 'var_jsonp_handler' => 'callback',
+];
diff --git a/config/session.php b/config/session.php
index 1d7b6c6..38ebaf4 100644
--- a/config/session.php
+++ b/config/session.php
@@ -17,10 +17,11 @@ return [
'id' => '',
// SESSION_ID的提交变量,解决flash上传跨域
'var_session_id' => '',
- // SESSION 前缀
- 'prefix' => 'think',
// 驱动方式 支持redis memcache memcached
'type' => '',
// 是否自动开启 SESSION
'auto_start' => true,
+ // Session配置参数
+ 'options' => [
+ ],
];
diff --git a/config/template.php b/config/template.php
deleted file mode 100644
index 0877562..0000000
--- a/config/template.php
+++ /dev/null
@@ -1,33 +0,0 @@
-
-// +----------------------------------------------------------------------
-
-// +----------------------------------------------------------------------
-// | 模板设置
-// +----------------------------------------------------------------------
-
-return [
- // 模板引擎类型 支持 php think 支持扩展
- 'type' => 'Think',
- // 模板路径
- 'view_path' => '',
- // 模板后缀
- 'view_suffix' => 'html',
- // 模板文件名分隔符
- 'view_depr' => DIRECTORY_SEPARATOR,
- // 模板引擎普通标签开始标记
- 'tpl_begin' => '{',
- // 模板引擎普通标签结束标记
- 'tpl_end' => '}',
- // 标签库标签开始标记
- 'taglib_begin' => '{',
- // 标签库标签结束标记
- 'taglib_end' => '}',
-];
diff --git a/nbproject/project.properties b/nbproject/project.properties
new file mode 100644
index 0000000..9e7cd7b
--- /dev/null
+++ b/nbproject/project.properties
@@ -0,0 +1,7 @@
+include.path=${php.global.include.path}
+php.version=PHP_56
+source.encoding=UTF-8
+src.dir=.
+tags.asp=false
+tags.short=false
+web.root=.
diff --git a/nbproject/project.xml b/nbproject/project.xml
new file mode 100644
index 0000000..85b9940
--- /dev/null
+++ b/nbproject/project.xml
@@ -0,0 +1,9 @@
+
+
+ org.netbeans.modules.php.project
+
+
+ thinkphp
+
+
+
diff --git a/public/index.php b/public/index.php
index 6e03f16..e67b8d6 100644
--- a/public/index.php
+++ b/public/index.php
@@ -12,75 +12,13 @@
// [ 应用入口文件 ]
namespace think;
+require __DIR__ . '/../vendor/autoload.php';
+// 执行HTTP应用并响应
+$http = (new App())->http;
+$response = $http->run();
+$response->send();
-
-
-
-function langt($str = '',$lang = 'en'){
- // $lang 要自动获取当前语言,并不需要靠赋值来区分语言
- if($lang == 'cn') return $str;
- $langarr = array(
- 'en' => array(
- 'Name of the merchant'=>'商户名称',
- 'Detailed address'=>'详细地址',
- 'Distribution area'=>'经销区域',
- 'Latitude and longitude orientation'=>'经纬度定位',
- 'Latitude and longitude orientation'=>'经纬度定位',
- ),
- 'tc' => array(
- 'Name of the merchant'=>'商戶名稱',
- 'Detailed address'=>'詳細地址',
- 'Distribution area'=>'經銷區域',
- 'Latitude and longitude orientation'=>'經緯度定位6',
- )
- );
-
- $langkey = (string) array_search($str,$langarr['en']);
- if($lang == 'en') return $langkey?:$str;
- return isset($langarr[$lang][$langkey])?$langarr[$lang][$langkey]:$str;
-}
-/**
- * 输出字符串或数组
- * @param string/array $vars 输出字符串或数组
- * @param string $label 提示标题
- * @param string $return 是否有返回值
- */
-function dump($vars, $return = false, $label = ''){
- if (ini_get('html_errors')){
- $content = "\n";
- if ($label != '') {
- $content .= "{$label} :\n";
- }
- $content .= htmlspecialchars(print_r($vars, true), ENT_COMPAT, 'ISO-8859-1');
- $content .= "\n\n";
- } else {
- $content = $label . " :\n" . print_r($vars, true);
- }
- echo $content;
- if ($return) exit;
- return null;
-
- for ($i=0;$i<100;$i++){
-
- }
-
-}
-
-
-
-// 加载基础文件
-require __DIR__ . '/../thinkphp/base.php';
-
-// 支持事先使用静态方法设置Request对象和Config对象
-
-// Container::get('app') 返回thinkphp/libray/think/app的实例
-// run() thinkphp/libray/think/app 对应用进行各种配置和初始化
-// send() think\Response 内
-// 执行应用并响应
-
-Container::get('app')->run()->send();
-
-//Loader::dinfo();
+$http->end($response);
diff --git a/route/routes.php b/route/app.php
similarity index 86%
rename from route/routes.php
rename to route/app.php
index d2342f3..25cb2bd 100644
--- a/route/routes.php
+++ b/route/app.php
@@ -8,15 +8,10 @@
// +----------------------------------------------------------------------
// | Author: liu21st
// +----------------------------------------------------------------------
+use think\facade\Route;
Route::get('think', function () {
return 'hello,ThinkPHP5!';
});
-//Route::get('hello/:name', 'index/hello');
-//
-//Route::get('news', 'news/test/hello');
-
-return [
-
-];
+Route::get('hello/:name', 'index/hello');
diff --git a/think b/think
index 6a923b3..b7e9aa4 100644
--- a/think
+++ b/think
@@ -13,10 +13,7 @@
namespace think;
// 加载基础文件
-require __DIR__ . '/thinkphp/base.php';
+require __DIR__ . '/vendor/autoload.php';
// 应用初始化
-Container::get('app')->path(__DIR__ . '/application/')->initialize();
-
-// 控制台初始化
-Console::init();
\ No newline at end of file
+(new App())->console->run();
\ No newline at end of file
diff --git a/thinkphp/.gitignore b/thinkphp/.gitignore
deleted file mode 100644
index 832c352..0000000
--- a/thinkphp/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-/composer.lock
-.idea
-.DS_Store
diff --git a/thinkphp/.htaccess b/thinkphp/.htaccess
deleted file mode 100644
index 3418e55..0000000
--- a/thinkphp/.htaccess
+++ /dev/null
@@ -1 +0,0 @@
-deny from all
\ No newline at end of file
diff --git a/thinkphp/CONTRIBUTING.md b/thinkphp/CONTRIBUTING.md
deleted file mode 100644
index 6cefcb3..0000000
--- a/thinkphp/CONTRIBUTING.md
+++ /dev/null
@@ -1,119 +0,0 @@
-如何贡献我的源代码
-===
-
-此文档介绍了 ThinkPHP 团队的组成以及运转机制,您提交的代码将给 ThinkPHP 项目带来什么好处,以及如何才能加入我们的行列。
-
-## 通过 Github 贡献代码
-
-ThinkPHP 目前使用 Git 来控制程序版本,如果你想为 ThinkPHP 贡献源代码,请先大致了解 Git 的使用方法。我们目前把项目托管在 GitHub 上,任何 GitHub 用户都可以向我们贡献代码。
-
-参与的方式很简单,`fork`一份 ThinkPHP 的代码到你的仓库中,修改后提交,并向我们发起`pull request`申请,我们会及时对代码进行审查并处理你的申请并。审查通过后,你的代码将被`merge`进我们的仓库中,这样你就会自动出现在贡献者名单里了,非常方便。
-
-我们希望你贡献的代码符合:
-
-* ThinkPHP 的编码规范
-* 适当的注释,能让其他人读懂
-* 遵循 Apache2 开源协议
-
-**如果想要了解更多细节或有任何疑问,请继续阅读下面的内容**
-
-### 注意事项
-
-* 本项目代码格式化标准选用 [**PSR-2**](http://www.kancloud.cn/thinkphp/php-fig-psr/3141);
-* 类名和类文件名遵循 [**PSR-4**](http://www.kancloud.cn/thinkphp/php-fig-psr/3144);
-* 对于 Issues 的处理,请使用诸如 `fix #xxx(Issue ID)` 的 commit title 直接关闭 issue。
-* 系统会自动在 PHP 5.4 5.5 5.6 7.0 和 HHVM 上测试修改,其中 HHVM 下的测试容许报错,请确保你的修改符合 PHP 5.4 ~ 5.6 和 PHP 7.0 的语法规范;
-* 管理员不会合并造成 CI faild 的修改,若出现 CI faild 请检查自己的源代码或修改相应的[单元测试文件](tests);
-
-## GitHub Issue
-
-GitHub 提供了 Issue 功能,该功能可以用于:
-
-* 提出 bug
-* 提出功能改进
-* 反馈使用体验
-
-该功能不应该用于:
-
- * 提出修改意见(涉及代码署名和修订追溯问题)
- * 不友善的言论
-
-## 快速修改
-
-**GitHub 提供了快速编辑文件的功能**
-
-1. 登录 GitHub 帐号;
-2. 浏览项目文件,找到要进行修改的文件;
-3. 点击右上角铅笔图标进行修改;
-4. 填写 `Commit changes` 相关内容(Title 必填);
-5. 提交修改,等待 CI 验证和管理员合并。
-
-**若您需要一次提交大量修改,请继续阅读下面的内容**
-
-## 完整流程
-
-1. `fork`本项目;
-2. 克隆(`clone`)你 `fork` 的项目到本地;
-3. 新建分支(`branch`)并检出(`checkout`)新分支;
-4. 添加本项目到你的本地 git 仓库作为上游(`upstream`);
-5. 进行修改,若你的修改包含方法或函数的增减,请记得修改[单元测试文件](tests);
-6. 变基(衍合 `rebase`)你的分支到上游 master 分支;
-7. `push` 你的本地仓库到 GitHub;
-8. 提交 `pull request`;
-9. 等待 CI 验证(若不通过则重复 5~7,GitHub 会自动更新你的 `pull request`);
-10. 等待管理员处理,并及时 `rebase` 你的分支到上游 master 分支(若上游 master 分支有修改)。
-
-*若有必要,可以 `git push -f` 强行推送 rebase 后的分支到自己的 `fork`*
-
-*绝对不可以使用 `git push -f` 强行推送修改到上游*
-
-### 注意事项
-
-* 若对上述流程有任何不清楚的地方,请查阅 GIT 教程,如 [这个](http://backlogtool.com/git-guide/cn/);
-* 对于代码**不同方面**的修改,请在自己 `fork` 的项目中**创建不同的分支**(原因参见`完整流程`第9条备注部分);
-* 变基及交互式变基操作参见 [Git 交互式变基](http://pakchoi.me/2015/03/17/git-interactive-rebase/)
-
-## 推荐资源
-
-### 开发环境
-
-* XAMPP for Windows 5.5.x
-* WampServer (for Windows)
-* upupw Apache PHP5.4 ( for Windows)
-
-或自行安装
-
-- Apache / Nginx
-- PHP 5.4 ~ 5.6
-- MySQL / MariaDB
-
-*Windows 用户推荐添加 PHP bin 目录到 PATH,方便使用 composer*
-
-*Linux 用户自行配置环境, Mac 用户推荐使用内置 Apache 配合 Homebrew 安装 PHP 和 MariaDB*
-
-### 编辑器
-
-Sublime Text 3 + phpfmt 插件
-
-phpfmt 插件参数
-
-```json
-{
- "autocomplete": true,
- "enable_auto_align": true,
- "format_on_save": true,
- "indent_with_space": true,
- "psr1_naming": false,
- "psr2": true,
- "version": 4
-}
-```
-
-或其他 编辑器 / IDE 配合 PSR2 自动格式化工具
-
-### Git GUI
-
-* SourceTree
-* GitHub Desktop
-
-或其他 Git 图形界面客户端
diff --git a/thinkphp/LICENSE.txt b/thinkphp/LICENSE.txt
deleted file mode 100644
index 574a39c..0000000
--- a/thinkphp/LICENSE.txt
+++ /dev/null
@@ -1,32 +0,0 @@
-
-ThinkPHP遵循Apache2开源协议发布,并提供免费使用。
-版权所有Copyright © 2006-2016 by ThinkPHP (http://thinkphp.cn)
-All rights reserved。
-ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
-
-Apache Licence是著名的非盈利开源组织Apache采用的协议。
-该协议和BSD类似,鼓励代码共享和尊重原作者的著作权,
-允许代码修改,再作为开源或商业软件发布。需要满足
-的条件:
-1. 需要给代码的用户一份Apache Licence ;
-2. 如果你修改了代码,需要在被修改的文件中说明;
-3. 在延伸的代码中(修改和有源代码衍生的代码中)需要
-带有原来代码中的协议,商标,专利声明和其他原来作者规
-定需要包含的说明;
-4. 如果再发布的产品中包含一个Notice文件,则在Notice文
-件中需要带有本协议内容。你可以在Notice中增加自己的
-许可,但不可以表现为对Apache Licence构成更改。
-具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
diff --git a/thinkphp/README.md b/thinkphp/README.md
deleted file mode 100644
index 5da1eef..0000000
--- a/thinkphp/README.md
+++ /dev/null
@@ -1,61 +0,0 @@
-ThinkPHP 5.1
-===============
-
-[](https://styleci.io/repos/48530411)
-[](https://travis-ci.org/top-think/framework)
-[](http://codecov.io/github/github/top-think/framework?branch=master)
-[](https://packagist.org/packages/topthink/framework)
-[](https://packagist.org/packages/topthink/framework)
-[](https://packagist.org/packages/topthink/framework)
-[](https://packagist.org/packages/topthink/framework)
-
-ThinkPHP5.1对底层架构做了进一步的改进,减少依赖,其主要特性包括:
-
- + 采用容器统一管理对象
- + 支持Facade
- + 更易用的路由
- + 注解路由支持
- + 路由跨域请求支持
- + 验证类增强
- + 配置和路由目录独立
- + 取消系统常量
- + 类库别名机制
- + 模型和数据库增强
- + 依赖注入完善
- + 支持PSR-3日志规范
-
-### 废除的功能:
-
- + 聚合模型
- + 内置控制器扩展类
- + 模型自动验证
-
-> ThinkPHP5的运行环境要求PHP5.6以上。
-
-
-## 在线手册
-
-+ [完全开发手册](https://www.kancloud.cn/manual/thinkphp5_1)
-+ [升级指导](https://www.kancloud.cn/manual/thinkphp5_1/354155)
-
-## 命名规范
-
-`ThinkPHP5`遵循PSR-2命名规范和PSR-4自动加载规范。
-
-## 参与开发
-
-请参阅 [ThinkPHP5 核心框架包](https://github.com/top-think/framework)。
-
-## 版权信息
-
-ThinkPHP遵循Apache2开源协议发布,并提供免费使用。
-
-本项目包含的第三方源码和二进制文件之版权信息另行标注。
-
-版权所有Copyright © 2006-2018 by ThinkPHP (http://thinkphp.cn)
-
-All rights reserved。
-
-ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
-
-更多细节参阅 [LICENSE.txt](LICENSE.txt)
diff --git a/thinkphp/base.php b/thinkphp/base.php
deleted file mode 100644
index 910ef32..0000000
--- a/thinkphp/base.php
+++ /dev/null
@@ -1,108 +0,0 @@
-
-// +----------------------------------------------------------------------
-namespace think;
-
-// 载入Loader类
-require __DIR__ . '/library/think/Loader.php';
-
-// 注册自动加载
-Loader::register();
-
-//// 注册错误和异常处理机制
-//Error::register();
-//
-//// 实现日志接口
-//if (interface_exists('Psr\Log\LoggerInterface')) {
-// interface LoggerInterface extends \Psr\Log\LoggerInterface
-// {}
-//} else {
-// interface LoggerInterface
-// {}
-//}
-
-
-//通过 Container::getInstance()->bind() 先将核心类库实例化后注册到容器内
-//再通过 Facade::bind() 将核心类转成静态代理,
-//最后使用 Loader::addClassAlias() 给静态代理注册类别名,方便直接静态调用
-
-// 注册核心类到容器
-Container::getInstance()->bind([
- 'app' => App::class,
- 'build' => Build::class,
- 'cache' => Cache::class,
- 'config' => Config::class,
- 'cookie' => Cookie::class,
- 'debug' => Debug::class,
- 'env' => Env::class,
- 'hook' => Hook::class,
- 'lang' => Lang::class,
- 'log' => Log::class,
- 'request' => Request::class,
- 'response' => Response::class,
- 'route' => Route::class,
- 'session' => Session::class,
- 'url' => Url::class,
- 'validate' => Validate::class,
- 'view' => View::class,
- 'middlewareDispatcher' => http\middleware\Dispatcher::class,
- // 接口依赖注入
- 'think\LoggerInterface' => Log::class,
-]);
-
-// 注册核心类的静态代理
-Facade::bind([
- facade\App::class => App::class,
- facade\Build::class => Build::class,
- facade\Cache::class => Cache::class,
- facade\Config::class => Config::class,
- facade\Cookie::class => Cookie::class,
- facade\Debug::class => Debug::class,
- facade\Env::class => Env::class,
- facade\Hook::class => Hook::class,
- facade\Lang::class => Lang::class,
- facade\Log::class => Log::class,
- facade\Request::class => Request::class,
- facade\Response::class => Response::class,
- facade\Route::class => Route::class,
- facade\Session::class => Session::class,
- facade\Url::class => Url::class,
- facade\Validate::class => Validate::class,
- facade\View::class => View::class,
-]);
-
-// 注册类库别名
-Loader::addClassAlias([
- 'App' => facade\App::class,
- 'Build' => facade\Build::class,
- 'Cache' => facade\Cache::class,
- 'Config' => facade\Config::class,
- 'Cookie' => facade\Cookie::class,
- 'Db' => Db::class,
- 'Debug' => facade\Debug::class,
- 'Env' => facade\Env::class,
- 'Facade' => Facade::class,
- 'Hook' => facade\Hook::class,
- 'Lang' => facade\Lang::class,
- 'Log' => facade\Log::class,
- 'Request' => facade\Request::class,
- 'Response' => facade\Response::class,
- 'Route' => facade\Route::class,
- 'Session' => facade\Session::class,
- 'Url' => facade\Url::class,
- 'Validate' => facade\Validate::class,
- 'View' => facade\View::class,
-]);
-
-// 加载惯例配置文件
-facade\Config::set(__include_file(__DIR__ . '/convention.php'));
-
-// 加载composer autofile文件
-Loader::loadComposerAutoloadFiles();
diff --git a/thinkphp/composer.json b/thinkphp/composer.json
deleted file mode 100644
index 3e50496..0000000
--- a/thinkphp/composer.json
+++ /dev/null
@@ -1,35 +0,0 @@
-{
- "name": "topthink/framework",
- "description": "the new thinkphp framework",
- "type": "think-framework",
- "keywords": [
- "framework",
- "thinkphp",
- "ORM"
- ],
- "homepage": "http://thinkphp.cn/",
- "license": "Apache-2.0",
- "authors": [
- {
- "name": "liu21st",
- "email": "liu21st@gmail.com"
- },
- {
- "name": "yunwuxin",
- "email": "448901948@qq.com"
- }
- ],
- "require": {
- "php": ">=5.6.0",
- "topthink/think-installer": "~1.0"
- },
- "require-dev": {
- "phpunit/phpunit": "^5.0|^6.0",
- "johnkary/phpunit-speedtrap": "^1.0",
- "mikey179/vfsStream": "~1.6",
- "phploc/phploc": "2.*",
- "sebastian/phpcpd": "2.*",
- "squizlabs/php_codesniffer": "2.*",
- "phpdocumentor/reflection-docblock": "^2.0"
- }
-}
diff --git a/thinkphp/convention.php b/thinkphp/convention.php
deleted file mode 100644
index 01046c4..0000000
--- a/thinkphp/convention.php
+++ /dev/null
@@ -1,292 +0,0 @@
- [
- // 应用名称
- 'app_name' => '',
- // 应用地址
- 'app_host' => '',
- // 应用调试模式
- 'app_debug' => false,
- // 应用Trace
- 'app_trace' => false,
- // 应用模式状态
- 'app_status' => '',
- // 是否支持多模块
- 'app_multi_module' => true,
- // 入口自动绑定模块
- 'auto_bind_module' => false,
- // 注册的根命名空间
- 'root_namespace' => [],
- // 默认输出类型
- 'default_return_type' => 'html',
- // 默认AJAX 数据返回格式,可选json xml ...
- 'default_ajax_return' => 'json',
- // 默认JSONP格式返回的处理方法
- 'default_jsonp_handler' => 'jsonpReturn',
- // 默认JSONP处理方法
- 'var_jsonp_handler' => 'callback',
- // 默认时区
- 'default_timezone' => 'PRC',
- // 是否开启多语言
- 'lang_switch_on' => false,
- // 默认全局过滤方法 用逗号分隔多个
- 'default_filter' => '',
- // 默认语言
- 'default_lang' => 'zh-cn',
- // 应用类库后缀
- 'class_suffix' => false,
- // 控制器类后缀
- 'controller_suffix' => false,
-
- // +----------------------------------------------------------------------
- // | 模块设置
- // +----------------------------------------------------------------------
-
- // 默认模块名
- 'default_module' => 'index',
- // 禁止访问模块
- 'deny_module_list' => ['common'],
- // 默认控制器名
- 'default_controller' => 'Index',
- // 默认操作名
- 'default_action' => 'index',
- // 默认验证器
- 'default_validate' => '',
- // 默认的空模块名
- 'empty_module' => '',
- // 默认的空控制器名
- 'empty_controller' => 'Error',
- // 操作方法前缀
- 'use_action_prefix' => false,
- // 操作方法后缀
- 'action_suffix' => '',
- // 自动搜索控制器
- 'controller_auto_search' => false,
-
- // +----------------------------------------------------------------------
- // | URL设置
- // +----------------------------------------------------------------------
-
- // PATHINFO变量名 用于兼容模式
- 'var_pathinfo' => 's',
- // 兼容PATH_INFO获取
- 'pathinfo_fetch' => ['ORIG_PATH_INFO', 'REDIRECT_PATH_INFO', 'REDIRECT_URL'],
- // pathinfo分隔符
- 'pathinfo_depr' => '/',
- // HTTPS代理标识
- 'https_agent_name' => '',
- // URL伪静态后缀
- 'url_html_suffix' => 'html',
- // URL普通方式参数 用于自动生成
- 'url_common_param' => false,
- // URL参数方式 0 按名称成对解析 1 按顺序解析
- 'url_param_type' => 0,
- // 是否开启路由延迟解析
- 'url_lazy_route' => false,
- // 是否强制使用路由
- 'url_route_must' => false,
- // 路由是否完全匹配
- 'route_complete_match' => false,
- // 使用注解路由
- 'route_annotation' => false,
- // 域名根,如thinkphp.cn
- 'url_domain_root' => '',
- // 是否自动转换URL中的控制器和操作名
- 'url_convert' => true,
- // 默认的访问控制器层
- 'url_controller_layer' => 'controller',
- // 表单请求类型伪装变量
- 'var_method' => '_method',
- // 表单ajax伪装变量
- 'var_ajax' => '_ajax',
- // 表单pjax伪装变量
- 'var_pjax' => '_pjax',
- // 是否开启请求缓存 true自动缓存 支持设置请求缓存规则
- 'request_cache' => false,
- // 请求缓存有效期
- 'request_cache_expire' => null,
- // 全局请求缓存排除规则
- 'request_cache_except' => [],
-
- // 默认跳转页面对应的模板文件
- 'dispatch_success_tmpl' => __DIR__ . '/tpl/dispatch_jump.tpl',
- 'dispatch_error_tmpl' => __DIR__ . '/tpl/dispatch_jump.tpl',
-
- // +----------------------------------------------------------------------
- // | 异常及错误设置
- // +----------------------------------------------------------------------
-
- // 异常页面的模板文件
- 'exception_tmpl' => __DIR__ . '/tpl/think_exception.tpl',
-
- // 错误显示信息,非调试模式有效
- 'error_message' => '页面错误!请稍后再试~',
- // 显示错误信息
- 'show_error_msg' => false,
- // 异常处理handle类 留空使用 \think\exception\Handle
- 'exception_handle' => '',
- ],
-
- // +----------------------------------------------------------------------
- // | 模板设置
- // +----------------------------------------------------------------------
-
- 'template' => [
- // 模板引擎类型 支持 php think 支持扩展
- 'type' => 'Think',
- // 视图基础目录,配置目录为所有模块的视图起始目录
- 'view_base' => '',
- // 当前模板的视图目录 留空为自动获取
- 'view_path' => '',
- // 模板后缀
- 'view_suffix' => 'html',
- // 模板文件名分隔符
- 'view_depr' => DIRECTORY_SEPARATOR,
- // 模板引擎普通标签开始标记
- 'tpl_begin' => '{',
- // 模板引擎普通标签结束标记
- 'tpl_end' => '}',
- // 标签库标签开始标记
- 'taglib_begin' => '{',
- // 标签库标签结束标记
- 'taglib_end' => '}',
- ],
-
- // +----------------------------------------------------------------------
- // | 日志设置
- // +----------------------------------------------------------------------
-
- 'log' => [
- // 日志记录方式,内置 file socket 支持扩展
- 'type' => 'File',
- // 日志保存目录
- //'path' => LOG_PATH,
- // 日志记录级别
- 'level' => [],
- // 是否记录trace信息到日志
- 'record_trace' => false,
- ],
-
- // +----------------------------------------------------------------------
- // | Trace设置 开启 app_trace 后 有效
- // +----------------------------------------------------------------------
- 'trace' => [
- // 内置Html Console 支持扩展
- 'type' => 'Html',
- 'file' => __DIR__ . '/tpl/page_trace.tpl',
- ],
-
- // +----------------------------------------------------------------------
- // | 缓存设置
- // +----------------------------------------------------------------------
-
- 'cache' => [
- // 驱动方式
- 'type' => 'File',
- // 缓存保存目录
- //'path' => CACHE_PATH,
- // 缓存前缀
- 'prefix' => '',
- // 缓存有效期 0表示永久缓存
- 'expire' => 0,
- ],
-
- // +----------------------------------------------------------------------
- // | 会话设置
- // +----------------------------------------------------------------------
-
- 'session' => [
- 'id' => '',
- // SESSION_ID的提交变量,解决flash上传跨域
- 'var_session_id' => '',
- // SESSION 前缀
- 'prefix' => 'think',
- // 驱动方式 支持redis memcache memcached
- 'type' => '',
- // 是否自动开启 SESSION
- 'auto_start' => true,
- 'httponly' => true,
- 'secure' => false,
- ],
-
- // +----------------------------------------------------------------------
- // | Cookie设置
- // +----------------------------------------------------------------------
- 'cookie' => [
- // cookie 名称前缀
- 'prefix' => '',
- // cookie 保存时间
- 'expire' => 0,
- // cookie 保存路径
- 'path' => '/',
- // cookie 有效域名
- 'domain' => '',
- // cookie 启用安全传输
- 'secure' => false,
- // httponly设置
- 'httponly' => '',
- // 是否使用 setcookie
- 'setcookie' => true,
- ],
-
- // +----------------------------------------------------------------------
- // | 数据库设置
- // +----------------------------------------------------------------------
-
- 'database' => [
- // 数据库类型
- 'type' => 'mysql',
- // 数据库连接DSN配置
- 'dsn' => '',
- // 服务器地址
- 'hostname' => '127.0.0.1',
- // 数据库名
- 'database' => '',
- // 数据库用户名
- 'username' => 'root',
- // 数据库密码
- 'password' => '',
- // 数据库连接端口
- 'hostport' => '',
- // 数据库连接参数
- 'params' => [],
- // 数据库编码默认采用utf8
- 'charset' => 'utf8',
- // 数据库表前缀
- 'prefix' => '',
- // 数据库调试模式
- 'debug' => false,
- // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
- 'deploy' => 0,
- // 数据库读写是否分离 主从式有效
- 'rw_separate' => false,
- // 读写分离后 主服务器数量
- 'master_num' => 1,
- // 指定从服务器序号
- 'slave_no' => '',
- // 是否严格检查字段是否存在
- 'fields_strict' => true,
- // 数据集返回类型
- 'resultset_type' => 'array',
- // 自动写入时间戳字段
- 'auto_timestamp' => false,
- // 时间字段取出后的默认时间格式
- 'datetime_format' => 'Y-m-d H:i:s',
- // 是否需要进行SQL性能分析
- 'sql_explain' => false,
- // 查询对象
- 'query' => '\\think\\db\\Query',
- ],
-
- //分页配置
- 'paginate' => [
- 'type' => 'bootstrap',
- 'var_page' => 'page',
- 'list_rows' => 15,
- ],
-
-];
diff --git a/thinkphp/helper.php b/thinkphp/helper.php
deleted file mode 100644
index 461460e..0000000
--- a/thinkphp/helper.php
+++ /dev/null
@@ -1,691 +0,0 @@
-
-// +----------------------------------------------------------------------
-
-//------------------------
-// ThinkPHP 助手函数
-//-------------------------
-
-use think\Container;
-use think\Db;
-use think\exception\HttpException;
-use think\exception\HttpResponseException;
-use think\facade\Cache;
-use think\facade\Config;
-use think\facade\Cookie;
-use think\facade\Debug;
-use think\facade\Env;
-use think\facade\Hook;
-use think\facade\Lang;
-use think\facade\Log;
-use think\facade\Request;
-use think\facade\Route;
-use think\facade\Session;
-use think\facade\Url;
-use think\Response;
-use think\route\RuleItem;
-
-if (!function_exists('abort')) {
- /**
- * 抛出HTTP异常
- * @param integer|Response $code 状态码 或者 Response对象实例
- * @param string $message 错误信息
- * @param array $header 参数
- */
- function abort($code, $message = null, $header = [])
- {
- if ($code instanceof Response) {
- throw new HttpResponseException($code);
- } else {
- throw new HttpException($code, $message, null, $header);
- }
- }
-}
-
-if (!function_exists('action')) {
- /**
- * 调用模块的操作方法 参数格式 [模块/控制器/]操作
- * @param string $url 调用地址
- * @param string|array $vars 调用参数 支持字符串和数组
- * @param string $layer 要调用的控制层名称
- * @param bool $appendSuffix 是否添加类名后缀
- * @return mixed
- */
- function action($url, $vars = [], $layer = 'controller', $appendSuffix = false)
- {
- return app()->action($url, $vars, $layer, $appendSuffix);
- }
-}
-
-if (!function_exists('app')) {
- /**
- * 快速获取容器中的实例 支持依赖注入
- * @param string $name 类名或标识 默认获取当前应用实例
- * @param array $args 参数
- * @param bool $newInstance 是否每次创建新的实例
- * @return object
- */
- function app($name = 'think\App', $args = [], $newInstance = false)
- {
- return Container::get($name, $args, $newInstance);
- }
-}
-
-if (!function_exists('behavior')) {
- /**
- * 执行某个行为(run方法) 支持依赖注入
- * @param mixed $behavior 行为类名或者别名
- * @param mixed $args 参数
- * @return mixed
- */
- function behavior($behavior, $args = null)
- {
- return Hook::exec($behavior, $args);
- }
-}
-
-if (!function_exists('bind')) {
- /**
- * 绑定一个类到容器
- * @access public
- * @param string $abstract 类标识、接口
- * @param mixed $concrete 要绑定的类、闭包或者实例
- * @return Container
- */
- function bind($abstract, $concrete = null)
- {
- return Container::getInstance()->bind($abstract, $concrete);
- }
-}
-
-if (!function_exists('cache')) {
- /**
- * 缓存管理
- * @param mixed $name 缓存名称,如果为数组表示进行缓存设置
- * @param mixed $value 缓存值
- * @param mixed $options 缓存参数
- * @param string $tag 缓存标签
- * @return mixed
- */
- function cache($name, $value = '', $options = null, $tag = null)
- {
- if (is_array($options)) {
- // 缓存操作的同时初始化
- Cache::connect($options);
- } elseif (is_array($name)) {
- // 缓存初始化
- return Cache::connect($name);
- }
-
- if ('' === $value) {
- // 获取缓存
- return 0 === strpos($name, '?') ? Cache::has(substr($name, 1)) : Cache::get($name);
- } elseif (is_null($value)) {
- // 删除缓存
- return Cache::rm($name);
- } else {
- // 缓存数据
- if (is_array($options)) {
- $expire = isset($options['expire']) ? $options['expire'] : null; //修复查询缓存无法设置过期时间
- } else {
- $expire = is_numeric($options) ? $options : null; //默认快捷缓存设置过期时间
- }
-
- if (is_null($tag)) {
- return Cache::set($name, $value, $expire);
- } else {
- return Cache::tag($tag)->set($name, $value, $expire);
- }
- }
- }
-}
-
-if (!function_exists('call')) {
- /**
- * 调用反射执行callable 支持依赖注入
- * @param mixed $callable 支持闭包等callable写法
- * @param array $args 参数
- * @return mixed
- */
- function call($callable, $args = [])
- {
- return Container::getInstance()->invoke($callable, $args);
- }
-}
-
-if (!function_exists('class_basename')) {
- /**
- * 获取类名(不包含命名空间)
- *
- * @param string|object $class
- * @return string
- */
- function class_basename($class)
- {
- $class = is_object($class) ? get_class($class) : $class;
- return basename(str_replace('\\', '/', $class));
- }
-}
-
-if (!function_exists('class_uses_recursive')) {
- /**
- *获取一个类里所有用到的trait,包括父类的
- *
- * @param $class
- * @return array
- */
- function class_uses_recursive($class)
- {
- if (is_object($class)) {
- $class = get_class($class);
- }
-
- $results = [];
- $classes = array_merge([$class => $class], class_parents($class));
- foreach ($classes as $class) {
- $results += trait_uses_recursive($class);
- }
-
- return array_unique($results);
- }
-}
-
-if (!function_exists('config')) {
- /**
- * 获取和设置配置参数
- * @param string|array $name 参数名
- * @param mixed $value 参数值
- * @return mixed
- */
- function config($name = '', $value = null)
- {
- if (is_null($value) && is_string($name)) {
- if ('.' == substr($name, -1)) {
- return Config::pull(substr($name, 0, -1));
- }
-
- return 0 === strpos($name, '?') ? Config::has(substr($name, 1)) : Config::get($name);
- } else {
- return Config::set($name, $value);
- }
- }
-}
-
-if (!function_exists('container')) {
- /**
- * 获取容器对象实例
- * @return Container
- */
- function container()
- {
- return Container::getInstance();
- }
-}
-
-if (!function_exists('controller')) {
- /**
- * 实例化控制器 格式:[模块/]控制器
- * @param string $name 资源地址
- * @param string $layer 控制层名称
- * @param bool $appendSuffix 是否添加类名后缀
- * @return \think\Controller
- */
- function controller($name, $layer = 'controller', $appendSuffix = false)
- {
- return app()->controller($name, $layer, $appendSuffix);
- }
-}
-
-if (!function_exists('cookie')) {
- /**
- * Cookie管理
- * @param string|array $name cookie名称,如果为数组表示进行cookie设置
- * @param mixed $value cookie值
- * @param mixed $option 参数
- * @return mixed
- */
- function cookie($name, $value = '', $option = null)
- {
- if (is_array($name)) {
- // 初始化
- Cookie::init($name);
- } elseif (is_null($name)) {
- // 清除
- Cookie::clear($value);
- } elseif ('' === $value) {
- // 获取
- return 0 === strpos($name, '?') ? Cookie::has(substr($name, 1), $option) : Cookie::get($name);
- } elseif (is_null($value)) {
- // 删除
- return Cookie::delete($name);
- } else {
- // 设置
- return Cookie::set($name, $value, $option);
- }
- }
-}
-
-if (!function_exists('db')) {
- /**
- * 实例化数据库类
- * @param string $name 操作的数据表名称(不含前缀)
- * @param array|string $config 数据库配置参数
- * @param bool $force 是否强制重新连接
- * @return \think\db\Query
- */
- function db($name = '', $config = [], $force = true)
- {
- return Db::connect($config, $force)->name($name);
- }
-}
-
-if (!function_exists('debug')) {
- /**
- * 记录时间(微秒)和内存使用情况
- * @param string $start 开始标签
- * @param string $end 结束标签
- * @param integer|string $dec 小数位 如果是m 表示统计内存占用
- * @return mixed
- */
- function debug($start, $end = '', $dec = 6)
- {
- if ('' == $end) {
- Debug::remark($start);
- } else {
- return 'm' == $dec ? Debug::getRangeMem($start, $end) : Debug::getRangeTime($start, $end, $dec);
- }
- }
-}
-
-if (!function_exists('dump')) {
- /**
- * 浏览器友好的变量输出
- * @param mixed $var 变量
- * @param boolean $echo 是否输出 默认为true 如果为false 则返回输出字符串
- * @param string $label 标签 默认为空
- * @return void|string
- */
- function dump($var, $echo = true, $label = null)
- {
- return Debug::dump($var, $echo, $label);
- }
-}
-
-if (!function_exists('env')) {
- /**
- * 获取环境变量值
- * @access public
- * @param string $name 环境变量名(支持二级 .号分割)
- * @param string $default 默认值
- * @return mixed
- */
- function env($name = null, $default = null)
- {
- return Env::get($name, $default);
- }
-}
-
-if (!function_exists('exception')) {
- /**
- * 抛出异常处理
- *
- * @param string $msg 异常消息
- * @param integer $code 异常代码 默认为0
- * @param string $exception 异常类
- *
- * @throws Exception
- */
- function exception($msg, $code = 0, $exception = '')
- {
- $e = $exception ?: '\think\Exception';
- throw new $e($msg, $code);
- }
-}
-
-if (!function_exists('halt')) {
- /**
- * 调试变量并且中断输出
- * @param mixed $var 调试变量或者信息
- */
- function halt($var)
- {
- dump($var);
-
- throw new HttpResponseException(new Response);
- }
-}
-
-if (!function_exists('input')) {
- /**
- * 获取输入数据 支持默认值和过滤
- * @param string $key 获取的变量名
- * @param mixed $default 默认值
- * @param string $filter 过滤方法
- * @return mixed
- */
- function input($key = '', $default = null, $filter = null)
- {
- if (0 === strpos($key, '?')) {
- $key = substr($key, 1);
- $has = true;
- }
-
- if ($pos = strpos($key, '.')) {
- // 指定参数来源
- $method = substr($key, 0, $pos);
- if (in_array($method, ['get', 'post', 'put', 'patch', 'delete', 'route', 'param', 'request', 'session', 'cookie', 'server', 'env', 'path', 'file'])) {
- $key = substr($key, $pos + 1);
- } else {
- $method = 'param';
- }
- } else {
- // 默认为自动判断
- $method = 'param';
- }
-
- if (isset($has)) {
- return request()->has($key, $method, $default);
- } else {
- return request()->$method($key, $default, $filter);
- }
- }
-}
-
-if (!function_exists('json')) {
- /**
- * 获取\think\response\Json对象实例
- * @param mixed $data 返回的数据
- * @param integer $code 状态码
- * @param array $header 头部
- * @param array $options 参数
- * @return \think\response\Json
- */
- function json($data = [], $code = 200, $header = [], $options = [])
- {
- return Response::create($data, 'json', $code, $header, $options);
- }
-}
-
-if (!function_exists('jsonp')) {
- /**
- * 获取\think\response\Jsonp对象实例
- * @param mixed $data 返回的数据
- * @param integer $code 状态码
- * @param array $header 头部
- * @param array $options 参数
- * @return \think\response\Jsonp
- */
- function jsonp($data = [], $code = 200, $header = [], $options = [])
- {
- return Response::create($data, 'jsonp', $code, $header, $options);
- }
-}
-
-if (!function_exists('lang')) {
- /**
- * 获取语言变量值
- * @param string $name 语言变量名
- * @param array $vars 动态变量值
- * @param string $lang 语言
- * @return mixed
- */
- function lang($name, $vars = [], $lang = '')
- {
- return Lang::get($name, $vars, $lang);
- }
-}
-
-if (!function_exists('model')) {
- /**
- * 实例化Model
- * @param string $name Model名称
- * @param string $layer 业务层名称
- * @param bool $appendSuffix 是否添加类名后缀
- * @return \think\Model
- */
- function model($name = '', $layer = 'model', $appendSuffix = false)
- {
- return app()->model($name, $layer, $appendSuffix);
- }
-}
-
-if (!function_exists('parse_name')) {
- /**
- * 字符串命名风格转换
- * type 0 将Java风格转换为C的风格 1 将C风格转换为Java的风格
- * @param string $name 字符串
- * @param integer $type 转换类型
- * @param bool $ucfirst 首字母是否大写(驼峰规则)
- * @return string
- */
- function parse_name($name, $type = 0, $ucfirst = true)
- {
- if ($type) {
- $name = preg_replace_callback('/_([a-zA-Z])/', function ($match) {
- return strtoupper($match[1]);
- }, $name);
-
- return $ucfirst ? ucfirst($name) : lcfirst($name);
- } else {
- return strtolower(trim(preg_replace("/[A-Z]/", "_\\0", $name), "_"));
- }
- }
-}
-
-if (!function_exists('redirect')) {
- /**
- * 获取\think\response\Redirect对象实例
- * @param mixed $url 重定向地址 支持Url::build方法的地址
- * @param array|integer $params 额外参数
- * @param integer $code 状态码
- * @return \think\response\Redirect
- */
- function redirect($url = [], $params = [], $code = 302)
- {
- if (is_integer($params)) {
- $code = $params;
- $params = [];
- }
-
- return Response::create($url, 'redirect', $code)->params($params);
- }
-}
-
-if (!function_exists('request')) {
- /**
- * 获取当前Request对象实例
- * @return Request
- */
- function request()
- {
- return app('request');
- }
-}
-
-if (!function_exists('response')) {
- /**
- * 创建普通 Response 对象实例
- * @param mixed $data 输出数据
- * @param int|string $code 状态码
- * @param array $header 头信息
- * @param string $type
- * @return Response
- */
- function response($data = [], $code = 200, $header = [], $type = 'html')
- {
- return Response::create($data, $type, $code, $header);
- }
-}
-
-if (!function_exists('route')) {
- /**
- * 路由注册
- * @param string $rule 路由规则
- * @param mixed $route 路由地址
- * @param array $option 路由参数
- * @param array $pattern 变量规则
- * @return RuleItem
- */
- function route($rule, $route, $option = [], $pattern = [])
- {
- return Route::rule($rule, $route, '*', $option, $pattern);
- }
-}
-
-if (!function_exists('session')) {
- /**
- * Session管理
- * @param string|array $name session名称,如果为数组表示进行session设置
- * @param mixed $value session值
- * @param string $prefix 前缀
- * @return mixed
- */
- function session($name, $value = '', $prefix = null)
- {
- if (is_array($name)) {
- // 初始化
- Session::init($name);
- } elseif (is_null($name)) {
- // 清除
- Session::clear($value);
- } elseif ('' === $value) {
- // 判断或获取
- return 0 === strpos($name, '?') ? Session::has(substr($name, 1), $prefix) : Session::get($name, $prefix);
- } elseif (is_null($value)) {
- // 删除
- return Session::delete($name, $prefix);
- } else {
- // 设置
- return Session::set($name, $value, $prefix);
- }
- }
-}
-
-if (!function_exists('token')) {
- /**
- * 生成表单令牌
- * @param string $name 令牌名称
- * @param mixed $type 令牌生成方法
- * @return string
- */
- function token($name = '__token__', $type = 'md5')
- {
- $token = Request::token($name, $type);
-
- return '';
- }
-}
-
-if (!function_exists('trace')) {
- /**
- * 记录日志信息
- * @param mixed $log log信息 支持字符串和数组
- * @param string $level 日志级别
- * @return array|void
- */
- function trace($log = '[think]', $level = 'log')
- {
- if ('[think]' === $log) {
- return Log::getLog();
- } else {
- Log::record($log, $level);
- }
- }
-}
-
-if (!function_exists('trait_uses_recursive')) {
- /**
- * 获取一个trait里所有引用到的trait
- *
- * @param string $trait
- * @return array
- */
- function trait_uses_recursive($trait)
- {
- $traits = class_uses($trait);
- foreach ($traits as $trait) {
- $traits += trait_uses_recursive($trait);
- }
-
- return $traits;
- }
-}
-
-if (!function_exists('url')) {
- /**
- * Url生成
- * @param string $url 路由地址
- * @param string|array $vars 变量
- * @param bool|string $suffix 生成的URL后缀
- * @param bool|string $domain 域名
- * @return string
- */
- function url($url = '', $vars = '', $suffix = true, $domain = false)
- {
- return Url::build($url, $vars, $suffix, $domain);
- }
-}
-
-if (!function_exists('validate')) {
- /**
- * 实例化验证器
- * @param string $name 验证器名称
- * @param string $layer 业务层名称
- * @param bool $appendSuffix 是否添加类名后缀
- * @return \think\Validate
- */
- function validate($name = '', $layer = 'validate', $appendSuffix = false)
- {
- return app()->validate($name, $layer, $appendSuffix);
- }
-}
-
-if (!function_exists('view')) {
- /**
- * 渲染模板输出
- * @param string $template 模板文件
- * @param array $vars 模板变量
- * @param integer $code 状态码
- * @param callable $filer 内容过滤
- * @return \think\response\View
- */
- function view($template = '', $vars = [], $code = 200, $filter = null)
- {
- return Response::create($template, 'view', $code)->assign($vars)->filter($filter);
- }
-}
-
-if (!function_exists('widget')) {
- /**
- * 渲染输出Widget
- * @param string $name Widget名称
- * @param array $data 传入的参数
- * @return mixed
- */
- function widget($name, $data = [])
- {
- return app()->action($name, $data, 'widget');
- }
-}
-
-if (!function_exists('xml')) {
- /**
- * 获取\think\response\Xml对象实例
- * @param mixed $data 返回的数据
- * @param integer $code 状态码
- * @param array $header 头部
- * @param array $options 参数
- * @return \think\response\Xml
- */
- function xml($data = [], $code = 200, $header = [], $options = [])
- {
- return Response::create($data, 'xml', $code, $header, $options);
- }
-}
diff --git a/thinkphp/lang/zh-cn.php b/thinkphp/lang/zh-cn.php
deleted file mode 100644
index dd8084d..0000000
--- a/thinkphp/lang/zh-cn.php
+++ /dev/null
@@ -1,135 +0,0 @@
-
-// +----------------------------------------------------------------------
-
-// 核心中文语言包
-return [
- // 系统错误提示
- 'Undefined variable' => '未定义变量',
- 'Undefined index' => '未定义数组索引',
- 'Undefined offset' => '未定义数组下标',
- 'Parse error' => '语法解析错误',
- 'Type error' => '类型错误',
- 'Fatal error' => '致命错误',
- 'syntax error' => '语法错误',
-
- // 框架核心错误提示
- 'dispatch type not support' => '不支持的调度类型',
- 'method param miss' => '方法参数错误',
- 'method not exists' => '方法不存在',
- 'module not exists' => '模块不存在',
- 'controller not exists' => '控制器不存在',
- 'class not exists' => '类不存在',
- 'property not exists' => '类的属性不存在',
- 'template not exists' => '模板文件不存在',
- 'illegal controller name' => '非法的控制器名称',
- 'illegal action name' => '非法的操作名称',
- 'url suffix deny' => '禁止的URL后缀访问',
- 'Route Not Found' => '当前访问路由未定义',
- 'Undefined db type' => '未定义数据库类型',
- 'variable type error' => '变量类型错误',
- 'PSR-4 error' => 'PSR-4 规范错误',
- 'not support total' => '简洁模式下不能获取数据总数',
- 'not support last' => '简洁模式下不能获取最后一页',
- 'error session handler' => '错误的SESSION处理器类',
- 'not allow php tag' => '模板不允许使用PHP语法',
- 'not support' => '不支持',
- 'redisd master' => 'Redisd 主服务器错误',
- 'redisd slave' => 'Redisd 从服务器错误',
- 'must run at sae' => '必须在SAE运行',
- 'memcache init error' => '未开通Memcache服务,请在SAE管理平台初始化Memcache服务',
- 'KVDB init error' => '没有初始化KVDB,请在SAE管理平台初始化KVDB服务',
- 'fields not exists' => '数据表字段不存在',
- 'where express error' => '查询表达式错误',
- 'no data to update' => '没有任何数据需要更新',
- 'miss data to insert' => '缺少需要写入的数据',
- 'miss complex primary data' => '缺少复合主键数据',
- 'miss update condition' => '缺少更新条件',
- 'model data Not Found' => '模型数据不存在',
- 'table data not Found' => '表数据不存在',
- 'delete without condition' => '没有条件不会执行删除操作',
- 'miss relation data' => '缺少关联表数据',
- 'tag attr must' => '模板标签属性必须',
- 'tag error' => '模板标签错误',
- 'cache write error' => '缓存写入失败',
- 'sae mc write error' => 'SAE mc 写入错误',
- 'route name not exists' => '路由标识不存在(或参数不够)',
- 'invalid request' => '非法请求',
- 'bind attr has exists' => '模型的属性已经存在',
- 'relation data not exists' => '关联数据不存在',
- 'relation not support' => '关联不支持',
- 'chunk not support order' => 'Chunk不支持调用order方法',
-
- // 上传错误信息
- 'unknown upload error' => '未知上传错误!',
- 'file write error' => '文件写入失败!',
- 'upload temp dir not found' => '找不到临时文件夹!',
- 'no file to uploaded' => '没有文件被上传!',
- 'only the portion of file is uploaded' => '文件只有部分被上传!',
- 'upload File size exceeds the maximum value' => '上传文件大小超过了最大值!',
- 'upload write error' => '文件上传保存错误!',
- 'has the same filename: {:filename}' => '存在同名文件:{:filename}',
- 'upload illegal files' => '非法上传文件',
- 'illegal image files' => '非法图片文件',
- 'extensions to upload is not allowed' => '上传文件后缀不允许',
- 'mimetype to upload is not allowed' => '上传文件MIME类型不允许!',
- 'filesize not match' => '上传文件大小不符!',
- 'directory {:path} creation failed' => '目录 {:path} 创建失败!',
-
- // Validate Error Message
- ':attribute require' => ':attribute不能为空',
- ':attribute must' => ':attribute必须',
- ':attribute must be numeric' => ':attribute必须是数字',
- ':attribute must be integer' => ':attribute必须是整数',
- ':attribute must be float' => ':attribute必须是浮点数',
- ':attribute must be bool' => ':attribute必须是布尔值',
- ':attribute not a valid email address' => ':attribute格式不符',
- ':attribute not a valid mobile' => ':attribute格式不符',
- ':attribute must be a array' => ':attribute必须是数组',
- ':attribute must be yes,on or 1' => ':attribute必须是yes、on或者1',
- ':attribute not a valid datetime' => ':attribute不是一个有效的日期或时间格式',
- ':attribute not a valid file' => ':attribute不是有效的上传文件',
- ':attribute not a valid image' => ':attribute不是有效的图像文件',
- ':attribute must be alpha' => ':attribute只能是字母',
- ':attribute must be alpha-numeric' => ':attribute只能是字母和数字',
- ':attribute must be alpha-numeric, dash, underscore' => ':attribute只能是字母、数字和下划线_及破折号-',
- ':attribute not a valid domain or ip' => ':attribute不是有效的域名或者IP',
- ':attribute must be chinese' => ':attribute只能是汉字',
- ':attribute must be chinese or alpha' => ':attribute只能是汉字、字母',
- ':attribute must be chinese,alpha-numeric' => ':attribute只能是汉字、字母和数字',
- ':attribute must be chinese,alpha-numeric,underscore, dash' => ':attribute只能是汉字、字母、数字和下划线_及破折号-',
- ':attribute not a valid url' => ':attribute不是有效的URL地址',
- ':attribute not a valid ip' => ':attribute不是有效的IP地址',
- ':attribute must be dateFormat of :rule' => ':attribute必须使用日期格式 :rule',
- ':attribute must be in :rule' => ':attribute必须在 :rule 范围内',
- ':attribute be notin :rule' => ':attribute不能在 :rule 范围内',
- ':attribute must between :1 - :2' => ':attribute只能在 :1 - :2 之间',
- ':attribute not between :1 - :2' => ':attribute不能在 :1 - :2 之间',
- 'size of :attribute must be :rule' => ':attribute长度不符合要求 :rule',
- 'max size of :attribute must be :rule' => ':attribute长度不能超过 :rule',
- 'min size of :attribute must be :rule' => ':attribute长度不能小于 :rule',
- ':attribute cannot be less than :rule' => ':attribute日期不能小于 :rule',
- ':attribute cannot exceed :rule' => ':attribute日期不能超过 :rule',
- ':attribute not within :rule' => '不在有效期内 :rule',
- 'access IP is not allowed' => '不允许的IP访问',
- 'access IP denied' => '禁止的IP访问',
- ':attribute out of accord with :2' => ':attribute和确认字段:2不一致',
- ':attribute cannot be same with :2' => ':attribute和比较字段:2不能相同',
- ':attribute must greater than or equal :rule' => ':attribute必须大于等于 :rule',
- ':attribute must greater than :rule' => ':attribute必须大于 :rule',
- ':attribute must less than or equal :rule' => ':attribute必须小于等于 :rule',
- ':attribute must less than :rule' => ':attribute必须小于 :rule',
- ':attribute must equal :rule' => ':attribute必须等于 :rule',
- ':attribute has exists' => ':attribute已存在',
- ':attribute not conform to the rules' => ':attribute不符合指定规则',
- 'invalid Request method' => '无效的请求类型',
- 'invalid token' => '令牌数据无效',
- 'not conform to the rules' => '规则错误',
-];
diff --git a/thinkphp/library/think/App.php b/thinkphp/library/think/App.php
deleted file mode 100644
index ad1fefd..0000000
--- a/thinkphp/library/think/App.php
+++ /dev/null
@@ -1,946 +0,0 @@
-
-// +----------------------------------------------------------------------
-
-namespace think;
-
-use think\exception\ClassNotFoundException;
-use think\exception\HttpResponseException;
-use think\route\Dispatch;
-
-/**
- * App 应用管理
- */
-class App implements \ArrayAccess
-{
- const VERSION = '5.1.5';
-
- /**
- * 当前模块路径
- * @var string
- */
- protected $modulePath;
-
- /**
- * 应用调试模式
- * @var bool
- */
- protected $debug = true;
-
- /**
- * 应用开始时间
- * @var float
- */
- protected $beginTime;
-
- /**
- * 应用内存初始占用
- * @var integer
- */
- protected $beginMem;
-
- /**
- * 应用类库命名空间
- * @var string
- */
- protected $namespace = 'app';
-
- /**
- * 应用类库后缀
- * @var bool
- */
- protected $suffix = false;
-
- /**
- * 严格路由检测
- * @var bool
- */
- protected $routeMust;
-
- /**
- * 应用类库目录
- * @var string
- */
- protected $appPath;
-
- /**
- * 框架目录
- * @var string
- */
- protected $thinkPath;
-
- /**
- * 应用根目录
- * @var string
- */
- protected $rootPath;
-
- /**
- * 运行时目录
- * @var string
- */
- protected $runtimePath;
-
- /**
- * 配置目录
- * @var string
- */
- protected $configPath;
-
- /**
- * 路由目录
- * @var string
- */
- protected $routePath;
-
- /**
- * 配置后缀
- * @var string
- */
- protected $configExt;
-
- /**
- * 应用调度实例
- * @var Dispatch
- */
- protected $dispatch;
-
- /**
- * 容器对象实例
- * @var Container
- */
- protected $container;
-
- /**
- * 绑定模块(控制器)
- * @var string
- */
- protected $bind;
-
- public function __construct($appPath = '')
- {
- $this->appPath = $appPath ?: realpath(dirname($_SERVER['SCRIPT_FILENAME']) . '/../application') . '/';
- $this->container = Container::getInstance();
- }
-
- /**
- * 绑定模块或者控制器
- * @access public
- * @param string $bind
- * @return $this
- */
- public function bind($bind)
- {
- $this->bind = $bind;
- return $this;
- }
-
- /**
- * 设置应用类库目录
- * @access public
- * @param string $path 路径
- * @return $this
- */
- public function path($path)
- {
- $this->appPath = $path;
- return $this;
- }
-
- /**
- * 初始化应用
- * @access public
- * @return void
- */
- public function initialize()
- {
- //返回当前 Unix 时间戳的微秒数
- $this->beginTime = microtime(true);
-
- //返回分配给 PHP 的内存量
- $this->beginMem = memory_get_usage();
-
- //函数返回路径中的目录部分
- // dirname(__DIR__) D:\wamp\www\tp5\thinkphp\library
- // dirname(dirname(__DIR__)) D:\wamp\www\tp5\thinkphp
- $this->thinkPath = dirname(dirname(__DIR__)) . '/'; // D:\wamp\www\tp5\thinkphp/
-
- //realpath() 函数返回绝对路径。
- // $this->appPath D:\wamp\www\tp5\application/
- $this->rootPath = dirname(realpath($this->appPath)) . '/'; // D:\wamp\www\tp5/
- $this->runtimePath = $this->rootPath . 'runtime/'; // D:\wamp\www\tp5/runtime/
- $this->routePath = $this->rootPath . 'route/'; // D:\wamp\www\tp5/route/
- $this->configPath = $this->rootPath . 'config/'; // D:\wamp\www\tp5/config/
-
- // 设置路径环境变量
- //$this->env think\Env
- $this->env->set([
- 'think_path' => $this->thinkPath, // D:\wamp\www\tp5\thinkphp/
- 'root_path' => $this->rootPath, // D:\wamp\www\tp5/
- 'app_path' => $this->appPath, // D:\wamp\www\tp5\application/ 应用所在的文件夹
- 'config_path' => $this->configPath, // D:\wamp\www\tp5/config/
- 'route_path' => $this->routePath, // D:\wamp\www\tp5/route/
- 'runtime_path' => $this->runtimePath, // D:\wamp\www\tp5/runtime/
- 'extend_path' => $this->rootPath . 'extend/', // D:\wamp\www\tp5/extend/
- 'vendor_path' => $this->rootPath . 'vendor/', // D:\wamp\www\tp5/vendor/
- ]);
-
- // 加载环境变量配置文件
- // is_file() 函数检查指定的文件名是否存在 文件存在则返回 true。
- if (is_file($this->rootPath . '.env')) {
- // 获取.env的配置信息 内容格式为.ini语法
- $this->env->load($this->rootPath . '.env');
- }
-
- $this->namespace = $this->env->get('app_namespace', $this->namespace); //返回app // $this->namespace
-
- $this->env->set('app_namespace', $this->namespace);
-
- // 注册应用命名空间 $this->appPath [指定应用所在的文件夹 D:\wamp\www\tp5\application/]
- Loader::addNamespace($this->namespace, $this->appPath);
-
- // 配置后缀
- $this->configExt = $this->env->get('config_ext', '.php');
-
- // 初始化应用
- $this->init();
-
- // 开启类名后缀 实际是查看config 内 app内的 class_suffix 值,默认为false
- $this->suffix = $this->config('app.class_suffix');
-
- // 应用调试模式
- // 如果app_debug 没有设置 则启用 $this->config('app.app_debug')的值 默认为false
- $this->debug = $this->env->get('app_debug', $this->config('app.app_debug'));
- //获取的值设置为 app_debug 的值给予下次调用
- $this->env->set('app_debug', $this->debug);
-
- if (!$this->debug) {
- // 非调试模式 关闭(Off)错误
- ini_set('display_errors', 'Off');
- } elseif (PHP_SAPI != 'cli') {
- //开启调试后切非cli格式 执行
- //重新申请一块比较大的buffer
- if (ob_get_level() > 0) {
- $output = ob_get_clean();
- }
- ob_start();
- if (!empty($output)) {
- echo $output;
- }
- }
-
- // 注册根命名空间
- // root_namespace 默认为 空数组
- if (!empty($this->config('app.root_namespace'))) {
- //等于非空数组时执行
- Loader::addNamespace($this->config('app.root_namespace'));
- }
-
- // 注册类库别名
- // alias 主页为空
- Loader::addClassAlias($this->config->pull('alias'));
-
- // 设置系统时区
- date_default_timezone_set($this->config('app.default_timezone'));
-
- // 监听app_init
- $this->hook->listen('app_init',['ceshi','TESTT']);
- }
-
- /**
- * 初始化应用或模块
- * @access public
- * @param string $module 模块名
- * @return void
- */
- public function init($module = '')
- {
- // 定位模块目录文件名,指定当前模块的文件夹名称
- $module = $module ? $module . DIRECTORY_SEPARATOR : '';
-
- //指定当前模块的文件夹目录
- $path = $this->appPath . $module;
-
- // 加载初始化文件
- // 检测init.php 是否存在
- if (is_file($path . 'init.php')) {
- include $path . 'init.php';
- //检测根目录下的是否存在 D:\wamp\www\tp5/runtime/
- } elseif (is_file($this->runtimePath . $module . 'init.php')) {
- include $this->runtimePath . $module . 'init.php';
- } else {
- // 加载行为扩展文件
- if (is_file($path . 'tags.php')) {
- // $this->hook think\Hook
- // 注册钩子
- $this->hook->import(include $path . 'tags.php');
- }
-
- // 加载application下的 common.php 公共文件
- if (is_file($path . 'common.php')) {
- include $path . 'common.php';
- }
-
- //$module 等于空 加载系统助手函数
- if ('' == $module) {
- // 加载系统助手函数 D:\wamp\www\tp5\thinkphp/
- include $this->thinkPath . 'helper.php';
- }
-
- // 注册服务的容器对象实例
- if (is_file($path . 'provider.php')) {
- $this->container->bind(include $path . 'provider.php');
- }
-
- // 自动读取配置文件
- //模块下的配置文件夹不存在就加载 D:\wamp\www\tp5/config/ 内的
- if (is_dir($path . 'config')) {
- $dir = $path . 'config';
- } elseif (is_dir($this->configPath . $module)) {
- $dir = $this->configPath . $module;
- }
-
- // scandir($dir) 列出 $dir 目录中的文件和目录
- $files = isset($dir) ? scandir($dir) : [];
-
- //循环去掉一切不需要的值
- foreach ($files as $file) {
- if ('.' . pathinfo($file, PATHINFO_EXTENSION) === $this->configExt) {
- $filename = $dir . DIRECTORY_SEPARATOR . $file;
- //加载所有的配置文件
- // $this->config think\Config
- $this->config->load($filename, pathinfo($file, PATHINFO_FILENAME));
- }
- }
- }
-
- // $this->request think\Request
- // 全局过滤方法 default_filter 实际是 app 键值内的 default_filter 值
- $this->request->filter($this->config('app.default_filter'));
- }
-
- /**
- * 执行应用程序
- * @access public
- * @return Response
- * @throws Exception
- */
- public function run()
- {
- // 初始化应用,初步完成注释
- $this->initialize();
-
- try {
- if ($this->bind) {
- // 模块/控制器绑定
- // $this->route think\Route
- $this->route->bind($this->bind);
- } elseif ($this->config('app.auto_bind_module')) {
- // 入口自动绑定模块 app.auto_bind_module 默认是false
- // 入口自动绑定
- $name = pathinfo($this->request->baseFile(), PATHINFO_FILENAME);
- if ($name && 'index' != $name && is_dir($this->appPath . $name)) {
- $this->route->bind($name);
- }
- }
-
- // 读取默认语言
- // app.default_lang 默认为 zh-cn
- // $this->lang think\Lang
- // 设置当前的语言
- $this->lang->range($this->config('app.default_lang'));
- //判断是否开启了多语言,默认是false
- if ($this->config('app.lang_switch_on')) {
- // 开启多语言机制 检测当前语言
- $this->lang->detect();
- }
-
- // $this->request think\Request
- // $this->lang->range() 获取当前的语言
- // 设置当前的语言
- $this->request->langset($this->lang->range());
-
- // 加载系统语言包
- $this->lang->load([
- $this->thinkPath . 'lang/' . $this->request->langset() . '.php',
- $this->appPath . 'lang/' . $this->request->langset() . '.php',
- ]);
-
- // 监听app_dispatch
- $this->hook->listen('app_dispatch');
-
- // 获取应用调度信息
- $dispatch = $this->dispatch;
- if (empty($dispatch)) {
- //$dispatch 为空时执行
- // 进行URL路由检测
- // 主页返回的 think\route\dispatch\Url 实例
- // 在这里也或许会返回404
- $dispatch = $this->routeCheck();
- }
-
- // 记录当前调度信息 设置或者获取当前请求的调度信息
- $this->request->dispatch($dispatch);
-
- // 记录路由和请求信息
- if ($this->debug) {
- $this->log('[ ROUTE ] ' . var_export($this->request->routeInfo(), true));
- $this->log('[ HEADER ] ' . var_export($this->request->header(), true));
- $this->log('[ PARAM ] ' . var_export($this->request->param(), true));
- }
-
- // 监听app_begin
- $this->hook->listen('app_begin');
-
- // 请求缓存检查
- $this->request->cache(
- $this->config('app.request_cache'),
- $this->config('app.request_cache_expire'),
- $this->config('app.request_cache_except')
- );
-
- // 执行调度
- // think\route\dispatch\Url 内的 run()
- $data = $dispatch->run();
- var_dump($data);
-
-// EXIT;
-
- } catch (HttpResponseException $exception) {
- $data = $exception->getResponse();
- }
-
- $this->middlewareDispatcher->add(function (Request $request, $next) use ($data) {
- // 输出数据到客户端
- if ($data instanceof Response) {
- $response = $data;
- } elseif (!is_null($data)) {
- // 默认自动识别响应输出类型
- $isAjax = $request->isAjax();
- $type = $isAjax ? $this->config('app.default_ajax_return') : $this->config('app.default_return_type');
-
- $response = Response::create($data, $type);
- } else {
- $response = Response::create();
- }
- return $response;
- });
-
- $response = $this->middlewareDispatcher->dispatch($this->request);
-
- // 监听app_end
- $this->hook->listen('app_end', $response);
-
- return $response;
- }
-
- /**
- * 设置当前请求的调度信息
- * @access public
- * @param Dispatch $dispatch 调度信息
- * @return $this
- */
- public function dispatch(Dispatch $dispatch)
- {
- $this->dispatch = $dispatch;
- return $this;
- }
-
- /**
- * 记录调试信息
- * @access public
- * @param mixed $msg 调试信息
- * @param string $type 信息类型
- * @return void
- */
- public function log($log, $type = 'info')
- {
- $this->debug && $this->log->record($log, $type);
- }
-
- /**
- * 获取配置参数 为空则获取所有配置
- * @access public
- * @param string $name 配置参数名(支持二级配置 .号分割)
- * @return mixed
- */
- public function config($name = '')
- {
- return $this->config->get($name);
- }
-
- /**
- * URL路由检测(根据PATH_INFO)
- * @access public
- * @return Dispatch
- */
- public function routeCheck()
- {
- // 获取当前请求URL的pathinfo信息(不含URL后缀 如:.html)
- $path = $this->request->path();
- // pathinfo_depr 为 pathinfo分隔符,默认为'/'
- $depr = $this->config('app.pathinfo_depr');
-
- // 路由检测
- $files = scandir($this->routePath); // D:\wamp\www\tp5/route/
- foreach ($files as $file) {
- if (strpos($file, '.php')) {
- $filename = $this->routePath . $file;
- var_dump($filename);
- // 导入路由配置
- $rules = include $filename;
- // is_array() 检测变量是否是数组
- if (is_array($rules)) {
- $this->route->import($rules);
-
- }
- }
- }
- $this->route->routeinfo();
-// exit;
-
- // app.route_annotation 使用注解路由 默认false
- // 这个模式可以放弃使用
- if ($this->config('app.route_annotation')) {
- // 自动生成路由定义
- if ($this->debug) {
- $this->build->buildRoute($this->config('app.controller_suffix'));
- }
-
- $filename = $this->runtimePath . 'build_route.php';
-
- if (is_file($filename)) {
- include $filename;
- }
- }
-
- // 是否强制路由模式
- // 等于false 则使用
- // $this->routeMust 默认为空 is_null($this->routeMust) 为 true
- // $this->routeMust 默认为空
- // app.url_route_must 是否强制使用路由 默认为false
- $must = !is_null($this->routeMust) ? $this->routeMust : $this->config('app.url_route_must');
- // $must 值为false
-
- // 路由检测 返回一个Dispatch对象
-
- // $path 请求URL 不含后缀(.HTML) 不含域名
- // URL分隔符 默认为/
- // $must 是否强制路由模式 默认值为false
- // app.rote_complete_match 路由是否完全匹配 默认为false
- return $this->route->check($path, $depr, $must, $this->config('app.route_complete_match'));
- }
-
- /**
- * 设置应用的路由检测机制
- * @access public
- * @param bool $must 是否强制检测路由
- * @return $this
- */
- public function routeMust($must = false)
- {
- $this->routeMust = $must;
- return $this;
- }
-
- /**
- * 解析模块和类名
- * @access protected
- * @param string $name 资源地址
- * @param string $layer 验证层名称
- * @param bool $appendSuffix 是否添加类名后缀
- * @return array
- */
- protected function parseModuleAndClass($name, $layer, $appendSuffix)
- {
- if (false !== strpos($name, '\\')) {
- $class = $name;
- $module = $this->request->module();
- } else {
- if (strpos($name, '/')) {
- list($module, $name) = explode('/', $name, 2);
- } else {
- $module = $this->request->module();
- }
-
- $class = $this->parseClass($module, $layer, $name, $appendSuffix);
- }
-
- return [$module, $class];
- }
-
- /**
- * 实例化应用类库
- * @access public
- * @param string $name 类名称
- * @param string $layer 业务层名称
- * @param bool $appendSuffix 是否添加类名后缀
- * @param string $common 公共模块名
- * @return object
- * @throws ClassNotFoundException
- */
- public function create($name, $layer, $appendSuffix = false, $common = 'common')
- {
- $guid = $name . $layer;
-
- if ($this->__isset($guid)) {
- return $this->__get($guid);
- }
-
- list($module, $class) = $this->parseModuleAndClass($name, $layer, $appendSuffix);
-
- if (class_exists($class)) {
- $object = $this->__get($class);
- } else {
- $class = str_replace('\\' . $module . '\\', '\\' . $common . '\\', $class);
- if (class_exists($class)) {
- $object = $this->__get($class);
- } else {
- throw new ClassNotFoundException('class not exists:' . $class, $class);
- }
- }
-
- $this->__set($guid, $class);
-
- return $object;
- }
-
- /**
- * 实例化(分层)模型
- * @access public
- * @param string $name Model名称
- * @param string $layer 业务层名称
- * @param bool $appendSuffix 是否添加类名后缀
- * @param string $common 公共模块名
- * @return Model
- * @throws ClassNotFoundException
- */
- public function model($name = '', $layer = 'model', $appendSuffix = false, $common = 'common')
- {
- return $this->create($name, $layer, $appendSuffix, $common);
- }
-
- /**
- * 实例化(分层)控制器 格式:[模块名/]控制器名
- * @access public
- * @param string $name 资源地址
- * @param string $layer 控制层名称
- * @param bool $appendSuffix 是否添加类名后缀
- * @param string $empty 空控制器名称
- * @return object
- * @throws ClassNotFoundException
- */
- public function controller($name, $layer = 'controller', $appendSuffix = false, $empty = '')
- {
- list($module, $class) = $this->parseModuleAndClass($name, $layer, $appendSuffix);
-
- if (class_exists($class)) {
- return $this->__get($class);
- } elseif ($empty && class_exists($emptyClass = $this->parseClass($module, $layer, $empty, $appendSuffix))) {
- return $this->__get($emptyClass);
- } else {
- throw new ClassNotFoundException('class not exists:' . $class, $class);
- }
- }
-
- /**
- * 实例化验证类 格式:[模块名/]验证器名
- * @access public
- * @param string $name 资源地址
- * @param string $layer 验证层名称
- * @param bool $appendSuffix 是否添加类名后缀
- * @param string $common 公共模块名
- * @return Validate
- * @throws ClassNotFoundException
- */
- public function validate($name = '', $layer = 'validate', $appendSuffix = false, $common = 'common')
- {
- $name = $name ?: $this->config('default_validate');
-
- if (empty($name)) {
- return new Validate;
- }
-
- return $this->create($name, $layer, $appendSuffix, $common);
- }
-
- /**
- * 数据库初始化
- * @access public
- * @param mixed $config 数据库配置
- * @param bool|string $name 连接标识 true 强制重新连接
- * @return \think\db\Query
- */
- public function db($config = [], $name = false)
- {
- return Db::connect($config, $name);
- }
-
- /**
- * 远程调用模块的操作方法 参数格式 [模块/控制器/]操作
- * @access public
- * @param string $url 调用地址
- * @param string|array $vars 调用参数 支持字符串和数组
- * @param string $layer 要调用的控制层名称
- * @param bool $appendSuffix 是否添加类名后缀
- * @return mixed
- * @throws ClassNotFoundException
- */
- public function action($url, $vars = [], $layer = 'controller', $appendSuffix = false)
- {
- $info = pathinfo($url);
- $action = $info['basename'];
- $module = '.' != $info['dirname'] ? $info['dirname'] : $this->request->controller();
- $class = $this->controller($module, $layer, $appendSuffix);
-
- if (is_scalar($vars)) {
- if (strpos($vars, '=')) {
- parse_str($vars, $vars);
- } else {
- $vars = [$vars];
- }
- }
-
- return $this->container->invokeMethod([$class, $action . $this->config('action_suffix')], $vars);
- }
-
- /**
- * 解析应用类的类名
- * @access public
- * @param string $module 模块名
- * @param string $layer 层名 controller model ...
- * @param string $name 类名
- * @param bool $appendSuffix
- * @return string
- */
- public function parseClass($module, $layer, $name, $appendSuffix = false)
- {
- $name = str_replace(['/', '.'], '\\', $name);
- $array = explode('\\', $name);
- $class = Loader::parseName(array_pop($array), 1) . ($this->suffix || $appendSuffix ? ucfirst($layer) : '');
- $path = $array ? implode('\\', $array) . '\\' : '';
-
- return $this->namespace . '\\' . ($module ? $module . '\\' : '') . $layer . '\\' . $path . $class;
- }
-
- /**
- * 获取框架版本
- * @access public
- * @return string
- */
- public function version()
- {
- return static::VERSION;
- }
-
- /**
- * 是否为调试模式
- * @access public
- * @return bool
- */
- public function isDebug()
- {
- return $this->debug;
- }
-
- /**
- * 获取模块路径
- * @access public
- * @return string
- */
- public function getModulePath()
- {
- return $this->modulePath;
- }
-
- /**
- * 设置模块路径
- * @access public
- * @param string $path 路径
- * @return void
- */
- public function setModulePath($path)
- {
- $this->modulePath = $path;
- $this->env->set('module_path', $path);
- }
-
- /**
- * 获取应用根目录
- * @access public
- * @return string
- */
- public function getRootPath()
- {
- return $this->rootPath;
- }
-
- /**
- * 获取应用类库目录
- * @access public
- * @return string
- */
- public function getAppPath()
- {
- return $this->appPath;
- }
-
- /**
- * 获取应用运行时目录
- * @access public
- * @return string
- */
- public function getRuntimePath()
- {
- return $this->runtimePath;
- }
-
- /**
- * 获取核心框架目录
- * @access public
- * @return string
- */
- public function getThinkPath()
- {
- return $this->thinkPath;
- }
-
- /**
- * 获取路由目录
- * @access public
- * @return string
- */
- public function getRoutePath()
- {
- return $this->routePath;
- }
-
- /**
- * 获取应用配置目录
- * @access public
- * @return string
- */
- public function getConfigPath()
- {
- return $this->configPath;
- }
-
- /**
- * 获取配置后缀
- * @access public
- * @return string
- */
- public function getConfigExt()
- {
- return $this->configExt;
- }
-
- /**
- * 获取应用类库命名空间
- * @access public
- * @return string
- */
- public function getNamespace()
- {
- return $this->namespace;
- }
-
- /**
- * 设置应用类库命名空间
- * @access public
- * @param string $namespace 命名空间名称
- * @return $this
- */
- public function setNamespace($namespace)
- {
- $this->namespace = $namespace;
- return $this;
- }
-
- /**
- * 是否启用类库后缀
- * @access public
- * @return bool
- */
- public function getSuffix()
- {
- return $this->suffix;
- }
-
- /**
- * 获取应用开启时间
- * @access public
- * @return float
- */
- public function getBeginTime()
- {
- return $this->beginTime;
- }
-
- /**
- * 获取应用初始内存占用
- * @access public
- * @return integer
- */
- public function getBeginMem()
- {
- return $this->beginMem;
- }
-
- /**
- * 获取容器实例
- * @access public
- * @return Container
- */
- public function container()
- {
- return $this->container;
- }
-
- public function __set($name, $value)
- {
- $this->container->bind($name, $value);
- }
-
- public function __get($name)
- {
- return $this->container->make($name);
- }
-
- public function __isset($name)
- {
- return $this->container->bound($name);
- }
-
- public function __unset($name)
- {
- $this->container->__unset($name);
- }
-
- public function offsetExists($key)
- {
- return $this->__isset($key);
- }
-
- public function offsetGet($key)
- {
- return $this->__get($key);
- }
-
- public function offsetSet($key, $value)
- {
- $this->__set($key, $value);
- }
-
- public function offsetUnset($key)
- {
- $this->__unset($key);
- }
-}
diff --git a/thinkphp/library/think/Build.php b/thinkphp/library/think/Build.php
deleted file mode 100644
index decfc12..0000000
--- a/thinkphp/library/think/Build.php
+++ /dev/null
@@ -1,376 +0,0 @@
-
-// +----------------------------------------------------------------------
-
-namespace think;
-
-class Build
-{
- /**
- * 应用对象
- * @var App
- */
- protected $app;
-
- /**
- * 应用目录
- * @var string
- */
- protected $basePath;
-
- public function __construct(App $app)
- {
- $this->app = $app;
- $this->basePath = $this->app->getAppPath();
- }
-
- /**
- * 根据传入的build资料创建目录和文件
- * @access public
- * @param array $build build列表
- * @param string $namespace 应用类库命名空间
- * @param bool $suffix 类库后缀
- * @return void
- */
- public function run(array $build = [], $namespace = 'app', $suffix = false)
- {
- // 锁定
- $lockfile = $this->basePath . 'build.lock';
-
- if (is_writable($lockfile)) {
- return;
- } elseif (!touch($lockfile)) {
- throw new Exception('应用目录[' . $this->basePath . ']不可写,目录无法自动生成!
请手动生成项目目录~', 10006);
- }
-
- foreach ($build as $module => $list) {
- if ('__dir__' == $module) {
- // 创建目录列表
- $this->buildDir($list);
- } elseif ('__file__' == $module) {
- // 创建文件列表
- $this->buildFile($list);
- } else {
- // 创建模块
- $this->module($module, $list, $namespace, $suffix);
- }
- }
-
- // 解除锁定
- unlink($lockfile);
- }
-
- /**
- * 创建目录
- * @access protected
- * @param array $list 目录列表
- * @return void
- */
- protected function buildDir($list)
- {
- foreach ($list as $dir) {
- $this->checkDirBuild($this->basePath . $dir);
- }
- }
-
- /**
- * 创建文件
- * @access protected
- * @param array $list 文件列表
- * @return void
- */
- protected function buildFile($list)
- {
- foreach ($list as $file) {
- if (!is_dir($this->basePath . dirname($file))) {
- // 创建目录
- mkdir($this->basePath . dirname($file), 0755, true);
- }
-
- if (!is_file($this->basePath . $file)) {
- file_put_contents($this->basePath . $file, 'php' == pathinfo($file, PATHINFO_EXTENSION) ? "basePath . $module)) {
- // 创建模块目录
- mkdir($this->basePath . $module);
- }
-
- if (basename($this->app->getRuntimePath()) != $module) {
- // 创建配置文件和公共文件
- $this->buildCommon($module);
- // 创建模块的默认页面
- $this->buildHello($module, $namespace, $suffix);
- }
-
- if (empty($list)) {
- // 创建默认的模块目录和文件
- $list = [
- '__file__' => ['common.php'],
- '__dir__' => ['controller', 'model', 'view', 'config'],
- ];
- }
-
- // 创建子目录和文件
- foreach ($list as $path => $file) {
- $modulePath = $this->basePath . $module . '/';
- if ('__dir__' == $path) {
- // 生成子目录
- foreach ($file as $dir) {
- $this->checkDirBuild($modulePath . $dir);
- }
- } elseif ('__file__' == $path) {
- // 生成(空白)文件
- foreach ($file as $name) {
- if (!is_file($modulePath . $name)) {
- file_put_contents($modulePath . $name, 'php' == pathinfo($name, PATHINFO_EXTENSION) ? "checkDirBuild(dirname($filename));
- $content = '';
- break;
- default:
- // 其他文件
- $content = "app);
- exit;
- $namespace = $this->app->getNameSpace();
- $modules = glob($this->basePath . '*', GLOB_ONLYDIR);
- $content = 'app->config('app.url_controller_layer');
- }
-
- foreach ($modules as $module) {
- $module = basename($module);
-
- if (in_array($module, $this->app->config('app.deny_module_list'))) {
- continue;
- }
-
- $controllers = glob($this->basePath . $module . '/' . $layer . '/*.php');
-
- foreach ($controllers as $controller) {
- $content .= $this->getControllerRoute($namespace, $module, basename($controller, '.php'), $alias, $layer);
- }
- }
-
- $filename = $this->app->getRuntimePath() . 'build_route.php';
- file_put_contents($filename, $content);
-
- return $filename;
- }
-
- /**
- * 生成控制器类的路由规则
- * @access protected
- * @param string $namespace 应用命名空间
- * @param string $module 模块
- * @param string $controller 控制器名
- * @param bool $suffix 类库后缀
- * @param string $layer 控制器层目录名
- * @return string
- */
- protected function getControllerRoute($namespace, $module, $controller, $alias = false, $layer = '')
- {
- $class = new \ReflectionClass($namespace . '\\' . $module . '\\' . $layer . '\\' . $controller);
- $content = '';
- $comment = $class->getDocComment();
-
- if ($alias) {
- $controller = substr($controller, 0, -10);
- }
-
- if (false !== strpos($comment, '@route(')) {
- $comment = $this->parseRouteComment($comment);
- $route = $module . '/' . $controller;
- $comment = preg_replace('/route\(\s?([\'\"][\-\_\/\:\<\>\?\$\[\]\w]+[\'\"])\s?\)/is', 'Route::resourece(\1,\'' . $route . '\')', $comment);
- $content .= PHP_EOL . $comment;
- } elseif (false !== strpos($comment, '@alias(')) {
- $comment = $this->parseRouteComment($comment, '@alias(');
- $route = $module . '/' . $controller;
- $comment = preg_replace('/alias\(\s?([\'\"][\-\_\/\w]+[\'\"])\s?\)/is', 'Route::alias(\1,\'' . $route . '\')', $comment);
- $content .= PHP_EOL . $comment;
- }
-
- $methods = $class->getMethods(\ReflectionMethod::IS_PUBLIC);
-
- foreach ($methods as $method) {
- $comment = $this->getMethodRouteComment($module, $controller, $method);
- if ($comment) {
- $content .= PHP_EOL . $comment;
- }
- }
-
- return $content;
- }
-
- /**
- * 解析路由注释
- * @access protected
- * @param string $comment
- * @param string $tag
- * @return string
- */
- protected function parseRouteComment($comment, $tag = '@route(')
- {
- $comment = substr($comment, 3, -2);
- $comment = explode(PHP_EOL, substr(strstr(trim($comment), $tag), 1));
- $comment = array_map(function ($item) {return trim(trim($item), ' \t*');}, $comment);
-
- if (count($comment) > 1) {
- $key = array_search('', $comment);
- $comment = array_slice($comment, 0, false === $key ? 1 : $key);
- }
-
- $comment = implode(PHP_EOL . "\t", $comment) . ';';
-
- if (strpos($comment, '{')) {
- $comment = preg_replace_callback('/\{\s?.*?\s?\}/s', function ($matches) {
- return false !== strpos($matches[0], '"') ? '[' . substr(var_export(json_decode($matches[0], true), true), 7, -1) . ']' : $matches[0];
- }, $comment);
- }
- return $comment;
- }
-
- /**
- * 获取方法的路由注释
- * @access protected
- * @param string $module 模块
- * @param string $controller 控制器名
- * @param \ReflectMethod $reflectMethod
- * @return string|void
- */
- protected function getMethodRouteComment($module, $controller, $reflectMethod)
- {
- $comment = $reflectMethod->getDocComment();
-
- if (false !== strpos($comment, '@route(')) {
- $comment = $this->parseRouteComment($comment);
- $action = $reflectMethod->getName();
-
- if ($suffix = $this->app->config('app.action_suffix')) {
- $action = substr($action, 0, -strlen($suffix));
- }
-
- $route = $module . '/' . $controller . '/' . $action;
- $comment = preg_replace('/route\s?\(\s?([\'\"][\-\_\/\:\<\>\?\$\[\]\w]+[\'\"])\s?\,?\s?[\'\"]?(\w+?)[\'\"]?\s?\)/is', 'Route::\2(\1,\'' . $route . '\')', $comment);
- $comment = preg_replace('/route\s?\(\s?([\'\"][\-\_\/\:\<\>\?\$\[\]\w]+[\'\"])\s?\)/is', 'Route::rule(\1,\'' . $route . '\')', $comment);
-
- return $comment;
- }
- }
-
- /**
- * 创建模块的欢迎页面
- * @access protected
- * @param string $module 模块名
- * @param string $namespace 应用类库命名空间
- * @param bool $suffix 类库后缀
- * @return void
- */
- protected function buildHello($module, $namespace, $suffix = false)
- {
- $filename = $this->basePath . ($module ? $module . DIRECTORY_SEPARATOR : '') . 'controller' . DIRECTORY_SEPARATOR . 'Index' . ($suffix ? 'Controller' : '') . '.php';
- if (!is_file($filename)) {
- $content = file_get_contents($this->app->getThinkPath() . 'tpl' . DIRECTORY_SEPARATOR . 'default_index.tpl');
- $content = str_replace(['{$app}', '{$module}', '{layer}', '{$suffix}'], [$namespace, $module ? $module . '\\' : '', 'controller', $suffix ? 'Controller' : ''], $content);
- $this->checkDirBuild(dirname($filename));
-
- file_put_contents($filename, $content);
- }
- }
-
- /**
- * 创建模块的公共文件
- * @access protected
- * @param string $module 模块名
- * @return void
- */
- protected function buildCommon($module)
- {
- $filename = $this->app->getConfigPath() . ($module ? $module . DIRECTORY_SEPARATOR : '') . 'app.php';
- $this->checkDirBuild(dirname($filename));
-
- if (!is_file($filename)) {
- file_put_contents($filename, "basePath . ($module ? $module . DIRECTORY_SEPARATOR : '') . 'common.php';
-
- if (!is_file($filename)) {
- file_put_contents($filename, "
-// +----------------------------------------------------------------------
-
-namespace think;
-
-use think\cache\Driver;
-
-class Cache
-{
- /**
- * 缓存实例
- * @var array
- */
- protected $instance = [];
-
- /**
- * 应用对象
- * @var App
- */
- protected $app;
-
- /**
- * 操作句柄
- * @var object
- */
- protected $handler;
-
- public function __construct(App $app)
- {
- $this->app = $app;
- }
-
- /**
- * 连接缓存
- * @access public
- * @param array $options 配置数组
- * @param bool|string $name 缓存连接标识 true 强制重新连接
- * @return Driver
- */
- public function connect(array $options = [], $name = false)
- {
- $type = !empty($options['type']) ? $options['type'] : 'File';
-
- if (false === $name) {
- $name = md5(serialize($options));
- }
-
- if (true === $name || !isset($this->instance[$name])) {
- $class = false !== strpos($type, '\\') ? $type : '\\think\\cache\\driver\\' . ucwords($type);
-
- // 记录初始化信息
- $this->app->log('[ CACHE ] INIT ' . $type);
-
- if (true === $name) {
- $name = md5(serialize($options));
- }
-
- $this->instance[$name] = new $class($options);
- }
-
- return $this->instance[$name];
- }
-
- /**
- * 自动初始化缓存
- * @access public
- * @param array $options 配置数组
- * @return Driver
- */
- public function init(array $options = [])
- {
- if (is_null($this->handler)) {
- // 自动初始化缓存
- $config = $this->app['config'];
-
- if (empty($options) && 'complex' == $config->get('cache.type')) {
- $default = $config->get('cache.default');
- $options = $config->get('cache.' . $default['type']) ?: $default;
- } elseif (empty($options)) {
- $options = $config->pull('cache');
- }
-
- $this->handler = $this->connect($options);
- }
-
- return $this->handler;
- }
-
- /**
- * 切换缓存类型 需要配置 cache.type 为 complex
- * @access public
- * @param string $name 缓存标识
- * @return Driver
- */
- public function store($name = '')
- {
- if ('' !== $name && 'complex' == $this->app['config']->get('cache.type')) {
- return $this->connect($this->app['config']->get('cache.' . $name), strtolower($name));
- }
-
- return $this->init();
- }
-
- public function __call($method, $args)
- {
- return call_user_func_array([$this->init(), $method], $args);
- }
-
-}
diff --git a/thinkphp/library/think/Collection.php b/thinkphp/library/think/Collection.php
deleted file mode 100644
index 929b519..0000000
--- a/thinkphp/library/think/Collection.php
+++ /dev/null
@@ -1,388 +0,0 @@
-
-// +----------------------------------------------------------------------
-
-namespace think;
-
-use ArrayAccess;
-use ArrayIterator;
-use Countable;
-use IteratorAggregate;
-use JsonSerializable;
-
-class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSerializable
-{
- /**
- * 数据集数据
- * @var array
- */
- protected $items = [];
-
- public function __construct($items = [])
- {
- $this->items = $this->convertToArray($items);
- }
-
- public static function make($items = [])
- {
- return new static($items);
- }
-
- /**
- * 是否为空
- * @access public
- * @return bool
- */
- public function isEmpty()
- {
- return empty($this->items);
- }
-
- public function toArray()
- {
- return array_map(function ($value) {
- return ($value instanceof Model || $value instanceof self) ? $value->toArray() : $value;
- }, $this->items);
- }
-
- public function all()
- {
- return $this->items;
- }
-
- /**
- * 合并数组
- *
- * @access public
- * @param mixed $items
- * @return static
- */
- public function merge($items)
- {
- return new static(array_merge($this->items, $this->convertToArray($items)));
- }
-
- /**
- * 比较数组,返回差集
- *
- * @access public
- * @param mixed $items
- * @return static
- */
- public function diff($items)
- {
- return new static(array_diff($this->items, $this->convertToArray($items)));
- }
-
- /**
- * 交换数组中的键和值
- *
- * @access public
- * @return static
- */
- public function flip()
- {
- return new static(array_flip($this->items));
- }
-
- /**
- * 比较数组,返回交集
- *
- * @access public
- * @param mixed $items
- * @return static
- */
- public function intersect($items)
- {
- return new static(array_intersect($this->items, $this->convertToArray($items)));
- }
-
- /**
- * 返回数组中所有的键名
- *
- * @access public
- * @return static
- */
- public function keys()
- {
- return new static(array_keys($this->items));
- }
-
- /**
- * 删除数组的最后一个元素(出栈)
- *
- * @access public
- * @return mixed
- */
- public function pop()
- {
- return array_pop($this->items);
- }
-
- /**
- * 通过使用用户自定义函数,以字符串返回数组
- *
- * @access public
- * @param callable $callback
- * @param mixed $initial
- * @return mixed
- */
- public function reduce(callable $callback, $initial = null)
- {
- return array_reduce($this->items, $callback, $initial);
- }
-
- /**
- * 以相反的顺序返回数组。
- *
- * @access public
- * @return static
- */
- public function reverse()
- {
- return new static(array_reverse($this->items));
- }
-
- /**
- * 删除数组中首个元素,并返回被删除元素的值
- *
- * @access public
- * @return mixed
- */
- public function shift()
- {
- return array_shift($this->items);
- }
-
- /**
- * 在数组结尾插入一个元素
- * @access public
- * @param mixed $value
- * @param mixed $key
- * @return void
- */
- public function push($value, $key = null)
- {
- if (is_null($key)) {
- $this->items[] = $value;
- } else {
- $this->items[$key] = $value;
- }
- }
-
- /**
- * 把一个数组分割为新的数组块.
- *
- * @access public
- * @param int $size
- * @param bool $preserveKeys
- * @return static
- */
- public function chunk($size, $preserveKeys = false)
- {
- $chunks = [];
-
- foreach (array_chunk($this->items, $size, $preserveKeys) as $chunk) {
- $chunks[] = new static($chunk);
- }
-
- return new static($chunks);
- }
-
- /**
- * 在数组开头插入一个元素
- * @access public
- * @param mixed $value
- * @param mixed $key
- * @return void
- */
- public function unshift($value, $key = null)
- {
- if (is_null($key)) {
- array_unshift($this->items, $value);
- } else {
- $this->items = [$key => $value] + $this->items;
- }
- }
-
- /**
- * 给每个元素执行个回调
- *
- * @access public
- * @param callable $callback
- * @return $this
- */
- public function each(callable $callback)
- {
- foreach ($this->items as $key => $item) {
- $result = $callback($item, $key);
-
- if (false === $result) {
- break;
- } elseif (!is_object($item)) {
- $this->items[$key] = $result;
- }
- }
-
- return $this;
- }
-
- /**
- * 用回调函数过滤数组中的元素
- * @access public
- * @param callable|null $callback
- * @return static
- */
- public function filter(callable $callback = null)
- {
- if ($callback) {
- return new static(array_filter($this->items, $callback));
- }
-
- return new static(array_filter($this->items));
- }
-
- /**
- * 返回数据中指定的一列
- * @access public
- * @param mixed $columnKey 键名
- * @param mixed $indexKey 作为索引值的列
- * @return array
- */
- public function column($columnKey, $indexKey = null)
- {
- return array_column($this->items, $columnKey, $indexKey);
- }
-
- /**
- * 对数组排序
- *
- * @access public
- * @param callable|null $callback
- * @return static
- */
- public function sort(callable $callback = null)
- {
- $items = $this->items;
-
- $callback = $callback ?: function ($a, $b) {
- return $a == $b ? 0 : (($a < $b) ? -1 : 1);
-
- };
-
- uasort($items, $callback);
-
- return new static($items);
- }
-
- /**
- * 将数组打乱
- *
- * @access public
- * @return static
- */
- public function shuffle()
- {
- $items = $this->items;
-
- shuffle($items);
-
- return new static($items);
- }
-
- /**
- * 截取数组
- *
- * @access public
- * @param int $offset
- * @param int $length
- * @param bool $preserveKeys
- * @return static
- */
- public function slice($offset, $length = null, $preserveKeys = false)
- {
- return new static(array_slice($this->items, $offset, $length, $preserveKeys));
- }
-
- // ArrayAccess
- public function offsetExists($offset)
- {
- return array_key_exists($offset, $this->items);
- }
-
- public function offsetGet($offset)
- {
- return $this->items[$offset];
- }
-
- public function offsetSet($offset, $value)
- {
- if (is_null($offset)) {
- $this->items[] = $value;
- } else {
- $this->items[$offset] = $value;
- }
- }
-
- public function offsetUnset($offset)
- {
- unset($this->items[$offset]);
- }
-
- //Countable
- public function count()
- {
- return count($this->items);
- }
-
- //IteratorAggregate
- public function getIterator()
- {
- return new ArrayIterator($this->items);
- }
-
- //JsonSerializable
- public function jsonSerialize()
- {
- return $this->toArray();
- }
-
- /**
- * 转换当前数据集为JSON字符串
- * @access public
- * @param integer $options json参数
- * @return string
- */
- public function toJson($options = JSON_UNESCAPED_UNICODE)
- {
- return json_encode($this->toArray(), $options);
- }
-
- public function __toString()
- {
- return $this->toJson();
- }
-
- /**
- * 转换成数组
- *
- * @access public
- * @param mixed $items
- * @return array
- */
- protected function convertToArray($items)
- {
- if ($items instanceof self) {
- return $items->all();
- }
-
- return (array) $items;
- }
-}
diff --git a/thinkphp/library/think/Config.php b/thinkphp/library/think/Config.php
deleted file mode 100644
index e3fa776..0000000
--- a/thinkphp/library/think/Config.php
+++ /dev/null
@@ -1,330 +0,0 @@
-
-// +----------------------------------------------------------------------
-
-namespace think;
-
-class Config implements \ArrayAccess
-{
- /**
- * 配置参数
- * @var array
- */
- private $config = [];
-
- /**
- * 缓存前缀
- * @var string
- */
- private $prefix = 'app';
-
- /**
- * 设置配置参数默认前缀
- * @access public
- * @param string $prefix 前缀
- * @return void
- */
- public function setDefaultPrefix($prefix)
- {
- $this->prefix = $prefix;
- }
-
- /**
- * 解析配置文件或内容
- * @access public
- * @param string $config 配置文件路径或内容
- * @param string $type 配置解析类型
- * @param string $name 配置名(如设置即表示二级配置)
- * @return mixed
- */
- public function parse($config, $type = '', $name = '')
- {
- if (empty($type)) {
- $type = pathinfo($config, PATHINFO_EXTENSION);
- }
-
- $class = false !== strpos($type, '\\') ? $type : '\\think\\config\\driver\\' . ucwords($type);
-
- return $this->set((new $class())->parse($config), $name);
- }
-
- /**
- * 加载配置文件(多种格式)
- * @access public
- * @param string $file 配置文件名
- * @param string $name 一级配置名
- * @return mixed
- */
- public function load($file, $name = '')
- {
- //检测文件是否存在
- if (is_file($file)) {
- //$name 所有字符转换为小写
- $name = strtolower($name);
- //获取文件的后缀格式
- $type = pathinfo($file, PATHINFO_EXTENSION);
- if ('php' == $type) {
- // 后缀为 php格式,返回配置信息数组的值
- return $this->set(include $file, $name);
- } elseif ('yaml' == $type && function_exists('yaml_parse_file')) {
- // yaml 后缀格式 并检测环境是否支持 yaml_parse_file 函数
- return $this->set(yaml_parse_file($file), $name);
- } else {
- // 除以上两种格式以外的
- return $this->parse($file, $type, $name);
- }
- } else {
- // 文件不存在直接返回配置信息数组
- return $this->config;
- }
- }
-
- /**
- * 自动加载配置文件(PHP格式)
- * @access public
- * @param string $name 配置名
- * @return void
- */
- protected function autoLoad($name)
- {
- // 如果尚未载入 则动态加载配置文件
- $module = Container::get('request')->module();
- $module = $module ? $module . '/' : '';
- $app = Container::get('app');
- $path = $app->getAppPath() . $module;
-
- if (is_dir($path . 'config')) {
- $file = $path . 'config/' . $name . $app->getConfigExt();
- } elseif (is_dir($app->getConfigPath() . $module)) {
- $file = $app->getConfigPath() . $module . $name . $app->getConfigExt();
- }
-
- if (isset($file) && is_file($file)) {
- $this->load($file, $name);
- }
- }
-
- /**
- * 检测配置是否存在
- * @access public
- * @param string $name 配置参数名(支持多级配置 .号分割)
- * @return bool
- */
- public function has($name)
- {
- if (!strpos($name, '.')) {
- $name = $this->prefix . '.' . $name;
- }
-
- return $this->get($name) ? true : false;
- }
-
- /**
- * 获取一级配置
- * @access public
- * @param string $name 一级配置名
- * @return array
- */
- public function pull($name)
- {
- $name = strtolower($name);
-
- if (!isset($this->config[$name])) {
- // 如果尚未载入 则动态加载配置文件
- $this->autoLoad($name);
- }
-
- return isset($this->config[$name]) ? $this->config[$name] : [];
- }
-
- /**
- * 获取配置参数 为空则获取所有配置
- * @access public
- * @param string $name 配置参数名(支持多级配置 .号分割)
- * @return mixed
- */
- public function get($name = null)
- {
- // 无参数时获取所有
- if (empty($name)) {
- return $this->config;
- }
-
- //点在字符串中第一次出现的位置
- if (!strpos($name, '.')) {
- $name = $this->prefix . '.' . $name;
- } elseif ('.' == substr($name, -1)) {
- return $this->pull(substr($name, 0, -1));
- }
-
- $name = explode('.', $name);
- $name[0] = strtolower($name[0]);
- $config = $this->config;
-
- if (!isset($config[$name[0]])) {
- // 如果尚未载入 则动态加载配置文件
- $this->autoLoad($name[0]);
- }
-
- // 按.拆分成多维数组进行判断
- foreach ($name as $val) {
- if (isset($config[$val])) {
- $config = $config[$val];
- } else {
- return;
- }
- }
-
- return $config;
- }
-
- /**
- * 设置配置参数 name为数组则为批量设置
- * @access public
- * @param string|array $name 配置参数名(支持三级配置 .号分割)
- * @param mixed $value 配置值
- * @return mixed
- */
- public function set($name, $value = null)
- {
-
- // PHP 后缀时 $value 标识为文件名 $name 文件内容(数组)
- // 检测$name 是否是字符串 是为true
- // php 时一般$name 为数组 非字符串
- if (is_string($name)) {
- if (!strpos($name, '.')) {
- $name = $this->prefix . '.' . $name;
- }
-
- $name = explode('.', $name, 3);
-
- if (count($name) == 2) {
- $this->config[strtolower($name[0])][$name[1]] = $value;
- } else {
- $this->config[strtolower($name[0])][$name[1]][$name[2]] = $value;
- }
-
- return $value;
- } elseif (is_array($name)) {
- // 为数组时执行 批量设置
- // 检测¥value 是否为空或者null 不为空才执行如下
- if (!empty($value)) {
- //检测 是否已经存在
- if (isset($this->config[$value])) {
- //存在则合并成新的
- $result = array_merge($this->config[$value], $name);
- } else {
- //不存在则赋值
- $result = $name;
- }
- //最终根据¥value值为键值
- $this->config[$value] = $result;
- } else {
- // empty($value) 为空时执行 数组合并
- $result = $this->config = array_merge($this->config, $name);
- }
- } else {
- // 为空直接返回 已有配置
- $result = $this->config;
- }
- //并且返回当前的值
- return $result;
- }
-
- /**
- * 移除配置
- * @access public
- * @param string $name 配置参数名(支持三级配置 .号分割)
- * @return void
- */
- public function remove($name)
- {
- if (!strpos($name, '.')) {
- $name = $this->prefix . '.' . $name;
- }
-
- $name = explode('.', $name, 3);
-
- if (count($name) == 2) {
- unset($this->config[strtolower($name[0])][$name[1]]);
- } else {
- unset($this->config[strtolower($name[0])][$name[1]][$name[2]]);
- }
- }
-
- /**
- * 重置配置参数
- * @access public
- * @param string $prefix 配置前缀名
- * @return void
- */
- public function reset($prefix = '')
- {
- if ('' === $prefix) {
- $this->config = [];
- } else {
- $this->config[$prefix] = [];
- }
- }
-
- /**
- * 设置配置
- * @access public
- * @param string $name 参数名
- * @param mixed $value 值
- */
- public function __set($name, $value)
- {
- return $this->set($name, $value);
- }
-
- /**
- * 获取配置参数
- * @access public
- * @param string $name 参数名
- * @return mixed
- */
- public function __get($name)
- {
- return $this->get($name);
- }
-
- /**
- * 检测是否存在参数
- * @access public
- * @param string $name 参数名
- * @return bool
- */
- public function __isset($name)
- {
- return $this->has($name);
- }
-
- // ArrayAccess
- public function offsetSet($name, $value)
- {
- $this->set($name, $value);
- }
-
- public function offsetExists($name)
- {
- return $this->has($name);
- }
-
- public function offsetUnset($name)
- {
- $this->remove($name);
- }
-
- public function offsetGet($name)
- {
- return $this->get($name);
- }
-}
diff --git a/thinkphp/library/think/Console.php b/thinkphp/library/think/Console.php
deleted file mode 100644
index 5cb1ccd..0000000
--- a/thinkphp/library/think/Console.php
+++ /dev/null
@@ -1,762 +0,0 @@
-
-// +----------------------------------------------------------------------
-
-namespace think;
-
-use think\console\Command;
-use think\console\command\Help as HelpCommand;
-use think\console\Input;
-use think\console\input\Argument as InputArgument;
-use think\console\input\Definition as InputDefinition;
-use think\console\input\Option as InputOption;
-use think\console\Output;
-use think\console\output\driver\Buffer;
-
-class Console
-{
-
- private $name;
- private $version;
-
- /** @var Command[] */
- private $commands = [];
-
- private $wantHelps = false;
-
- private $catchExceptions = true;
- private $autoExit = true;
- private $definition;
- private $defaultCommand;
-
- private static $defaultCommands = [
- "think\\console\\command\\Help",
- "think\\console\\command\\Lists",
- "think\\console\\command\\Build",
- "think\\console\\command\\Clear",
- "think\\console\\command\\make\\Controller",
- "think\\console\\command\\make\\Model",
- "think\\console\\command\\optimize\\Autoload",
- "think\\console\\command\\optimize\\Config",
- "think\\console\\command\\optimize\\Schema",
- "think\\console\\command\\optimize\\Route",
- "think\\console\\command\\RunServer",
- ];
-
- public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
- {
- $this->name = $name;
- $this->version = $version;
-
- $this->defaultCommand = 'list';
- $this->definition = $this->getDefaultInputDefinition();
-
- foreach ($this->getDefaultCommands() as $command) {
- $this->add($command);
- }
- }
-
- public static function init($run = true)
- {
- static $console;
-
- if (!$console) {
- // 实例化console
- $console = new self('Think Console', '0.1');
-
- // 读取指令集
- $file = Container::get('env')->get('app_path') . 'command.php';
-
- if (is_file($file)) {
- $commands = include $file;
-
- if (is_array($commands)) {
- foreach ($commands as $command) {
- if (class_exists($command) && is_subclass_of($command, "\\think\\console\\Command")) {
- // 注册指令
- $console->add(new $command());
- }
- }
- }
- }
- }
-
- if ($run) {
- // 运行
- return $console->run();
- } else {
- return $console;
- }
- }
-
- /**
- * @access public
- * @param string $command
- * @param array $parameters
- * @param string $driver
- * @return Output|Buffer
- */
- public static function call($command, array $parameters = [], $driver = 'buffer')
- {
- $console = self::init(false);
-
- array_unshift($parameters, $command);
-
- $input = new Input($parameters);
- $output = new Output($driver);
-
- $console->setCatchExceptions(false);
- $console->find($command)->run($input, $output);
-
- return $output;
- }
-
- /**
- * 执行当前的指令
- * @access public
- * @return int
- * @throws \Exception
- * @api
- */
- public function run()
- {
- $input = new Input();
- $output = new Output();
-
- $this->configureIO($input, $output);
-
- try {
- $exitCode = $this->doRun($input, $output);
- } catch (\Exception $e) {
- if (!$this->catchExceptions) {
- throw $e;
- }
-
- $output->renderException($e);
-
- $exitCode = $e->getCode();
- if (is_numeric($exitCode)) {
- $exitCode = (int) $exitCode;
- if (0 === $exitCode) {
- $exitCode = 1;
- }
- } else {
- $exitCode = 1;
- }
- }
-
- if ($this->autoExit) {
- if ($exitCode > 255) {
- $exitCode = 255;
- }
-
- exit($exitCode);
- }
-
- return $exitCode;
- }
-
- /**
- * 执行指令
- * @access public
- * @param Input $input
- * @param Output $output
- * @return int
- */
- public function doRun(Input $input, Output $output)
- {
- if (true === $input->hasParameterOption(['--version', '-V'])) {
- $output->writeln($this->getLongVersion());
-
- return 0;
- }
-
- $name = $this->getCommandName($input);
-
- if (true === $input->hasParameterOption(['--help', '-h'])) {
- if (!$name) {
- $name = 'help';
- $input = new Input(['help']);
- } else {
- $this->wantHelps = true;
- }
- }
-
- if (!$name) {
- $name = $this->defaultCommand;
- $input = new Input([$this->defaultCommand]);
- }
-
- $command = $this->find($name);
-
- $exitCode = $this->doRunCommand($command, $input, $output);
-
- return $exitCode;
- }
-
- /**
- * 设置输入参数定义
- * @access public
- * @param InputDefinition $definition
- */
- public function setDefinition(InputDefinition $definition)
- {
- $this->definition = $definition;
- }
-
- /**
- * 获取输入参数定义
- * @access public
- * @return InputDefinition The InputDefinition instance
- */
- public function getDefinition()
- {
- return $this->definition;
- }
-
- /**
- * Gets the help message.
- * @access public
- * @return string A help message.
- */
- public function getHelp()
- {
- return $this->getLongVersion();
- }
-
- /**
- * 是否捕获异常
- * @access public
- * @param bool $boolean
- * @api
- */
- public function setCatchExceptions($boolean)
- {
- $this->catchExceptions = (bool) $boolean;
- }
-
- /**
- * 是否自动退出
- * @access public
- * @param bool $boolean
- * @api
- */
- public function setAutoExit($boolean)
- {
- $this->autoExit = (bool) $boolean;
- }
-
- /**
- * 获取名称
- * @access public
- * @return string
- */
- public function getName()
- {
- return $this->name;
- }
-
- /**
- * 设置名称
- * @access public
- * @param string $name
- */
- public function setName($name)
- {
- $this->name = $name;
- }
-
- /**
- * 获取版本
- * @access public
- * @return string
- * @api
- */
- public function getVersion()
- {
- return $this->version;
- }
-
- /**
- * 设置版本
- * @access public
- * @param string $version
- */
- public function setVersion($version)
- {
- $this->version = $version;
- }
-
- /**
- * 获取完整的版本号
- * @access public
- * @return string
- */
- public function getLongVersion()
- {
- if ('UNKNOWN' !== $this->getName() && 'UNKNOWN' !== $this->getVersion()) {
- return sprintf('%s version %s', $this->getName(), $this->getVersion());
- }
-
- return 'Console Tool';
- }
-
- /**
- * 注册一个指令
- * @access public
- * @param string $name
- * @return Command
- */
- public function register($name)
- {
- return $this->add(new Command($name));
- }
-
- /**
- * 添加指令
- * @access public
- * @param Command[] $commands
- */
- public function addCommands(array $commands)
- {
- foreach ($commands as $command) {
- $this->add($command);
- }
- }
-
- /**
- * 添加一个指令
- * @access public
- * @param Command $command
- * @return Command
- */
- public function add(Command $command)
- {
- $command->setConsole($this);
-
- if (!$command->isEnabled()) {
- $command->setConsole(null);
- return;
- }
-
- if (null === $command->getDefinition()) {
- throw new \LogicException(sprintf('Command class "%s" is not correctly initialized. You probably forgot to call the parent constructor.', get_class($command)));
- }
-
- $this->commands[$command->getName()] = $command;
-
- foreach ($command->getAliases() as $alias) {
- $this->commands[$alias] = $command;
- }
-
- return $command;
- }
-
- /**
- * 获取指令
- * @access public
- * @param string $name 指令名称
- * @return Command
- * @throws \InvalidArgumentException
- */
- public function get($name)
- {
- if (!isset($this->commands[$name])) {
- throw new \InvalidArgumentException(sprintf('The command "%s" does not exist.', $name));
- }
-
- $command = $this->commands[$name];
-
- if ($this->wantHelps) {
- $this->wantHelps = false;
-
- /** @var HelpCommand $helpCommand */
- $helpCommand = $this->get('help');
- $helpCommand->setCommand($command);
-
- return $helpCommand;
- }
-
- return $command;
- }
-
- /**
- * 某个指令是否存在
- * @access public
- * @param string $name 指令名称
- * @return bool
- */
- public function has($name)
- {
- return isset($this->commands[$name]);
- }
-
- /**
- * 获取所有的命名空间
- * @access public
- * @return array
- */
- public function getNamespaces()
- {
- $namespaces = [];
- foreach ($this->commands as $command) {
- $namespaces = array_merge($namespaces, $this->extractAllNamespaces($command->getName()));
-
- foreach ($command->getAliases() as $alias) {
- $namespaces = array_merge($namespaces, $this->extractAllNamespaces($alias));
- }
- }
-
- return array_values(array_unique(array_filter($namespaces)));
- }
-
- /**
- * 查找注册命名空间中的名称或缩写。
- * @access public
- * @param string $namespace
- * @return string
- * @throws \InvalidArgumentException
- */
- public function findNamespace($namespace)
- {
- $allNamespaces = $this->getNamespaces();
- $expr = preg_replace_callback('{([^:]+|)}', function ($matches) {
- return preg_quote($matches[1]) . '[^:]*';
- }, $namespace);
- $namespaces = preg_grep('{^' . $expr . '}', $allNamespaces);
-
- if (empty($namespaces)) {
- $message = sprintf('There are no commands defined in the "%s" namespace.', $namespace);
-
- if ($alternatives = $this->findAlternatives($namespace, $allNamespaces)) {
- if (1 == count($alternatives)) {
- $message .= "\n\nDid you mean this?\n ";
- } else {
- $message .= "\n\nDid you mean one of these?\n ";
- }
-
- $message .= implode("\n ", $alternatives);
- }
-
- throw new \InvalidArgumentException($message);
- }
-
- $exact = in_array($namespace, $namespaces, true);
- if (count($namespaces) > 1 && !$exact) {
- throw new \InvalidArgumentException(sprintf('The namespace "%s" is ambiguous (%s).', $namespace, $this->getAbbreviationSuggestions(array_values($namespaces))));
- }
-
- return $exact ? $namespace : reset($namespaces);
- }
-
- /**
- * 查找指令
- * @access public
- * @param string $name 名称或者别名
- * @return Command
- * @throws \InvalidArgumentException
- */
- public function find($name)
- {
- $allCommands = array_keys($this->commands);
-
- $expr = preg_replace_callback('{([^:]+|)}', function ($matches) {
- return preg_quote($matches[1]) . '[^:]*';
- }, $name);
-
- $commands = preg_grep('{^' . $expr . '}', $allCommands);
-
- if (empty($commands) || count(preg_grep('{^' . $expr . '$}', $commands)) < 1) {
- if (false !== $pos = strrpos($name, ':')) {
- $this->findNamespace(substr($name, 0, $pos));
- }
-
- $message = sprintf('Command "%s" is not defined.', $name);
-
- if ($alternatives = $this->findAlternatives($name, $allCommands)) {
- if (1 == count($alternatives)) {
- $message .= "\n\nDid you mean this?\n ";
- } else {
- $message .= "\n\nDid you mean one of these?\n ";
- }
- $message .= implode("\n ", $alternatives);
- }
-
- throw new \InvalidArgumentException($message);
- }
-
- if (count($commands) > 1) {
- $commandList = $this->commands;
-
- $commands = array_filter($commands, function ($nameOrAlias) use ($commandList, $commands) {
- $commandName = $commandList[$nameOrAlias]->getName();
-
- return $commandName === $nameOrAlias || !in_array($commandName, $commands);
- });
- }
-
- $exact = in_array($name, $commands, true);
- if (count($commands) > 1 && !$exact) {
- $suggestions = $this->getAbbreviationSuggestions(array_values($commands));
-
- throw new \InvalidArgumentException(sprintf('Command "%s" is ambiguous (%s).', $name, $suggestions));
- }
-
- return $this->get($exact ? $name : reset($commands));
- }
-
- /**
- * 获取所有的指令
- * @access public
- * @param string $namespace 命名空间
- * @return Command[]
- * @api
- */
- public function all($namespace = null)
- {
- if (null === $namespace) {
- return $this->commands;
- }
-
- $commands = [];
- foreach ($this->commands as $name => $command) {
- if ($this->extractNamespace($name, substr_count($namespace, ':') + 1) === $namespace) {
- $commands[$name] = $command;
- }
- }
-
- return $commands;
- }
-
- /**
- * 获取可能的指令名
- * @access public
- * @param array $names
- * @return array
- */
- public static function getAbbreviations($names)
- {
- $abbrevs = [];
- foreach ($names as $name) {
- for ($len = strlen($name); $len > 0; --$len) {
- $abbrev = substr($name, 0, $len);
- $abbrevs[$abbrev][] = $name;
- }
- }
-
- return $abbrevs;
- }
-
- /**
- * 配置基于用户的参数和选项的输入和输出实例。
- * @access protected
- * @param Input $input 输入实例
- * @param Output $output 输出实例
- */
- protected function configureIO(Input $input, Output $output)
- {
- if (true === $input->hasParameterOption(['--ansi'])) {
- $output->setDecorated(true);
- } elseif (true === $input->hasParameterOption(['--no-ansi'])) {
- $output->setDecorated(false);
- }
-
- if (true === $input->hasParameterOption(['--no-interaction', '-n'])) {
- $input->setInteractive(false);
- }
-
- if (true === $input->hasParameterOption(['--quiet', '-q'])) {
- $output->setVerbosity(Output::VERBOSITY_QUIET);
- } else {
- if ($input->hasParameterOption('-vvv') || $input->hasParameterOption('--verbose=3') || $input->getParameterOption('--verbose') === 3) {
- $output->setVerbosity(Output::VERBOSITY_DEBUG);
- } elseif ($input->hasParameterOption('-vv') || $input->hasParameterOption('--verbose=2') || $input->getParameterOption('--verbose') === 2) {
- $output->setVerbosity(Output::VERBOSITY_VERY_VERBOSE);
- } elseif ($input->hasParameterOption('-v') || $input->hasParameterOption('--verbose=1') || $input->hasParameterOption('--verbose') || $input->getParameterOption('--verbose')) {
- $output->setVerbosity(Output::VERBOSITY_VERBOSE);
- }
- }
- }
-
- /**
- * 执行指令
- * @access protected
- * @param Command $command 指令实例
- * @param Input $input 输入实例
- * @param Output $output 输出实例
- * @return int
- * @throws \Exception
- */
- protected function doRunCommand(Command $command, Input $input, Output $output)
- {
- return $command->run($input, $output);
- }
-
- /**
- * 获取指令的基础名称
- * @access protected
- * @param Input $input
- * @return string
- */
- protected function getCommandName(Input $input)
- {
- return $input->getFirstArgument();
- }
-
- /**
- * 获取默认输入定义
- * @access protected
- * @return InputDefinition
- */
- protected function getDefaultInputDefinition()
- {
- return new InputDefinition([
- new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),
- new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message'),
- new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this console version'),
- new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message'),
- new InputOption('--verbose', '-v|vv|vvv', InputOption::VALUE_NONE, 'Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug'),
- new InputOption('--ansi', '', InputOption::VALUE_NONE, 'Force ANSI output'),
- new InputOption('--no-ansi', '', InputOption::VALUE_NONE, 'Disable ANSI output'),
- new InputOption('--no-interaction', '-n', InputOption::VALUE_NONE, 'Do not ask any interactive question'),
- ]);
- }
-
- /**
- * 设置默认命令
- * @access protected
- * @return Command[] An array of default Command instances
- */
- protected function getDefaultCommands()
- {
- $defaultCommands = [];
-
- foreach (self::$defaultCommands as $classname) {
- if (class_exists($classname) && is_subclass_of($classname, "think\\console\\Command")) {
- $defaultCommands[] = new $classname();
- }
- }
-
- return $defaultCommands;
- }
-
- public static function addDefaultCommands(array $classnames)
- {
- self::$defaultCommands = array_merge(self::$defaultCommands, $classnames);
- }
-
- /**
- * 获取可能的建议
- * @access private
- * @param array $abbrevs
- * @return string
- */
- private function getAbbreviationSuggestions($abbrevs)
- {
- return sprintf('%s, %s%s', $abbrevs[0], $abbrevs[1], count($abbrevs) > 2 ? sprintf(' and %d more', count($abbrevs) - 2) : '');
- }
-
- /**
- * 返回命名空间部分
- * @access public
- * @param string $name 指令
- * @param string $limit 部分的命名空间的最大数量
- * @return string
- */
- public function extractNamespace($name, $limit = null)
- {
- $parts = explode(':', $name);
- array_pop($parts);
-
- return implode(':', null === $limit ? $parts : array_slice($parts, 0, $limit));
- }
-
- /**
- * 查找可替代的建议
- * @access private
- * @param string $name
- * @param array|\Traversable $collection
- * @return array
- */
- private function findAlternatives($name, $collection)
- {
- $threshold = 1e3;
- $alternatives = [];
-
- $collectionParts = [];
- foreach ($collection as $item) {
- $collectionParts[$item] = explode(':', $item);
- }
-
- foreach (explode(':', $name) as $i => $subname) {
- foreach ($collectionParts as $collectionName => $parts) {
- $exists = isset($alternatives[$collectionName]);
- if (!isset($parts[$i]) && $exists) {
- $alternatives[$collectionName] += $threshold;
- continue;
- } elseif (!isset($parts[$i])) {
- continue;
- }
-
- $lev = levenshtein($subname, $parts[$i]);
- if ($lev <= strlen($subname) / 3 || '' !== $subname && false !== strpos($parts[$i], $subname)) {
- $alternatives[$collectionName] = $exists ? $alternatives[$collectionName] + $lev : $lev;
- } elseif ($exists) {
- $alternatives[$collectionName] += $threshold;
- }
- }
- }
-
- foreach ($collection as $item) {
- $lev = levenshtein($name, $item);
- if ($lev <= strlen($name) / 3 || false !== strpos($item, $name)) {
- $alternatives[$item] = isset($alternatives[$item]) ? $alternatives[$item] - $lev : $lev;
- }
- }
-
- $alternatives = array_filter($alternatives, function ($lev) use ($threshold) {
- return $lev < 2 * $threshold;
- });
- asort($alternatives);
-
- return array_keys($alternatives);
- }
-
- /**
- * 设置默认的指令
- * @access public
- * @param string $commandName The Command name
- */
- public function setDefaultCommand($commandName)
- {
- $this->defaultCommand = $commandName;
- }
-
- /**
- * 返回所有的命名空间
- * @access private
- * @param string $name
- * @return array
- */
- private function extractAllNamespaces($name)
- {
- $parts = explode(':', $name, -1);
- $namespaces = [];
-
- foreach ($parts as $part) {
- if (count($namespaces)) {
- $namespaces[] = end($namespaces) . ':' . $part;
- } else {
- $namespaces[] = $part;
- }
- }
-
- return $namespaces;
- }
-
-}
diff --git a/thinkphp/library/think/Container.php b/thinkphp/library/think/Container.php
deleted file mode 100644
index d3b2021..0000000
--- a/thinkphp/library/think/Container.php
+++ /dev/null
@@ -1,320 +0,0 @@
-
-// +----------------------------------------------------------------------
-
-namespace think;
-
-use Closure;
-use InvalidArgumentException;
-use ReflectionClass;
-use ReflectionFunction;
-use ReflectionMethod;
-
-class Container
-{
- /**
- * 容器对象实例
- * @var Container
- */
- protected static $instance;
-
- /**
- * 容器中的对象实例
- * @var array
- */
- protected $instances = [];
-
- /**
- * 容器绑定标识
- * @var array
- */
- protected $bind = [];
-
- /**
- * 获取当前容器的实例(单例)
- * @access public
- * @return static
- */
- public static function getInstance()
- {
- if (is_null(static::$instance)) {
- static::$instance = new static;
- }
-
- return static::$instance;
- }
-
- /**
- * 获取容器中的对象实例
- * @access public
- * @param string $abstract 类名或者标识
- * @param array|true $vars 变量
- * @param bool $newInstance 是否每次创建新的实例
- * @return object
- */
- public static function get($abstract, $vars = [], $newInstance = false)
- {
- return static::getInstance()->make($abstract, $vars, $newInstance);
- }
-
- /**
- * 绑定一个类、闭包、实例、接口实现到容器
- * @access public
- * @param string $abstract 类标识、接口
- * @param mixed $concrete 要绑定的类、闭包或者实例
- * @return Container
- */
- public static function set($abstract, $concrete = null)
- {
- return static::getInstance()->bind($abstract, $concrete);
- }
-
- /**
- * 绑定一个类、闭包、实例、接口实现到容器
- * @access public
- * @param string|array $abstract 类标识、接口
- * @param mixed $concrete 要绑定的类、闭包或者实例
- * @return $this
- */
- public function bind($abstract, $concrete = null)
- {
- if (is_array($abstract)) {
- $this->bind = array_merge($this->bind, $abstract);
- } elseif ($concrete instanceof Closure) {
- $this->bind[$abstract] = $concrete;
- } elseif (is_object($concrete)) {
- $this->instances[$abstract] = $concrete;
- } else {
- $this->bind[$abstract] = $concrete;
- }
-
- return $this;
- }
-
- /**
- * 绑定一个类实例当容器
- * @access public
- * @param string $abstract 类名或者标识
- * @param object $instance 类的实例
- * @return $this
- */
- public function instance($abstract, $instance)
- {
- if (isset($this->bind[$abstract])) {
- $abstract = $this->bind[$abstract];
- }
-
- $this->instances[$abstract] = $instance;
-
- return $this;
- }
-
- /**
- * 判断容器中是否存在类及标识
- * @access public
- * @param string $abstract 类名或者标识
- * @return bool
- */
- public function bound($abstract)
- {
- return isset($this->bind[$abstract]) || isset($this->instances[$abstract]);
- }
-
- /**
- * 判断容器中是否存在类及标识
- * @access public
- * @param string $name 类名或者标识
- * @return bool
- */
- public function has($name)
- {
- return $this->bound($name);
- }
-
- /**
- * 创建类的实例
- * @access public
- * @param string $abstract 类名或者标识
- * @param array|true $args 变量
- * @param bool $newInstance 是否每次创建新的实例
- * @return object
- */
- public function make($abstract, $vars = [], $newInstance = false)
- {
- if (true === $vars) {
- // 总是创建新的实例化对象
- $newInstance = true;
- $vars = [];
- }
-
- if (isset($this->instances[$abstract]) && !$newInstance) {
- $object = $this->instances[$abstract];
- } else {
- if (isset($this->bind[$abstract])) {
- $concrete = $this->bind[$abstract];
-
- if ($concrete instanceof Closure) {
- $object = $this->invokeFunction($concrete, $vars);
- } else {
- $object = $this->make($concrete, $vars, $newInstance);
- }
- } else {
- $object = $this->invokeClass($abstract, $vars);
- }
-
- if (!$newInstance) {
- $this->instances[$abstract] = $object;
- }
- }
-
- return $object;
- }
-
- /**
- * 执行函数或者闭包方法 支持参数调用
- * @access public
- * @param string|array|\Closure $function 函数或者闭包
- * @param array $vars 变量
- * @return mixed
- */
- public function invokeFunction($function, $vars = [])
- {
- //$vars 带入的参数
- $reflect = new ReflectionFunction($function);
- //整理参数
- $args = $this->bindParams($reflect, $vars);
- // 调用(执行)反射的方法并将其参数作为数组传递
- return $reflect->invokeArgs($args);
- }
-
- /**
- * 调用反射执行类的方法 支持参数绑定
- * @access public
- * @param string|array $method 方法
- * @param array $vars 变量
- * @return mixed
- */
- public function invokeMethod($method, $vars = [])
- {
- if (is_array($method)) {
- //检测变量是否是一个对象
- //检测第一个值是否为实例化对象,是则采用,不是则获取生成实例化对象
- $class = is_object($method[0]) ? $method[0] : $this->invokeClass($method[0]);
- $reflect = new ReflectionMethod($class, $method[1]);
- } else {
- // 静态方法
- $reflect = new ReflectionMethod($method);
- }
- //整理参数
- $args = $this->bindParams($reflect, $vars);
- // 调用(执行)反射的方法并将其参数作为数组传递
- return $reflect->invokeArgs(isset($class) ? $class : null, $args);
- }
-
- /**
- * 调用反射执行callable 支持参数绑定
- * @access public
- * @param mixed $callable
- * @param array $vars 变量
- * @return mixed
- */
- public function invoke($callable, $vars = [])
- {
- // $callable 数组或者字符串,匿名函数,或者类命名空间 或者静态调用方法
- // $vars 传递的参数
- //是否为闭包,闭包则执行函数,否则执行类方法
- if ($callable instanceof Closure) {
- //执行闭包函数
- $result = $this->invokeFunction($callable, $vars);
-
- } else {
- //执行类 方法操作
- $result = $this->invokeMethod($callable, $vars);
- }
-
- return $result;
- }
-
- /**
- * 调用反射执行类的实例化 支持依赖注入
- * @access public
- * @param string $class 类名
- * @param array $vars 变量
- * @return mixed
- */
- public function invokeClass($class, $vars = [])
- {
- //给定命名空间或者类名,返回对应的实例对象
- // $vars 实例时需要传递的值
- $reflect = new ReflectionClass($class);
- // 获取类的构造函数,返回类命名空间以及构造函数
- $constructor = $reflect->getConstructor();
-
- if ($constructor) {
- //处理传递的参数
- $args = $this->bindParams($constructor, $vars);
- } else {
- $args = [];
- }
-
- //返回创建的新实例 从给出的参数创建一个新的类实例
- return $reflect->newInstanceArgs($args);
- }
-
- /**
- * 绑定参数
- * @access protected
- * @param \ReflectionMethod|\ReflectionFunction $reflect 反射类
- * @param array $vars 变量
- * @return array
- */
- protected function bindParams($reflect, $vars = [])
- {
- $args = [];
-
- // $reflect 代表ReflectionFunction 或者 ReflectionMethod 实例
- // getNumberOfParameters() 获取的是函数或者方法需要的参数个数 如:function($1,$2,$3)
- if ($reflect->getNumberOfParameters() > 0) {
- // 判断数组类型 数字数组时按顺序绑定参数
- // 将数组的内部指针指向第一个单元
- reset($vars);
- $type = key($vars) === 0 ? 1 : 0;
-
- //获取函数或者方法内 参数额变量名
- $params = $reflect->getParameters();
-
- foreach ($params as $param) {
- //变量名称
- $name = $param->getName();
- //所属类
- $class = $param->getClass();
-
- //判断类是否有值
- if ($class) {
- //获取类的命名空间名称
- $className = $class->getName();
- $args[] = $this->make($className);
- } elseif (1 == $type && !empty($vars)) {
- //删除数组中的第一个元素
- $args[] = array_shift($vars);
- } elseif (0 == $type && isset($vars[$name])) {
- $args[] = $vars[$name];
- } elseif ($param->isDefaultValueAvailable()) {
- $args[] = $param->getDefaultValue();
- } else {
- throw new InvalidArgumentException('method param miss:' . $name);
- }
- }
- }
-
- return $args;
- }
-
-}
diff --git a/thinkphp/library/think/Controller.php b/thinkphp/library/think/Controller.php
deleted file mode 100644
index cc3953d..0000000
--- a/thinkphp/library/think/Controller.php
+++ /dev/null
@@ -1,242 +0,0 @@
-
-// +----------------------------------------------------------------------
-
-namespace think;
-
-use think\exception\ValidateException;
-use traits\controller\Jump;
-
-class Controller
-{
- use Jump;
-
- /**
- * 视图类实例
- * @var \think\View
- */
- protected $view;
-
- /**
- * Request实例
- * @var \think\Request
- */
- protected $request;
-
- /**
- * 应用实例
- * @var \think\App
- */
- protected $app;
-
- /**
- * 验证失败是否抛出异常
- * @var bool
- */
- protected $failException = false;
-
- /**
- * 是否批量验证
- * @var bool
- */
- protected $batchValidate = false;
-
- /**
- * 前置操作方法列表
- * @var array $beforeActionList
- */
- protected $beforeActionList = [];
-
- /**
- * 构造方法
- * @access public
- */
- public function __construct()
- {
- $this->request = Container::get('request');
- $this->app = Container::get('app');
- $this->view = Container::get('view')->init(
- $this->app['config']->pull('template')
- );
-
- // 控制器初始化
- $this->initialize();
-
- // 前置操作方法
- if ($this->beforeActionList) {
- foreach ($this->beforeActionList as $method => $options) {
- is_numeric($method) ?
- $this->beforeAction($options) :
- $this->beforeAction($method, $options);
- }
- }
- }
-
- // 初始化
- protected function initialize()
- {}
-
- /**
- * 前置操作
- * @access protected
- * @param string $method 前置操作方法名
- * @param array $options 调用参数 ['only'=>[...]] 或者['except'=>[...]]
- */
- protected function beforeAction($method, $options = [])
- {
- if (isset($options['only'])) {
- if (is_string($options['only'])) {
- $options['only'] = explode(',', $options['only']);
- }
- if (!in_array($this->request->action(), $options['only'])) {
- return;
- }
- } elseif (isset($options['except'])) {
- if (is_string($options['except'])) {
- $options['except'] = explode(',', $options['except']);
- }
- if (in_array($this->request->action(), $options['except'])) {
- return;
- }
- }
-
- call_user_func([$this, $method]);
- }
-
- /**
- * 加载模板输出
- * @access protected
- * @param string $template 模板文件名
- * @param array $vars 模板输出变量
- * @param array $config 模板参数
- * @return mixed
- */
- protected function fetch($template = '', $vars = [], $config = [])
- {
- return $this->view->fetch($template, $vars, $config);
- }
-
- /**
- * 渲染内容输出
- * @access protected
- * @param string $content 模板内容
- * @param array $vars 模板输出变量
- * @param array $config 模板参数
- * @return mixed
- */
- protected function display($content = '', $vars = [], $config = [])
- {
- return $this->view->display($content, $vars, $config);
- }
-
- /**
- * 模板变量赋值
- * @access protected
- * @param mixed $name 要显示的模板变量
- * @param mixed $value 变量的值
- * @return $this
- */
- protected function assign($name, $value = '')
- {
- $this->view->assign($name, $value);
-
- return $this;
- }
-
- /**
- * 视图过滤
- * @access protected
- * @param Callable $filter 过滤方法或闭包
- * @return $this
- */
- protected function filter($filter)
- {
- $this->view->filter($filter);
-
- return $this;
- }
-
- /**
- * 初始化模板引擎
- * @access protected
- * @param array|string $engine 引擎参数
- * @return $this
- */
- protected function engine($engine)
- {
- $this->view->engine($engine);
-
- return $this;
- }
-
- /**
- * 设置验证失败后是否抛出异常
- * @access protected
- * @param bool $fail 是否抛出异常
- * @return $this
- */
- protected function validateFailException($fail = true)
- {
- $this->failException = $fail;
-
- return $this;
- }
-
- /**
- * 验证数据
- * @access protected
- * @param array $data 数据
- * @param string|array $validate 验证器名或者验证规则数组
- * @param array $message 提示信息
- * @param bool $batch 是否批量验证
- * @param mixed $callback 回调方法(闭包)
- * @return array|string|true
- * @throws ValidateException
- */
- protected function validate($data, $validate, $message = [], $batch = false, $callback = null)
- {
- if (is_array($validate)) {
- $v = $this->app->validate();
- $v->rule($validate);
- } else {
- if (strpos($validate, '.')) {
- // 支持场景
- list($validate, $scene) = explode('.', $validate);
- }
- $v = $this->app->validate($validate);
- if (!empty($scene)) {
- $v->scene($scene);
- }
- }
-
- // 是否批量验证
- if ($batch || $this->batchValidate) {
- $v->batch(true);
- }
-
- if (is_array($message)) {
- $v->message($message);
- }
-
- if ($callback && is_callable($callback)) {
- call_user_func_array($callback, [$v, &$data]);
- }
-
- if (!$v->check($data)) {
- if ($this->failException) {
- throw new ValidateException($v->getError());
- } else {
- return $v->getError();
- }
- } else {
- return true;
- }
- }
-}
diff --git a/thinkphp/library/think/Cookie.php b/thinkphp/library/think/Cookie.php
deleted file mode 100644
index c645fde..0000000
--- a/thinkphp/library/think/Cookie.php
+++ /dev/null
@@ -1,262 +0,0 @@
-
-// +----------------------------------------------------------------------
-
-namespace think;
-
-class Cookie
-{
- /**
- * 配置参数
- * @var array
- */
- protected $config = [
- // cookie 名称前缀
- 'prefix' => '',
- // cookie 保存时间
- 'expire' => 0,
- // cookie 保存路径
- 'path' => '/',
- // cookie 有效域名
- 'domain' => '',
- // cookie 启用安全传输
- 'secure' => false,
- // httponly设置
- 'httponly' => false,
- // 是否使用 setcookie
- 'setcookie' => true,
- ];
-
- /**
- * 是否初始化
- * @var bool
- */
- protected $init;
-
- /**
- * Cookie初始化
- * @access public
- * @param array $config
- * @return void
- */
- public function init(array $config = [])
- {
- if (empty($config)) {
- $config = Container::get('config')->pull('cookie');
- }
-
- $this->config = array_merge($this->config, array_change_key_case($config));
-
- if (!empty($this->config['httponly'])) {
- ini_set('session.cookie_httponly', 1);
- }
-
- $this->init = true;
- }
-
- /**
- * 设置或者获取cookie作用域(前缀)
- * @access public
- * @param string $prefix
- * @return string|void
- */
- public function prefix($prefix = '')
- {
- if (empty($prefix)) {
- return $this->config['prefix'];
- }
-
- $this->config['prefix'] = $prefix;
- }
-
- /**
- * Cookie 设置、获取、删除
- *
- * @access public
- * @param string $name cookie名称
- * @param mixed $value cookie值
- * @param mixed $option 可选参数 可能会是 null|integer|string
- * @return void
- */
- public function set($name, $value = '', $option = null)
- {
- !isset($this->init) && $this->init();
-
- // 参数设置(会覆盖黙认设置)
- if (!is_null($option)) {
- if (is_numeric($option)) {
- $option = ['expire' => $option];
- } elseif (is_string($option)) {
- parse_str($option, $option);
- }
-
- $config = array_merge($this->config, array_change_key_case($option));
- } else {
- $config = $this->config;
- }
-
- $name = $config['prefix'] . $name;
-
- // 设置cookie
- if (is_array($value)) {
- array_walk_recursive($value, [$this, 'jsonFormatProtect'], 'encode');
- $value = 'think:' . json_encode($value);
- }
-
- $expire = !empty($config['expire']) ? $_SERVER['REQUEST_TIME'] + intval($config['expire']) : 0;
-
- if ($config['setcookie']) {
- setcookie($name, $value, $expire, $config['path'], $config['domain'], $config['secure'], $config['httponly']);
- }
-
- $_COOKIE[$name] = $value;
- }
-
- /**
- * 永久保存Cookie数据
- * @access public
- * @param string $name cookie名称
- * @param mixed $value cookie值
- * @param mixed $option 可选参数 可能会是 null|integer|string
- * @return void
- */
- public function forever($name, $value = '', $option = null)
- {
- if (is_null($option) || is_numeric($option)) {
- $option = [];
- }
-
- $option['expire'] = 315360000;
-
- $this->set($name, $value, $option);
- }
-
- /**
- * 判断Cookie数据
- * @access public
- * @param string $name cookie名称
- * @param string|null $prefix cookie前缀
- * @return bool
- */
- public function has($name, $prefix = null)
- {
- !isset($this->init) && $this->init();
-
- $prefix = !is_null($prefix) ? $prefix : $this->config['prefix'];
- $name = $prefix . $name;
-
- return isset($_COOKIE[$name]);
- }
-
- /**
- * Cookie获取
- * @access public
- * @param string $name cookie名称 留空获取全部
- * @param string|null $prefix cookie前缀
- * @return mixed
- */
- public function get($name = '', $prefix = null)
- {
- !isset($this->init) && $this->init();
-
- $prefix = !is_null($prefix) ? $prefix : $this->config['prefix'];
- $key = $prefix . $name;
-
- if ('' == $name) {
- if ($prefix) {
- $value = [];
- foreach ($_COOKIE as $k => $val) {
- if (0 === strpos($k, $prefix)) {
- $value[$k] = $val;
- }
- }
- } else {
- $value = $_COOKIE;
- }
- } elseif (isset($_COOKIE[$key])) {
- $value = $_COOKIE[$key];
-
- if (0 === strpos($value, 'think:')) {
- $value = substr($value, 6);
- $value = json_decode($value, true);
- array_walk_recursive($value, [$this, 'jsonFormatProtect'], 'decode');
- }
- } else {
- $value = null;
- }
-
- return $value;
- }
-
- /**
- * Cookie删除
- * @access public
- * @param string $name cookie名称
- * @param string|null $prefix cookie前缀
- * @return void
- */
- public function delete($name, $prefix = null)
- {
- !isset($this->init) && $this->init();
-
- $config = $this->config;
- $prefix = !is_null($prefix) ? $prefix : $config['prefix'];
- $name = $prefix . $name;
-
- if ($config['setcookie']) {
- setcookie($name, '', $_SERVER['REQUEST_TIME'] - 3600, $config['path'], $config['domain'], $config['secure'], $config['httponly']);
- }
-
- // 删除指定cookie
- unset($_COOKIE[$name]);
- }
-
- /**
- * Cookie清空
- * @access public
- * @param string|null $prefix cookie前缀
- * @return void
- */
- public function clear($prefix = null)
- {
- // 清除指定前缀的所有cookie
- if (empty($_COOKIE)) {
- return;
- }
-
- !isset($this->init) && $this->init();
-
- // 要删除的cookie前缀,不指定则删除config设置的指定前缀
- $config = $this->config;
- $prefix = !is_null($prefix) ? $prefix : $config['prefix'];
-
- if ($prefix) {
- // 如果前缀为空字符串将不作处理直接返回
- foreach ($_COOKIE as $key => $val) {
- if (0 === strpos($key, $prefix)) {
- if ($config['setcookie']) {
- setcookie($key, '', $_SERVER['REQUEST_TIME'] - 3600, $config['path'], $config['domain'], $config['secure'], $config['httponly']);
- }
- unset($_COOKIE[$key]);
- }
- }
- }
-
- return;
- }
-
- private function jsonFormatProtect(&$val, $key, $type = 'encode')
- {
- if (!empty($val) && true !== $val) {
- $val = 'decode' == $type ? urldecode($val) : urlencode($val);
- }
- }
-
-}
diff --git a/thinkphp/library/think/Db.php b/thinkphp/library/think/Db.php
deleted file mode 100644
index 21770e0..0000000
--- a/thinkphp/library/think/Db.php
+++ /dev/null
@@ -1,69 +0,0 @@
-
-// +----------------------------------------------------------------------
-
-namespace think;
-
-/**
- * Class Db
- * @package think
- * @method \think\db\Query table(string $table) static 指定数据表(含前缀)
- * @method \think\db\Query name(string $name) static 指定数据表(不含前缀)
- * @method \think\db\Query where(mixed $field, string $op = null, mixed $condition = null) static 查询条件
- * @method \think\db\Query join(mixed $join, mixed $condition = null, string $type = 'INNER') static JOIN查询
- * @method \think\db\Query view(mixed $join, mixed $field = null, mixed $on = null, string $type = 'INNER') static 视图查询
- * @method \think\db\Query union(mixed $union, boolean $all = false) static UNION查询
- * @method \think\db\Query limit(mixed $offset, integer $length = null) static 查询LIMIT
- * @method \think\db\Query order(mixed $field, string $order = null) static 查询ORDER
- * @method \think\db\Query cache(mixed $key = null , integer $expire = null) static 设置查询缓存
- * @method mixed value(string $field) static 获取某个字段的值
- * @method array column(string $field, string $key = '') static 获取某个列的值
- * @method mixed find(mixed $data = null) static 查询单个记录
- * @method mixed select(mixed $data = null) static 查询多个记录
- * @method integer insert(array $data, boolean $replace = false, boolean $getLastInsID = false, string $sequence = null) static 插入一条记录
- * @method integer insertGetId(array $data, boolean $replace = false, string $sequence = null) static 插入一条记录并返回自增ID
- * @method integer insertAll(array $dataSet) static 插入多条记录
- * @method integer update(array $data) static 更新记录
- * @method integer delete(mixed $data = null) static 删除记录
- * @method boolean chunk(integer $count, callable $callback, string $column = null) static 分块获取数据
- * @method \Generator cursor(mixed $data = null) static 使用游标查找记录
- * @method mixed query(string $sql, array $bind = [], boolean $master = false, bool $pdo = false) static SQL查询
- * @method integer execute(string $sql, array $bind = [], boolean $fetch = false, boolean $getLastInsID = false, string $sequence = null) static SQL执行
- * @method \think\Paginator paginate(integer $listRows = 15, mixed $simple = null, array $config = []) static 分页查询
- * @method mixed transaction(callable $callback) static 执行数据库事务
- * @method void startTrans() static 启动事务
- * @method void commit() static 用于非自动提交状态下面的查询提交
- * @method void rollback() static 事务回滚
- * @method boolean batchQuery(array $sqlArray) static 批处理执行SQL语句
- * @method string getLastInsID($sequence = null) static 获取最近插入的ID
- */
-class Db
-{
- /**
- * 查询次数
- * @var integer
- */
- public static $queryTimes = 0;
-
- /**
- * 执行次数
- * @var integer
- */
- public static $executeTimes = 0;
-
- public static function __callStatic($method, $args)
- {
- $class = Container::get('config')->get('database.query') ?: '\\think\\db\\Query';
-
- $query = new $class();
-
- return call_user_func_array([$query, $method], $args);
- }
-}
diff --git a/thinkphp/library/think/Debug.php b/thinkphp/library/think/Debug.php
deleted file mode 100644
index 8a384e1..0000000
--- a/thinkphp/library/think/Debug.php
+++ /dev/null
@@ -1,259 +0,0 @@
-
-// +----------------------------------------------------------------------
-
-namespace think;
-
-use think\exception\ClassNotFoundException;
-use think\model\Collection as ModelCollection;
-use think\response\Redirect;
-
-class Debug
-{
- /**
- * 区间时间信息
- * @var array
- */
- protected $info = [];
-
- /**
- * 区间内存信息
- * @var array
- */
- protected $mem = [];
-
- /**
- * 应用对象
- * @var App
- */
- protected $app;
-
- public function __construct(App $app)
- {
- $this->app = $app;
- }
-
- /**
- * 记录时间(微秒)和内存使用情况
- * @access public
- * @param string $name 标记位置
- * @param mixed $value 标记值 留空则取当前 time 表示仅记录时间 否则同时记录时间和内存
- * @return void
- */
- public function remark($name, $value = '')
- {
- // 记录时间和内存使用
- $this->info[$name] = is_float($value) ? $value : microtime(true);
-
- if ('time' != $value) {
- $this->mem['mem'][$name] = is_float($value) ? $value : memory_get_usage();
- $this->mem['peak'][$name] = memory_get_peak_usage();
- }
- }
-
- /**
- * 统计某个区间的时间(微秒)使用情况
- * @access public
- * @param string $start 开始标签
- * @param string $end 结束标签
- * @param integer|string $dec 小数位
- * @return integer
- */
- public function getRangeTime($start, $end, $dec = 6)
- {
- if (!isset($this->info[$end])) {
- $this->info[$end] = microtime(true);
- }
-
- return number_format(($this->info[$end] - $this->info[$start]), $dec);
- }
-
- /**
- * 统计从开始到统计时的时间(微秒)使用情况
- * @access public
- * @param integer|string $dec 小数位
- * @return integer
- */
- public function getUseTime($dec = 6)
- {
- return number_format((microtime(true) - $this->app->getBeginTime()), $dec);
- }
-
- /**
- * 获取当前访问的吞吐率情况
- * @access public
- * @return string
- */
- public function getThroughputRate()
- {
- return number_format(1 / $this->getUseTime(), 2) . 'req/s';
- }
-
- /**
- * 记录区间的内存使用情况
- * @access public
- * @param string $start 开始标签
- * @param string $end 结束标签
- * @param integer|string $dec 小数位
- * @return string
- */
- public function getRangeMem($start, $end, $dec = 2)
- {
- if (!isset($this->mem['mem'][$end])) {
- $this->mem['mem'][$end] = memory_get_usage();
- }
-
- $size = $this->mem['mem'][$end] - $this->mem['mem'][$start];
- $a = ['B', 'KB', 'MB', 'GB', 'TB'];
- $pos = 0;
-
- while ($size >= 1024) {
- $size /= 1024;
- $pos++;
- }
-
- return round($size, $dec) . " " . $a[$pos];
- }
-
- /**
- * 统计从开始到统计时的内存使用情况
- * @access public
- * @param integer|string $dec 小数位
- * @return string
- */
- public function getUseMem($dec = 2)
- {
- $size = memory_get_usage() - $this->app->getBeginMem();
- $a = ['B', 'KB', 'MB', 'GB', 'TB'];
- $pos = 0;
-
- while ($size >= 1024) {
- $size /= 1024;
- $pos++;
- }
-
- return round($size, $dec) . " " . $a[$pos];
- }
-
- /**
- * 统计区间的内存峰值情况
- * @access public
- * @param string $start 开始标签
- * @param string $end 结束标签
- * @param integer|string $dec 小数位
- * @return string
- */
- public function getMemPeak($start, $end, $dec = 2)
- {
- if (!isset($this->mem['peak'][$end])) {
- $this->mem['peak'][$end] = memory_get_peak_usage();
- }
-
- $size = $this->mem['peak'][$end] - $this->mem['peak'][$start];
- $a = ['B', 'KB', 'MB', 'GB', 'TB'];
- $pos = 0;
-
- while ($size >= 1024) {
- $size /= 1024;
- $pos++;
- }
-
- return round($size, $dec) . " " . $a[$pos];
- }
-
- /**
- * 获取文件加载信息
- * @access public
- * @param bool $detail 是否显示详细
- * @return integer|array
- */
- public function getFile($detail = false)
- {
- if ($detail) {
- $files = get_included_files();
- $info = [];
-
- foreach ($files as $key => $file) {
- $info[] = $file . ' ( ' . number_format(filesize($file) / 1024, 2) . ' KB )';
- }
-
- return $info;
- }
-
- return count(get_included_files());
- }
-
- /**
- * 浏览器友好的变量输出
- * @access public
- * @param mixed $var 变量
- * @param boolean $echo 是否输出 默认为true 如果为false 则返回输出字符串
- * @param string $label 标签 默认为空
- * @param integer $flags htmlspecialchars flags
- * @return void|string
- */
- public function dump($var, $echo = true, $label = null, $flags = ENT_SUBSTITUTE)
- {
- $label = (null === $label) ? '' : rtrim($label) . ':';
- if ($var instanceof Model || $var instanceof ModelCollection) {
- $var = $var->toArray();
- }
-
- ob_start();
- var_dump($var);
-
- $output = ob_get_clean();
- $output = preg_replace('/\]\=\>\n(\s+)/m', '] => ', $output);
-
- if (PHP_SAPI == 'cli') {
- $output = PHP_EOL . $label . $output . PHP_EOL;
- } else {
- if (!extension_loaded('xdebug')) {
- $output = htmlspecialchars($output, $flags);
- }
- $output = '' . $label . $output . '
';
- }
- if ($echo) {
- echo($output);
- return;
- } else {
- return $output;
- }
- }
-
- public function inject(Response $response, &$content)
- {
- $config = $this->app['config']->pull('trace');
- $type = isset($config['type']) ? $config['type'] : 'Html';
- $class = false !== strpos($type, '\\') ? $type : '\\think\\debug\\' . ucwords($type);
- unset($config['type']);
-
- if (class_exists($class)) {
- $trace = new $class($config);
- } else {
- throw new ClassNotFoundException('class not exists:' . $class, $class);
- }
-
- if ($response instanceof Redirect) {
- //TODO 记录
- } else {
- $output = $trace->output($response, $this->app['log']->getLog());
- if (is_string($output)) {
- // trace调试信息注入
- $pos = strripos($content, '