├── .gitignore
├── thinkphp
├── .htaccess
├── logo.png
├── .gitignore
├── library
│ └── think
│ │ ├── console
│ │ ├── bin
│ │ │ ├── hiddeninput.exe
│ │ │ └── README.md
│ │ ├── command
│ │ │ ├── make
│ │ │ │ ├── stubs
│ │ │ │ │ ├── model.stub
│ │ │ │ │ ├── controller.plain.stub
│ │ │ │ │ ├── middleware.stub
│ │ │ │ │ ├── validate.stub
│ │ │ │ │ ├── controller.api.stub
│ │ │ │ │ └── controller.stub
│ │ │ │ ├── Model.php
│ │ │ │ ├── Middleware.php
│ │ │ │ ├── Validate.php
│ │ │ │ └── Controller.php
│ │ │ ├── Version.php
│ │ │ ├── Build.php
│ │ │ ├── RunServer.php
│ │ │ ├── Help.php
│ │ │ ├── Lists.php
│ │ │ ├── optimize
│ │ │ │ └── Route.php
│ │ │ ├── Clear.php
│ │ │ └── Make.php
│ │ ├── LICENSE
│ │ ├── output
│ │ │ ├── driver
│ │ │ │ ├── Nothing.php
│ │ │ │ └── Buffer.php
│ │ │ ├── question
│ │ │ │ └── Confirmation.php
│ │ │ └── formatter
│ │ │ │ └── Stack.php
│ │ └── input
│ │ │ └── Argument.php
│ │ ├── route
│ │ └── dispatch
│ │ │ ├── Response.php
│ │ │ ├── Redirect.php
│ │ │ ├── Callback.php
│ │ │ ├── View.php
│ │ │ └── Controller.php
│ │ ├── exception
│ │ ├── RouteNotFoundException.php
│ │ ├── HttpResponseException.php
│ │ ├── ClassNotFoundException.php
│ │ ├── TemplateNotFoundException.php
│ │ ├── ValidateException.php
│ │ ├── HttpException.php
│ │ ├── DbException.php
│ │ ├── PDOException.php
│ │ ├── ThrowableError.php
│ │ └── ErrorException.php
│ │ ├── config
│ │ └── driver
│ │ │ ├── Json.php
│ │ │ ├── Ini.php
│ │ │ └── Xml.php
│ │ ├── response
│ │ ├── Jump.php
│ │ ├── Json.php
│ │ ├── Jsonp.php
│ │ ├── View.php
│ │ └── Redirect.php
│ │ ├── facade
│ │ ├── Url.php
│ │ ├── Env.php
│ │ ├── Build.php
│ │ ├── Config.php
│ │ ├── Middleware.php
│ │ ├── Template.php
│ │ ├── Hook.php
│ │ ├── Cookie.php
│ │ ├── Lang.php
│ │ ├── View.php
│ │ ├── Debug.php
│ │ ├── Cache.php
│ │ ├── Session.php
│ │ ├── Response.php
│ │ ├── Log.php
│ │ ├── App.php
│ │ └── Route.php
│ │ ├── db
│ │ ├── Expression.php
│ │ ├── exception
│ │ │ ├── BindParamException.php
│ │ │ ├── ModelNotFoundException.php
│ │ │ └── DataNotFoundException.php
│ │ ├── builder
│ │ │ ├── Sqlite.php
│ │ │ └── Pgsql.php
│ │ └── connector
│ │ │ └── Sqlite.php
│ │ ├── model
│ │ ├── Pivot.php
│ │ ├── concern
│ │ │ └── TimeStamp.php
│ │ └── Collection.php
│ │ ├── process
│ │ ├── exception
│ │ │ ├── Faild.php
│ │ │ ├── Failed.php
│ │ │ └── Timeout.php
│ │ ├── Utils.php
│ │ └── pipes
│ │ │ └── Pipes.php
│ │ ├── Exception.php
│ │ ├── template
│ │ └── driver
│ │ │ └── File.php
│ │ └── Env.php
├── tpl
│ ├── default_index.tpl
│ └── dispatch_jump.tpl
├── composer.json
├── LICENSE.txt
├── phpunit.xml.dist
├── base.php
├── README.md
└── CONTRIBUTING.md
├── application
├── .htaccess
├── api
│ ├── model
│ │ ├── ChatRecord.php
│ │ ├── Clerk.php
│ │ ├── Visitor.php
│ │ └── Group.php
│ └── controller
│ │ ├── Visitor.php
│ │ ├── Upload.php
│ │ ├── ChatRecord.php
│ │ └── Clerk.php
├── client
│ ├── controller
│ │ ├── Visitor.php
│ │ ├── ChatRecord.php
│ │ ├── Clerk.php
│ │ └── Login.php
│ └── view
│ │ └── Login
│ │ └── index.html
├── common.php
├── command.php
├── provider.php
└── tags.php
├── extend
└── .gitignore
├── vendor
└── .gitignore
├── public
├── static
│ └── .gitignore
├── robots.txt
├── favicon.ico
├── pic
│ ├── 00.jpg
│ ├── a1.jpg
│ ├── a10.jpg
│ ├── a11.jpg
│ ├── a12.jpg
│ ├── a2.jpg
│ ├── a3.jpg
│ ├── a4.jpg
│ ├── a5.jpg
│ ├── a6.jpg
│ ├── a7.jpg
│ ├── a8.jpg
│ └── a9.jpg
├── uploads
│ ├── file
│ │ └── 20180827
│ │ │ ├── 2e2347165311879329f140960d44538b.jpg
│ │ │ ├── 317409a1f9dd4d4862f0c64f1dde7752.jpg
│ │ │ └── a512c13561e2db35b9637588bccd620a.doc
│ └── image
│ │ ├── 20180827
│ │ └── e8f9e6446b1c5c8d06e92470c7f1195e.jpg
│ │ ├── 20180829
│ │ ├── 7a17523090194124a7690124c916c65f.jpg
│ │ └── 880ab7e4521e01e6d8c431446f7fdba9.jpg
│ │ ├── 20180830
│ │ └── 258c39a9c097b151d308aa3417c233af.jpg
│ │ └── 20180831
│ │ ├── 25521fcd09b81203c0a31cf6435e63d5.jpg
│ │ └── 6454bba714b86e1f17578c93176d0391.jpg
├── .htaccess
├── router.php
└── index.php
├── readme
├── 01.png
├── 02.png
├── 03.png
└── 04.png
├── cat
├── route
└── route.php
├── README.md
├── think
├── composer.json
├── config
├── trace.php
├── middleware.php
├── console.php
├── cache.php
├── session.php
├── cookie.php
├── log.php
├── template.php
├── swoole.php
├── database.php
└── swoole_server.php
├── LICENSE.txt
└── .travis.yml
/.gitignore:
--------------------------------------------------------------------------------
1 | /nbproject
2 | /runtime
--------------------------------------------------------------------------------
/thinkphp/.htaccess:
--------------------------------------------------------------------------------
1 | deny from all
--------------------------------------------------------------------------------
/application/.htaccess:
--------------------------------------------------------------------------------
1 | deny from all
--------------------------------------------------------------------------------
/extend/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/vendor/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/public/static/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | User-agent: *
2 | Disallow:
3 |
--------------------------------------------------------------------------------
/readme/01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/readme/01.png
--------------------------------------------------------------------------------
/readme/02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/readme/02.png
--------------------------------------------------------------------------------
/readme/03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/readme/03.png
--------------------------------------------------------------------------------
/readme/04.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/readme/04.png
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/public/favicon.ico
--------------------------------------------------------------------------------
/public/pic/00.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/public/pic/00.jpg
--------------------------------------------------------------------------------
/public/pic/a1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/public/pic/a1.jpg
--------------------------------------------------------------------------------
/public/pic/a10.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/public/pic/a10.jpg
--------------------------------------------------------------------------------
/public/pic/a11.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/public/pic/a11.jpg
--------------------------------------------------------------------------------
/public/pic/a12.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/public/pic/a12.jpg
--------------------------------------------------------------------------------
/public/pic/a2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/public/pic/a2.jpg
--------------------------------------------------------------------------------
/public/pic/a3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/public/pic/a3.jpg
--------------------------------------------------------------------------------
/public/pic/a4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/public/pic/a4.jpg
--------------------------------------------------------------------------------
/public/pic/a5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/public/pic/a5.jpg
--------------------------------------------------------------------------------
/public/pic/a6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/public/pic/a6.jpg
--------------------------------------------------------------------------------
/public/pic/a7.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/public/pic/a7.jpg
--------------------------------------------------------------------------------
/public/pic/a8.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/public/pic/a8.jpg
--------------------------------------------------------------------------------
/public/pic/a9.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/public/pic/a9.jpg
--------------------------------------------------------------------------------
/thinkphp/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/thinkphp/logo.png
--------------------------------------------------------------------------------
/thinkphp/.gitignore:
--------------------------------------------------------------------------------
1 | /vendor
2 | composer.phar
3 | composer.lock
4 | .DS_Store
5 | Thumbs.db
6 | /phpunit.xml
7 | /.idea
8 | /.vscode
--------------------------------------------------------------------------------
/thinkphp/library/think/console/bin/hiddeninput.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/thinkphp/library/think/console/bin/hiddeninput.exe
--------------------------------------------------------------------------------
/public/uploads/file/20180827/2e2347165311879329f140960d44538b.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/public/uploads/file/20180827/2e2347165311879329f140960d44538b.jpg
--------------------------------------------------------------------------------
/public/uploads/file/20180827/317409a1f9dd4d4862f0c64f1dde7752.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/public/uploads/file/20180827/317409a1f9dd4d4862f0c64f1dde7752.jpg
--------------------------------------------------------------------------------
/public/uploads/file/20180827/a512c13561e2db35b9637588bccd620a.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/public/uploads/file/20180827/a512c13561e2db35b9637588bccd620a.doc
--------------------------------------------------------------------------------
/public/uploads/image/20180827/e8f9e6446b1c5c8d06e92470c7f1195e.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/public/uploads/image/20180827/e8f9e6446b1c5c8d06e92470c7f1195e.jpg
--------------------------------------------------------------------------------
/public/uploads/image/20180829/7a17523090194124a7690124c916c65f.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/public/uploads/image/20180829/7a17523090194124a7690124c916c65f.jpg
--------------------------------------------------------------------------------
/public/uploads/image/20180829/880ab7e4521e01e6d8c431446f7fdba9.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/public/uploads/image/20180829/880ab7e4521e01e6d8c431446f7fdba9.jpg
--------------------------------------------------------------------------------
/public/uploads/image/20180830/258c39a9c097b151d308aa3417c233af.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/public/uploads/image/20180830/258c39a9c097b151d308aa3417c233af.jpg
--------------------------------------------------------------------------------
/public/uploads/image/20180831/25521fcd09b81203c0a31cf6435e63d5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/public/uploads/image/20180831/25521fcd09b81203c0a31cf6435e63d5.jpg
--------------------------------------------------------------------------------
/public/uploads/image/20180831/6454bba714b86e1f17578c93176d0391.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phpvcl/oim/HEAD/public/uploads/image/20180831/6454bba714b86e1f17578c93176d0391.jpg
--------------------------------------------------------------------------------
/thinkphp/library/think/console/bin/README.md:
--------------------------------------------------------------------------------
1 | console 工具使用 hiddeninput.exe 在 windows 上隐藏密码输入,该二进制文件由第三方提供,相关源码和其他细节可以在 [Hidden Input](https://github.com/Seldaek/hidden-input) 找到。
2 |
--------------------------------------------------------------------------------
/application/api/model/ChatRecord.php:
--------------------------------------------------------------------------------
1 |
2 | Options +FollowSymlinks -Multiviews
3 | RewriteEngine On
4 |
5 | RewriteCond %{REQUEST_FILENAME} !-d
6 | RewriteCond %{REQUEST_FILENAME} !-f
7 | RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
8 |
9 |
--------------------------------------------------------------------------------
/application/client/controller/Visitor.php:
--------------------------------------------------------------------------------
1 | fetch('Visitor/index');
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/application/client/controller/ChatRecord.php:
--------------------------------------------------------------------------------
1 | fetch('ChatRecord/index');
22 | }
23 |
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/thinkphp/library/think/console/command/make/stubs/validate.stub:
--------------------------------------------------------------------------------
1 | ['规则1','规则2'...]
12 | *
13 | * @var array
14 | */
15 | protected $rule = [];
16 |
17 | /**
18 | * 定义错误信息
19 | * 格式:'字段名.规则名' => '错误信息'
20 | *
21 | * @var array
22 | */
23 | protected $message = [];
24 | }
25 |
--------------------------------------------------------------------------------
/application/client/controller/Clerk.php:
--------------------------------------------------------------------------------
1 | redirect('/client/Login/index');
24 | }
25 | return $this->fetch('Clerk/index');
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/application/api/model/Group.php:
--------------------------------------------------------------------------------
1 | hasMany('Clerk', 'group_id');
19 | }
20 | public function withAllClerk()
21 | {
22 | return $this->with('Clerk');
23 | }
24 | public function withClerk($id)
25 | {
26 | return $this->with(['Clerk' => function($query)use($id){
27 | $query->where('id', '<>', $id);
28 | }]);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/application/common.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | // 应用公共文件
13 |
--------------------------------------------------------------------------------
/route/route.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 | return [
12 |
13 | ];
14 |
--------------------------------------------------------------------------------
/application/command.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | return [];
13 |
--------------------------------------------------------------------------------
/application/provider.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | // 应用容器绑定定义
13 | return [
14 | ];
15 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### 功能
2 |
3 | 目前完成了基础通信、上下线通知、离线消息、发送图片、发送文件、聊天记录。访客端的用户体验还不是很友好
4 |
5 |
6 | ### 网站目录
7 | ./application/api 接口
8 | ./application/client 访客端与客服端
9 | ./application/server 服务端
10 | ./application/admin 没做,就客服管理而已
11 |
12 | ### 配置说明
13 | 数据库这些配置直接改./config/database.php就好了
14 | 服务端地址配置是与当前网站一致,如网站路径配置为:http://www.oim.com/
15 | 那么服务端地址就是:ws://www.oim.com:9501
16 |
17 |
18 | ### 其他注意
19 |
20 | 注意$server->connections会话连接池,需要安装pcre组件的支持,并重新编译swoole,不然是空值。
21 |
22 |
23 | 
24 |
25 | 
26 |
27 | 
28 |
29 | 
30 |
--------------------------------------------------------------------------------
/public/router.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 | // $Id$
12 |
13 | if (is_file($_SERVER["DOCUMENT_ROOT"] . $_SERVER["SCRIPT_NAME"])) {
14 | return false;
15 | } else {
16 | require __DIR__ . "/index.php";
17 | }
18 |
--------------------------------------------------------------------------------
/public/index.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | // [ 应用入口文件 ]
13 | namespace think;
14 |
15 | // 加载基础文件
16 | require __DIR__ . '/../thinkphp/base.php';
17 |
18 | // 支持事先使用静态方法设置Request对象和Config对象
19 |
20 | // 执行应用并响应
21 | Container::get('app')->run()->send();
22 |
--------------------------------------------------------------------------------
/think:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 |
11 | // +----------------------------------------------------------------------
12 |
13 | namespace think;
14 |
15 | // 加载基础文件
16 | require __DIR__ . '/thinkphp/base.php';
17 |
18 | // 应用初始化
19 | Container::get('app')->path(__DIR__ . '/application/')->initialize();
20 |
21 | // 控制台初始化
22 | Console::init();
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "topthink/think",
3 | "description": "the new thinkphp framework",
4 | "type": "project",
5 | "keywords": [
6 | "framework",
7 | "thinkphp",
8 | "ORM"
9 | ],
10 | "homepage": "http://thinkphp.cn/",
11 | "license": "Apache-2.0",
12 | "authors": [
13 | {
14 | "name": "liu21st",
15 | "email": "liu21st@gmail.com"
16 | }
17 | ],
18 | "require": {
19 | "php": ">=5.6.0",
20 | "topthink/framework": "5.1.*",
21 | "topthink/think-swoole": "^2.0",
22 | "topthink/think-mongo": "^2.0"
23 | },
24 | "autoload": {
25 | "psr-4": {
26 | "app\\": "application"
27 | }
28 | },
29 | "extra": {
30 | "think-path": "thinkphp"
31 | },
32 | "config": {
33 | "preferred-install": "dist"
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/thinkphp/library/think/route/dispatch/Response.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\route\dispatch;
13 |
14 | use think\route\Dispatch;
15 |
16 | class Response extends Dispatch
17 | {
18 | public function exec()
19 | {
20 | return $this->dispatch;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/config/trace.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | // +----------------------------------------------------------------------
13 | // | Trace设置 开启 app_trace 后 有效
14 | // +----------------------------------------------------------------------
15 | return [
16 | // 内置Html Console 支持扩展
17 | 'type' => 'Html',
18 | ];
19 |
--------------------------------------------------------------------------------
/config/middleware.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | // +----------------------------------------------------------------------
13 | // | 中间件配置
14 | // +----------------------------------------------------------------------
15 | return [
16 | // 默认中间件命名空间
17 | 'default_namespace' => 'app\\http\\middleware\\',
18 | ];
19 |
--------------------------------------------------------------------------------
/thinkphp/library/think/exception/RouteNotFoundException.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\exception;
13 |
14 | class RouteNotFoundException extends HttpException
15 | {
16 |
17 | public function __construct()
18 | {
19 | parent::__construct(404, 'Route Not Found');
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/config/console.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | // +----------------------------------------------------------------------
13 | // | 控制台配置
14 | // +----------------------------------------------------------------------
15 | return [
16 | 'name' => 'Think Console',
17 | 'version' => '0.1',
18 | 'user' => null,
19 | ];
20 |
--------------------------------------------------------------------------------
/thinkphp/tpl/default_index.tpl:
--------------------------------------------------------------------------------
1 | *{ 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 V5.1
12载初心不改(2006-2018) - 你值得信赖的PHP框架
';
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/thinkphp/library/think/route/dispatch/Redirect.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\route\dispatch;
13 |
14 | use think\Response;
15 | use think\route\Dispatch;
16 |
17 | class Redirect extends Dispatch
18 | {
19 | public function exec()
20 | {
21 | return Response::create($this->dispatch, 'redirect')->code($this->code);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/config/cache.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | // +----------------------------------------------------------------------
13 | // | 缓存设置
14 | // +----------------------------------------------------------------------
15 |
16 | return [
17 | // 驱动方式
18 | 'type' => 'File',
19 | // 缓存保存目录
20 | 'path' => '',
21 | // 缓存前缀
22 | 'prefix' => '',
23 | // 缓存有效期 0表示永久缓存
24 | 'expire' => 0,
25 | ];
26 |
--------------------------------------------------------------------------------
/application/tags.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | // 应用行为扩展定义文件
13 | return [
14 | // 应用初始化
15 | 'app_init' => [],
16 | // 应用开始
17 | 'app_begin' => [],
18 | // 模块初始化
19 | 'module_init' => [],
20 | // 操作开始执行
21 | 'action_begin' => [],
22 | // 视图内容过滤
23 | 'view_filter' => [],
24 | // 日志写入
25 | 'log_write' => [],
26 | // 应用结束
27 | 'app_end' => [],
28 | ];
29 |
--------------------------------------------------------------------------------
/thinkphp/library/think/route/dispatch/Callback.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\route\dispatch;
13 |
14 | use think\route\Dispatch;
15 |
16 | class Callback extends Dispatch
17 | {
18 | public function exec()
19 | {
20 | // 执行回调方法
21 | $vars = array_merge($this->request->param(), $this->param);
22 |
23 | return $this->app->invoke($this->dispatch, $vars);
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/thinkphp/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "topthink/framework",
3 | "description": "the new thinkphp framework",
4 | "type": "think-framework",
5 | "keywords": [
6 | "framework",
7 | "thinkphp",
8 | "ORM"
9 | ],
10 | "homepage": "http://thinkphp.cn/",
11 | "license": "Apache-2.0",
12 | "authors": [
13 | {
14 | "name": "liu21st",
15 | "email": "liu21st@gmail.com"
16 | },
17 | {
18 | "name": "yunwuxin",
19 | "email": "448901948@qq.com"
20 | }
21 | ],
22 | "require": {
23 | "php": ">=5.6.0",
24 | "topthink/think-installer": "2.*"
25 | },
26 | "require-dev": {
27 | "phpunit/phpunit": "^5.0|^6.0",
28 | "johnkary/phpunit-speedtrap": "^1.0",
29 | "mikey179/vfsStream": "~1.6",
30 | "phploc/phploc": "2.*",
31 | "sebastian/phpcpd": "2.*",
32 | "squizlabs/php_codesniffer": "2.*",
33 | "phpdocumentor/reflection-docblock": "^2.0"
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/thinkphp/library/think/route/dispatch/View.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\route\dispatch;
13 |
14 | use think\Response;
15 | use think\route\Dispatch;
16 |
17 | class View extends Dispatch
18 | {
19 | public function exec()
20 | {
21 | // 渲染模板输出
22 | $vars = array_merge($this->request->param(), $this->param);
23 |
24 | return Response::create($this->dispatch, 'view')->assign($vars);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/thinkphp/library/think/config/driver/Json.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\config\driver;
13 |
14 | class Json
15 | {
16 | protected $config;
17 |
18 | public function __construct($config)
19 | {
20 | if (is_file($config)) {
21 | $config = file_get_contents($config);
22 | }
23 |
24 | $this->config = $config;
25 | }
26 |
27 | public function parse()
28 | {
29 | return json_decode($this->config, true);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/thinkphp/library/think/config/driver/Ini.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\config\driver;
13 |
14 | class Ini
15 | {
16 | protected $config;
17 |
18 | public function __construct($config)
19 | {
20 | $this->config = $config;
21 | }
22 |
23 | public function parse()
24 | {
25 | if (is_file($this->config)) {
26 | return parse_ini_file($this->config, true);
27 | } else {
28 | return parse_ini_string($this->config, true);
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/thinkphp/library/think/exception/HttpResponseException.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\exception;
13 |
14 | use think\Response;
15 |
16 | class HttpResponseException extends \RuntimeException
17 | {
18 | /**
19 | * @var Response
20 | */
21 | protected $response;
22 |
23 | public function __construct(Response $response)
24 | {
25 | $this->response = $response;
26 | }
27 |
28 | public function getResponse()
29 | {
30 | return $this->response;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/config/session.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | // +----------------------------------------------------------------------
13 | // | 会话设置
14 | // +----------------------------------------------------------------------
15 |
16 | return [
17 | 'id' => '',
18 | // SESSION_ID的提交变量,解决flash上传跨域
19 | 'var_session_id' => '',
20 | // SESSION 前缀
21 | 'prefix' => 'think',
22 | // 驱动方式 支持redis memcache memcached
23 | 'type' => '',
24 | // 是否自动开启 SESSION
25 | 'auto_start' => true,
26 | ];
27 |
--------------------------------------------------------------------------------
/thinkphp/library/think/console/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2004-2016 Fabien Potencier
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is furnished
8 | to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
--------------------------------------------------------------------------------
/thinkphp/library/think/console/output/driver/Nothing.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\console\output\driver;
13 |
14 | use think\console\Output;
15 |
16 | class Nothing
17 | {
18 |
19 | public function __construct(Output $output)
20 | {
21 | // do nothing
22 | }
23 |
24 | public function write($messages, $newline = false, $options = Output::OUTPUT_NORMAL)
25 | {
26 | // do nothing
27 | }
28 |
29 | public function renderException(\Exception $e)
30 | {
31 | // do nothing
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/thinkphp/library/think/exception/ClassNotFoundException.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\exception;
13 |
14 | class ClassNotFoundException extends \RuntimeException
15 | {
16 | protected $class;
17 | public function __construct($message, $class = '')
18 | {
19 | $this->message = $message;
20 | $this->class = $class;
21 | }
22 |
23 | /**
24 | * 获取类名
25 | * @access public
26 | * @return string
27 | */
28 | public function getClass()
29 | {
30 | return $this->class;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/thinkphp/library/think/response/Jump.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\response;
13 |
14 | use think\Response;
15 |
16 | class Jump extends Response
17 | {
18 | protected $contentType = 'text/html';
19 |
20 | /**
21 | * 处理数据
22 | * @access protected
23 | * @param mixed $data 要处理的数据
24 | * @return mixed
25 | * @throws \Exception
26 | */
27 | protected function output($data)
28 | {
29 | $data = $this->app['view']->fetch($this->options['jump_template'], $data);
30 | return $data;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/thinkphp/library/think/route/dispatch/Controller.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\route\dispatch;
13 |
14 | use think\route\Dispatch;
15 |
16 | class Controller extends Dispatch
17 | {
18 | public function exec()
19 | {
20 | // 执行控制器的操作方法
21 | $vars = array_merge($this->request->param(), $this->param);
22 |
23 | return $this->app->action(
24 | $this->dispatch, $vars,
25 | $this->rule->getConfig('url_controller_layer'),
26 | $this->rule->getConfig('controller_suffix')
27 | );
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/thinkphp/library/think/exception/TemplateNotFoundException.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\exception;
13 |
14 | class TemplateNotFoundException extends \RuntimeException
15 | {
16 | protected $template;
17 |
18 | public function __construct($message, $template = '')
19 | {
20 | $this->message = $message;
21 | $this->template = $template;
22 | }
23 |
24 | /**
25 | * 获取模板文件
26 | * @access public
27 | * @return string
28 | */
29 | public function getTemplate()
30 | {
31 | return $this->template;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/config/cookie.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | // +----------------------------------------------------------------------
13 | // | Cookie设置
14 | // +----------------------------------------------------------------------
15 | return [
16 | // cookie 名称前缀
17 | 'prefix' => '',
18 | // cookie 保存时间
19 | 'expire' => 0,
20 | // cookie 保存路径
21 | 'path' => '/',
22 | // cookie 有效域名
23 | 'domain' => '',
24 | // cookie 启用安全传输
25 | 'secure' => false,
26 | // httponly设置
27 | 'httponly' => '',
28 | // 是否使用 setcookie
29 | 'setcookie' => true,
30 | ];
31 |
--------------------------------------------------------------------------------
/config/log.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | // +----------------------------------------------------------------------
13 | // | 日志设置
14 | // +----------------------------------------------------------------------
15 | return [
16 | // 日志记录方式,内置 file socket 支持扩展
17 | 'type' => 'File',
18 | // 日志保存目录
19 | 'path' => '',
20 | // 日志记录级别
21 | 'level' => [],
22 | // 单文件日志写入
23 | 'single' => false,
24 | // 独立日志级别
25 | 'apart_level' => [],
26 | // 最大日志文件数量
27 | 'max_files' => 0,
28 | // 是否关闭日志写入
29 | 'close' => false,
30 | ];
31 |
--------------------------------------------------------------------------------
/thinkphp/library/think/console/command/Version.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 | namespace think\console\command;
12 |
13 | use think\console\Command;
14 | use think\console\Input;
15 | use think\console\Output;
16 | use think\facade\App;
17 |
18 | class Version extends Command
19 | {
20 | protected function configure()
21 | {
22 | // 指令配置
23 | $this->setName('version')
24 | ->setDescription('show thinkphp framework version');
25 | }
26 |
27 | protected function execute(Input $input, Output $output)
28 | {
29 | $output->writeln('v' . App::version());
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/thinkphp/library/think/facade/Url.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\facade;
13 |
14 | use think\Facade;
15 |
16 | /**
17 | * @see \think\Url
18 | * @mixin \think\Url
19 | * @method string build(string $url = '', mixed $vars = '', mixed $suffix = true, mixed $domain = false) static URL生成 支持路由反射
20 | * @method void root(string $root) static 指定当前生成URL地址的root
21 | */
22 | class Url extends Facade
23 | {
24 | /**
25 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识)
26 | * @access protected
27 | * @return string
28 | */
29 | protected static function getFacadeClass()
30 | {
31 | return 'url';
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/thinkphp/library/think/exception/ValidateException.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\exception;
13 |
14 | class ValidateException extends \RuntimeException
15 | {
16 | protected $error;
17 |
18 | public function __construct($error, $code = 0)
19 | {
20 | $this->error = $error;
21 | $this->message = is_array($error) ? implode("\n\r", $error) : $error;
22 | $this->code = $code;
23 | }
24 |
25 | /**
26 | * 获取验证错误信息
27 | * @access public
28 | * @return array|string
29 | */
30 | public function getError()
31 | {
32 | return $this->error;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/thinkphp/library/think/console/command/make/stubs/controller.api.stub:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\facade;
13 |
14 | use think\Facade;
15 |
16 | /**
17 | * @see \think\Env
18 | * @mixin \think\Env
19 | * @method void load(string $file) static 读取环境变量定义文件
20 | * @method mixed get(string $name = null, mixed $default = null) static 获取环境变量值
21 | * @method void set(mixed $env, string $value = null) static 设置环境变量值
22 | */
23 | class Env extends Facade
24 | {
25 | /**
26 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识)
27 | * @access protected
28 | * @return string
29 | */
30 | protected static function getFacadeClass()
31 | {
32 | return 'env';
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/thinkphp/library/think/facade/Build.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\facade;
13 |
14 | use think\Facade;
15 |
16 | /**
17 | * @see \think\Build
18 | * @mixin \think\Build
19 | * @method void run(array $build = [], string $namespace = 'app', bool $suffix = false) static 根据传入的build资料创建目录和文件
20 | * @method void module(string $module = '', array $list = [], string $namespace = 'app', bool $suffix = false) static 创建模块
21 | */
22 | class Build extends Facade
23 | {
24 | /**
25 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识)
26 | * @access protected
27 | * @return string
28 | */
29 | protected static function getFacadeClass()
30 | {
31 | return 'build';
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/thinkphp/library/think/db/Expression.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\db;
13 |
14 | class Expression
15 | {
16 | /**
17 | * 查询表达式
18 | *
19 | * @var string
20 | */
21 | protected $value;
22 |
23 | /**
24 | * 创建一个查询表达式
25 | *
26 | * @param string $value
27 | * @return void
28 | */
29 | public function __construct($value)
30 | {
31 | $this->value = $value;
32 | }
33 |
34 | /**
35 | * 获取表达式
36 | *
37 | * @return string
38 | */
39 | public function getValue()
40 | {
41 | return $this->value;
42 | }
43 |
44 | public function __toString()
45 | {
46 | return (string) $this->value;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/thinkphp/library/think/exception/HttpException.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\exception;
13 |
14 | class HttpException extends \RuntimeException
15 | {
16 | private $statusCode;
17 | private $headers;
18 |
19 | public function __construct($statusCode, $message = null, \Exception $previous = null, array $headers = [], $code = 0)
20 | {
21 | $this->statusCode = $statusCode;
22 | $this->headers = $headers;
23 |
24 | parent::__construct($message, $code, $previous);
25 | }
26 |
27 | public function getStatusCode()
28 | {
29 | return $this->statusCode;
30 | }
31 |
32 | public function getHeaders()
33 | {
34 | return $this->headers;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/thinkphp/library/think/console/command/make/Model.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\console\command\make;
13 |
14 | use think\console\command\Make;
15 |
16 | class Model extends Make
17 | {
18 | protected $type = "Model";
19 |
20 | protected function configure()
21 | {
22 | parent::configure();
23 | $this->setName('make:model')
24 | ->setDescription('Create a new model class');
25 | }
26 |
27 | protected function getStub()
28 | {
29 | return __DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'model.stub';
30 | }
31 |
32 | protected function getNamespace($appNamespace, $module)
33 | {
34 | return parent::getNamespace($appNamespace, $module) . '\model';
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/thinkphp/library/think/db/exception/BindParamException.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\db\exception;
13 |
14 | use think\exception\DbException;
15 |
16 | /**
17 | * PDO参数绑定异常
18 | */
19 | class BindParamException extends DbException
20 | {
21 |
22 | /**
23 | * BindParamException constructor.
24 | * @access public
25 | * @param string $message
26 | * @param array $config
27 | * @param string $sql
28 | * @param array $bind
29 | * @param int $code
30 | */
31 | public function __construct($message, $config, $sql, $bind, $code = 10502)
32 | {
33 | $this->setData('Bind Param', $bind);
34 | parent::__construct($message, $config, $sql, $code);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/config/template.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | // +----------------------------------------------------------------------
13 | // | 模板设置
14 | // +----------------------------------------------------------------------
15 |
16 | return [
17 | // 模板引擎类型 支持 php think 支持扩展
18 | 'type' => 'Think',
19 | // 默认模板渲染规则 1 解析为小写+下划线 2 全部转换小写 3 保持操作方法
20 | 'auto_rule' => 1,
21 | // 模板路径
22 | 'view_path' => '',
23 | // 模板后缀
24 | 'view_suffix' => 'html',
25 | // 模板文件名分隔符
26 | 'view_depr' => DIRECTORY_SEPARATOR,
27 | // 模板引擎普通标签开始标记
28 | 'tpl_begin' => '{',
29 | // 模板引擎普通标签结束标记
30 | 'tpl_end' => '}',
31 | // 标签库标签开始标记
32 | 'taglib_begin' => '{',
33 | // 标签库标签结束标记
34 | 'taglib_end' => '}',
35 | ];
36 |
--------------------------------------------------------------------------------
/thinkphp/library/think/model/Pivot.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\model;
13 |
14 | use think\Model;
15 |
16 | class Pivot extends Model
17 | {
18 |
19 | /** @var Model */
20 | public $parent;
21 |
22 | protected $autoWriteTimestamp = false;
23 |
24 | /**
25 | * 架构函数
26 | * @access public
27 | * @param array|object $data 数据
28 | * @param Model $parent 上级模型
29 | * @param string $table 中间数据表名
30 | */
31 | public function __construct($data = [], Model $parent = null, $table = '')
32 | {
33 | $this->parent = $parent;
34 |
35 | if (is_null($this->name)) {
36 | $this->name = $table;
37 | }
38 |
39 | parent::__construct($data);
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/thinkphp/library/think/facade/Config.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\facade;
13 |
14 | use think\Facade;
15 |
16 | /**
17 | * @see \think\Config
18 | * @mixin \think\Config
19 | * @method bool has(string $name) static 检测配置是否存在
20 | * @method array pull(string $name) static 获取一级配置
21 | * @method mixed get(string $name,mixed $default = null) static 获取配置参数
22 | * @method mixed set(string $name, mixed $value = null) static 设置配置参数
23 | * @method array reset(string $prefix ='') static 重置配置参数
24 | */
25 | class Config extends Facade
26 | {
27 | /**
28 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识)
29 | * @access protected
30 | * @return string
31 | */
32 | protected static function getFacadeClass()
33 | {
34 | return 'config';
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/thinkphp/library/think/config/driver/Xml.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\config\driver;
13 |
14 | class Xml
15 | {
16 | protected $config;
17 |
18 | public function __construct($config)
19 | {
20 | $this->config = $config;
21 | }
22 |
23 | public function parse()
24 | {
25 | if (is_file($this->config)) {
26 | $content = simplexml_load_file($this->config);
27 | } else {
28 | $content = simplexml_load_string($this->config);
29 | }
30 |
31 | $result = (array) $content;
32 | foreach ($result as $key => $val) {
33 | if (is_object($val)) {
34 | $result[$key] = (array) $val;
35 | }
36 | }
37 |
38 | return $result;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | ThinkPHP遵循Apache2开源协议发布,并提供免费使用。
3 | 版权所有Copyright © 2006-2016 by ThinkPHP (http://thinkphp.cn)
4 | All rights reserved。
5 | ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
6 |
7 | Apache Licence是著名的非盈利开源组织Apache采用的协议。
8 | 该协议和BSD类似,鼓励代码共享和尊重原作者的著作权,
9 | 允许代码修改,再作为开源或商业软件发布。需要满足
10 | 的条件:
11 | 1. 需要给代码的用户一份Apache Licence ;
12 | 2. 如果你修改了代码,需要在被修改的文件中说明;
13 | 3. 在延伸的代码中(修改和有源代码衍生的代码中)需要
14 | 带有原来代码中的协议,商标,专利声明和其他原来作者规
15 | 定需要包含的说明;
16 | 4. 如果再发布的产品中包含一个Notice文件,则在Notice文
17 | 件中需要带有本协议内容。你可以在Notice中增加自己的
18 | 许可,但不可以表现为对Apache Licence构成更改。
19 | 具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0
20 |
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 | POSSIBILITY OF SUCH DAMAGE.
33 |
--------------------------------------------------------------------------------
/thinkphp/library/think/console/command/make/Middleware.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\console\command\make;
13 |
14 | use think\console\command\Make;
15 |
16 | class Middleware extends Make
17 | {
18 | protected $type = "Middleware";
19 |
20 | protected function configure()
21 | {
22 | parent::configure();
23 | $this->setName('make:middleware')
24 | ->setDescription('Create a new middleware class');
25 | }
26 |
27 | protected function getStub()
28 | {
29 | return __DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'middleware.stub';
30 | }
31 |
32 | protected function getNamespace($appNamespace, $module)
33 | {
34 | return parent::getNamespace($appNamespace, 'http') . '\middleware';
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/thinkphp/library/think/facade/Middleware.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\facade;
13 |
14 | use think\Facade;
15 |
16 | /**
17 | * @see \think\Middleware
18 | * @mixin \think\Middleware
19 | * @method void import(array $middlewares = []) static 批量设置中间件
20 | * @method void add(mixed $middleware) static 添加中间件到队列
21 | * @method void unshift(mixed $middleware) static 添加中间件到队列开头
22 | * @method array all() static 获取中间件队列
23 | * @method \think\Response dispatch(\think\Request $request) static 执行中间件调度
24 | */
25 | class Middleware extends Facade
26 | {
27 | /**
28 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识)
29 | * @access protected
30 | * @return string
31 | */
32 | protected static function getFacadeClass()
33 | {
34 | return 'middleware';
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/thinkphp/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | ThinkPHP遵循Apache2开源协议发布,并提供免费使用。
3 | 版权所有Copyright © 2006-2016 by ThinkPHP (http://thinkphp.cn)
4 | All rights reserved。
5 | ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
6 |
7 | Apache Licence是著名的非盈利开源组织Apache采用的协议。
8 | 该协议和BSD类似,鼓励代码共享和尊重原作者的著作权,
9 | 允许代码修改,再作为开源或商业软件发布。需要满足
10 | 的条件:
11 | 1. 需要给代码的用户一份Apache Licence ;
12 | 2. 如果你修改了代码,需要在被修改的文件中说明;
13 | 3. 在延伸的代码中(修改和有源代码衍生的代码中)需要
14 | 带有原来代码中的协议,商标,专利声明和其他原来作者规
15 | 定需要包含的说明;
16 | 4. 如果再发布的产品中包含一个Notice文件,则在Notice文
17 | 件中需要带有本协议内容。你可以在Notice中增加自己的
18 | 许可,但不可以表现为对Apache Licence构成更改。
19 | 具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0
20 |
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 | POSSIBILITY OF SUCH DAMAGE.
33 |
--------------------------------------------------------------------------------
/application/api/controller/Visitor.php:
--------------------------------------------------------------------------------
1 | request->post('id/d');
26 | $referrer = $this->request->post('referrer');
27 | $url = $this->request->post('url');
28 | $ip = $this->request->server('REMOTE_ADDR');
29 | $userAgent = $this->request->server('HTTP_USER_AGENT');
30 | $result = ['code' => 404, 'data' => []];
31 |
32 | $model = new MyModel();
33 | if (!$model->get($id))
34 | {
35 | $data = ['referrer'=>$referrer, 'url'=>$url, 'ip'=> ip2long($ip), 'user_agent'=>$userAgent, 'create_time'=>time()];
36 | $rs = $model->save($data);
37 | if ($rs)
38 | {
39 | $result['code'] = 200;
40 | $result['data']['id'] = $model->id;
41 | }
42 | }else{
43 | $result['code'] = 200;
44 | $result['data']['id'] = $id;
45 | }
46 |
47 | return json($result);
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/thinkphp/library/think/console/command/make/Validate.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\console\command\make;
13 |
14 | use think\console\command\Make;
15 |
16 | class Validate extends Make
17 | {
18 |
19 | protected $type = "Validate";
20 |
21 | protected function configure()
22 | {
23 | parent::configure();
24 | $this->setName('make:validate')
25 | ->setDescription('Create a validate class');
26 | }
27 |
28 | protected function getStub()
29 | {
30 | $stubPath = __DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR;
31 |
32 | return $stubPath . 'validate.stub';
33 | }
34 |
35 | protected function getNamespace($appNamespace, $module)
36 | {
37 | return parent::getNamespace($appNamespace, $module) . '\validate';
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/thinkphp/library/think/facade/Template.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\facade;
13 |
14 | use think\Facade;
15 |
16 | /**
17 | * @see \think\Template
18 | * @mixin \think\Template
19 | * @method void assign(mixed $name, mixed $value = '') static 模板变量赋值
20 | * @method mixed get(string $name = '') static 获取模板变量
21 | * @method void fetch(string $template, array $vars = [], array $config = []) static 渲染模板文件
22 | * @method void display(string $content, array $vars = [], array $config = []) static 渲染模板内容
23 | * @method mixed layout(string $name, string $replace = '') static 设置模板布局
24 | */
25 | class Template extends Facade
26 | {
27 | /**
28 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识)
29 | * @access protected
30 | * @return string
31 | */
32 | protected static function getFacadeClass()
33 | {
34 | return 'template';
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/thinkphp/library/think/db/exception/ModelNotFoundException.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\db\exception;
13 |
14 | use think\exception\DbException;
15 |
16 | class ModelNotFoundException extends DbException
17 | {
18 | protected $model;
19 |
20 | /**
21 | * 构造方法
22 | * @access public
23 | * @param string $message
24 | * @param string $model
25 | * @param array $config
26 | */
27 | public function __construct($message, $model = '', array $config = [])
28 | {
29 | $this->message = $message;
30 | $this->model = $model;
31 |
32 | $this->setData('Database Config', $config);
33 | }
34 |
35 | /**
36 | * 获取模型类名
37 | * @access public
38 | * @return string
39 | */
40 | public function getModel()
41 | {
42 | return $this->model;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/thinkphp/library/think/db/exception/DataNotFoundException.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\db\exception;
13 |
14 | use think\exception\DbException;
15 |
16 | class DataNotFoundException extends DbException
17 | {
18 | protected $table;
19 |
20 | /**
21 | * DbException constructor.
22 | * @access public
23 | * @param string $message
24 | * @param string $table
25 | * @param array $config
26 | */
27 | public function __construct($message, $table = '', array $config = [])
28 | {
29 | $this->message = $message;
30 | $this->table = $table;
31 |
32 | $this->setData('Database Config', $config);
33 | }
34 |
35 | /**
36 | * 获取数据表名
37 | * @access public
38 | * @return string
39 | */
40 | public function getTable()
41 | {
42 | return $this->table;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/thinkphp/library/think/facade/Hook.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\facade;
13 |
14 | use think\Facade;
15 |
16 | /**
17 | * @see \think\Hook
18 | * @mixin \think\Hook
19 | * @method \think\Hook alias(mixed $name, mixed $behavior = null) static 指定行为标识
20 | * @method void add(string $tag, mixed $behavior, bool $first = false) static 动态添加行为扩展到某个标签
21 | * @method void import(array $tags, bool $recursive = true) static 批量导入插件
22 | * @method array get(string $tag = '') static 获取插件信息
23 | * @method mixed listen(string $tag, mixed $params = null, bool $once = false) static 监听标签的行为
24 | * @method mixed exec(mixed $class, mixed $params = null) static 执行行为
25 | */
26 | class Hook extends Facade
27 | {
28 | /**
29 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识)
30 | * @access protected
31 | * @return string
32 | */
33 | protected static function getFacadeClass()
34 | {
35 | return 'hook';
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/thinkphp/library/think/exception/DbException.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\exception;
13 |
14 | use think\Exception;
15 |
16 | /**
17 | * Database相关异常处理类
18 | */
19 | class DbException extends Exception
20 | {
21 | /**
22 | * DbException constructor.
23 | * @access public
24 | * @param string $message
25 | * @param array $config
26 | * @param string $sql
27 | * @param int $code
28 | */
29 | public function __construct($message, array $config, $sql, $code = 10500)
30 | {
31 | $this->message = $message;
32 | $this->code = $code;
33 |
34 | $this->setData('Database Status', [
35 | 'Error Code' => $code,
36 | 'Error Message' => $message,
37 | 'Error SQL' => $sql,
38 | ]);
39 |
40 | unset($config['username'], $config['password']);
41 | $this->setData('Database Config', $config);
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/thinkphp/library/think/console/output/driver/Buffer.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\console\output\driver;
13 |
14 | use think\console\Output;
15 |
16 | class Buffer
17 | {
18 | /**
19 | * @var string
20 | */
21 | private $buffer = '';
22 |
23 | public function __construct(Output $output)
24 | {
25 | // do nothing
26 | }
27 |
28 | public function fetch()
29 | {
30 | $content = $this->buffer;
31 | $this->buffer = '';
32 | return $content;
33 | }
34 |
35 | public function write($messages, $newline = false, $options = Output::OUTPUT_NORMAL)
36 | {
37 | $messages = (array) $messages;
38 |
39 | foreach ($messages as $message) {
40 | $this->buffer .= $message;
41 | }
42 | if ($newline) {
43 | $this->buffer .= "\n";
44 | }
45 | }
46 |
47 | public function renderException(\Exception $e)
48 | {
49 | // do nothing
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/thinkphp/library/think/exception/PDOException.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\exception;
13 |
14 | /**
15 | * PDO异常处理类
16 | * 重新封装了系统的\PDOException类
17 | */
18 | class PDOException extends DbException
19 | {
20 | /**
21 | * PDOException constructor.
22 | * @access public
23 | * @param \PDOException $exception
24 | * @param array $config
25 | * @param string $sql
26 | * @param int $code
27 | */
28 | public function __construct(\PDOException $exception, array $config, $sql, $code = 10501)
29 | {
30 | $error = $exception->errorInfo;
31 |
32 | $this->setData('PDO Error Info', [
33 | 'SQLSTATE' => $error[0],
34 | 'Driver Error Code' => isset($error[1]) ? $error[1] : 0,
35 | 'Driver Error Message' => isset($error[2]) ? $error[2] : '',
36 | ]);
37 |
38 | parent::__construct($exception->getMessage(), $config, $sql, $code);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/thinkphp/phpunit.xml.dist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | ./library/think/*/tests/
27 |
28 |
29 |
30 |
31 |
32 | ./library/
33 |
34 | ./library/think/*/tests
35 | ./library/think/*/assets
36 | ./library/think/*/resources
37 | ./library/think/*/vendor
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/thinkphp/library/think/console/command/make/stubs/controller.stub:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\process\exception;
13 |
14 | use think\Process;
15 |
16 | class Faild extends \RuntimeException
17 | {
18 |
19 | private $process;
20 |
21 | public function __construct(Process $process)
22 | {
23 | if ($process->isSuccessful()) {
24 | throw new \InvalidArgumentException('Expected a failed process, but the given process was successful.');
25 | }
26 |
27 | $error = sprintf('The command "%s" failed.' . "\nExit Code: %s(%s)", $process->getCommandLine(), $process->getExitCode(), $process->getExitCodeText());
28 |
29 | if (!$process->isOutputDisabled()) {
30 | $error .= sprintf("\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s", $process->getOutput(), $process->getErrorOutput());
31 | }
32 |
33 | parent::__construct($error);
34 |
35 | $this->process = $process;
36 | }
37 |
38 | public function getProcess()
39 | {
40 | return $this->process;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/thinkphp/library/think/process/exception/Failed.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\process\exception;
13 |
14 | use think\Process;
15 |
16 | class Failed extends \RuntimeException
17 | {
18 |
19 | private $process;
20 |
21 | public function __construct(Process $process)
22 | {
23 | if ($process->isSuccessful()) {
24 | throw new \InvalidArgumentException('Expected a failed process, but the given process was successful.');
25 | }
26 |
27 | $error = sprintf('The command "%s" failed.' . "\nExit Code: %s(%s)", $process->getCommandLine(), $process->getExitCode(), $process->getExitCodeText());
28 |
29 | if (!$process->isOutputDisabled()) {
30 | $error .= sprintf("\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s", $process->getOutput(), $process->getErrorOutput());
31 | }
32 |
33 | parent::__construct($error);
34 |
35 | $this->process = $process;
36 | }
37 |
38 | public function getProcess()
39 | {
40 | return $this->process;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/thinkphp/library/think/facade/Cookie.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\facade;
13 |
14 | use think\Facade;
15 |
16 | /**
17 | * @see \think\Cookie
18 | * @mixin \think\Cookie
19 | * @method void init(array $config = []) static 初始化
20 | * @method bool has(string $name,string $prefix = null) static 判断Cookie数据
21 | * @method mixed prefix(string $prefix = '') static 设置或者获取cookie作用域(前缀)
22 | * @method mixed get(string $name,string $prefix = null) static Cookie获取
23 | * @method mixed set(string $name, mixed $value = null, mixed $option = null) static 设置Cookie
24 | * @method void forever(string $name, mixed $value = null, mixed $option = null) static 永久保存Cookie数据
25 | * @method void delete(string $name, string $prefix = null) static Cookie删除
26 | * @method void clear($prefix = null) static Cookie清空
27 | */
28 | class Cookie extends Facade
29 | {
30 | /**
31 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识)
32 | * @access protected
33 | * @return string
34 | */
35 | protected static function getFacadeClass()
36 | {
37 | return 'cookie';
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/thinkphp/library/think/response/Json.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\response;
13 |
14 | use think\Response;
15 |
16 | class Json extends Response
17 | {
18 | // 输出参数
19 | protected $options = [
20 | 'json_encode_param' => JSON_UNESCAPED_UNICODE,
21 | ];
22 |
23 | protected $contentType = 'application/json';
24 |
25 | /**
26 | * 处理数据
27 | * @access protected
28 | * @param mixed $data 要处理的数据
29 | * @return mixed
30 | * @throws \Exception
31 | */
32 | protected function output($data)
33 | {
34 | try {
35 | // 返回JSON数据格式到客户端 包含状态信息
36 | $data = json_encode($data, $this->options['json_encode_param']);
37 |
38 | if (false === $data) {
39 | throw new \InvalidArgumentException(json_last_error_msg());
40 | }
41 |
42 | return $data;
43 | } catch (\Exception $e) {
44 | if ($e->getPrevious()) {
45 | throw $e->getPrevious();
46 | }
47 | throw $e;
48 | }
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/config/swoole.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | use think\facade\Env;
13 |
14 | // +----------------------------------------------------------------------
15 | // | Swoole设置 php think swoole命令行下有效
16 | // +----------------------------------------------------------------------
17 | return [
18 | // 扩展自身配置
19 | 'host' => '0.0.0.0', // 监听地址
20 | 'port' => 9501, // 监听端口
21 | 'mode' => '', // 运行模式 默认为SWOOLE_PROCESS
22 | 'sock_type' => '', // sock type 默认为SWOOLE_SOCK_TCP
23 | 'app_path' => '', // 应用地址 如果开启了 'daemonize'=>true 必须设置(使用绝对路径)
24 | 'file_monitor' => false, // 是否开启PHP文件更改监控(调试模式下自动开启)
25 | 'file_monitor_interval' => 2, // 文件变化监控检测时间间隔(秒)
26 | 'file_monitor_path' => [], // 文件监控目录 默认监控application和config目录
27 |
28 | // 可以支持swoole的所有配置参数
29 | 'pid_file' => Env::get('runtime_path') . 'swoole.pid',
30 | 'log_file' => Env::get('runtime_path') . 'swoole.log',
31 | 'document_root' => Env::get('root_path') . 'public',
32 | 'enable_static_handler' => true,
33 | ];
34 |
--------------------------------------------------------------------------------
/thinkphp/library/think/Exception.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think;
13 |
14 | class Exception extends \Exception
15 | {
16 |
17 | /**
18 | * 保存异常页面显示的额外Debug数据
19 | * @var array
20 | */
21 | protected $data = [];
22 |
23 | /**
24 | * 设置异常额外的Debug数据
25 | * 数据将会显示为下面的格式
26 | *
27 | * Exception Data
28 | * --------------------------------------------------
29 | * Label 1
30 | * key1 value1
31 | * key2 value2
32 | * Label 2
33 | * key1 value1
34 | * key2 value2
35 | *
36 | * @access protected
37 | * @param string $label 数据分类,用于异常页面显示
38 | * @param array $data 需要显示的数据,必须为关联数组
39 | */
40 | final protected function setData($label, array $data)
41 | {
42 | $this->data[$label] = $data;
43 | }
44 |
45 | /**
46 | * 获取异常额外Debug数据
47 | * 主要用于输出到异常页面便于调试
48 | * @access public
49 | * @return array 由setData设置的Debug数据
50 | */
51 | final public function getData()
52 | {
53 | return $this->data;
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/thinkphp/library/think/facade/Lang.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\facade;
13 |
14 | use think\Facade;
15 |
16 | /**
17 | * @see \think\Lang
18 | * @mixin \think\Lang
19 | * @method mixed range($range = '') static 设定当前的语言
20 | * @method mixed set(mixed $name, string $value = null, string $range = '') static 设置语言定义
21 | * @method array load(mixed $file, string $range = '') static 加载语言定义
22 | * @method mixed get(string $name = null, array $vars = [], string $range = '') static 获取语言定义
23 | * @method mixed has(string $name, string $range = '') static 获取语言定义
24 | * @method string detect() static 自动侦测设置获取语言选择
25 | * @method void saveToCookie(string $lang = null) static 设置当前语言到Cookie
26 | * @method void setLangDetectVar(string $var) static 设置语言自动侦测的变量
27 | * @method void setLangCookieVar(string $var) static 设置语言的cookie保存变量
28 | * @method void setAllowLangList(array $list) static 设置允许的语言列表
29 | */
30 | class Lang extends Facade
31 | {
32 | /**
33 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识)
34 | * @access protected
35 | * @return string
36 | */
37 | protected static function getFacadeClass()
38 | {
39 | return 'lang';
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/thinkphp/library/think/exception/ThrowableError.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\exception;
13 |
14 | class ThrowableError extends \ErrorException
15 | {
16 | public function __construct(\Throwable $e)
17 | {
18 |
19 | if ($e instanceof \ParseError) {
20 | $message = 'Parse error: ' . $e->getMessage();
21 | $severity = E_PARSE;
22 | } elseif ($e instanceof \TypeError) {
23 | $message = 'Type error: ' . $e->getMessage();
24 | $severity = E_RECOVERABLE_ERROR;
25 | } else {
26 | $message = 'Fatal error: ' . $e->getMessage();
27 | $severity = E_ERROR;
28 | }
29 |
30 | parent::__construct(
31 | $message,
32 | $e->getCode(),
33 | $severity,
34 | $e->getFile(),
35 | $e->getLine()
36 | );
37 |
38 | $this->setTrace($e->getTrace());
39 | }
40 |
41 | protected function setTrace($trace)
42 | {
43 | $traceReflector = new \ReflectionProperty('Exception', 'trace');
44 | $traceReflector->setAccessible(true);
45 | $traceReflector->setValue($this, $trace);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/thinkphp/library/think/exception/ErrorException.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\exception;
13 |
14 | use think\Exception;
15 |
16 | /**
17 | * ThinkPHP错误异常
18 | * 主要用于封装 set_error_handler 和 register_shutdown_function 得到的错误
19 | * 除开从 think\Exception 继承的功能
20 | * 其他和PHP系统\ErrorException功能基本一样
21 | */
22 | class ErrorException extends Exception
23 | {
24 | /**
25 | * 用于保存错误级别
26 | * @var integer
27 | */
28 | protected $severity;
29 |
30 | /**
31 | * 错误异常构造函数
32 | * @access public
33 | * @param integer $severity 错误级别
34 | * @param string $message 错误详细信息
35 | * @param string $file 出错文件路径
36 | * @param integer $line 出错行号
37 | */
38 | public function __construct($severity, $message, $file, $line)
39 | {
40 | $this->severity = $severity;
41 | $this->message = $message;
42 | $this->file = $file;
43 | $this->line = $line;
44 | $this->code = 0;
45 | }
46 |
47 | /**
48 | * 获取错误级别
49 | * @access public
50 | * @return integer 错误级别
51 | */
52 | final public function getSeverity()
53 | {
54 | return $this->severity;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/thinkphp/library/think/facade/View.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\facade;
13 |
14 | use think\Facade;
15 |
16 | /**
17 | * @see \think\View
18 | * @mixin \think\View
19 | * @method \think\View init(mixed $engine = [], array $replace = []) static 初始化
20 | * @method \think\View share(mixed $name, mixed $value = '') static 模板变量静态赋值
21 | * @method \think\View assign(mixed $name, mixed $value = '') static 模板变量赋值
22 | * @method \think\View config(mixed $name, mixed $value = '') static 配置模板引擎
23 | * @method \think\View exists(mixed $name) static 检查模板是否存在
24 | * @method \think\View filter(Callable $filter) static 视图内容过滤
25 | * @method \think\View engine(mixed $engine = []) static 设置当前模板解析的引擎
26 | * @method string fetch(string $template = '', array $vars = [], array $replace = [], array $config = [], bool $renderContent = false) static 解析和获取模板内容
27 | * @method string display(string $content = '', array $vars = [], array $replace = [], array $config = []) static 渲染内容输出
28 | */
29 | class View extends Facade
30 | {
31 | /**
32 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识)
33 | * @access protected
34 | * @return string
35 | */
36 | protected static function getFacadeClass()
37 | {
38 | return 'view';
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/thinkphp/library/think/facade/Debug.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\facade;
13 |
14 | use think\Facade;
15 |
16 | /**
17 | * @see \think\Debug
18 | * @mixin \think\Debug
19 | * @method void remark(string $name, mixed $value = '') static 记录时间(微秒)和内存使用情况
20 | * @method int getRangeTime(string $start, string $end, mixed $dec = 6) static 统计某个区间的时间(微秒)使用情况
21 | * @method int getUseTime(int $dec = 6) static 统计从开始到统计时的时间(微秒)使用情况
22 | * @method string getThroughputRate(string $start, string $end, mixed $dec = 6) static 获取当前访问的吞吐率情况
23 | * @method string getRangeMem(string $start, string $end, mixed $dec = 2) static 记录区间的内存使用情况
24 | * @method int getUseMem(int $dec = 2) static 统计从开始到统计时的内存使用情况
25 | * @method string getMemPeak(string $start, string $end, mixed $dec = 2) static 统计区间的内存峰值情况
26 | * @method mixed getFile(bool $detail = false) static 获取文件加载信息
27 | * @method mixed dump(mixed $var, bool $echo = true, string $label = null, int $flags = ENT_SUBSTITUTE) static 浏览器友好的变量输出
28 | */
29 | class Debug extends Facade
30 | {
31 | /**
32 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识)
33 | * @access protected
34 | * @return string
35 | */
36 | protected static function getFacadeClass()
37 | {
38 | return 'debug';
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/application/client/controller/Login.php:
--------------------------------------------------------------------------------
1 | fetch('Login/index');
26 | }
27 |
28 | /**
29 | * 管理员登陆
30 | *
31 | * @return string
32 | */
33 | public function doLogin()
34 | {
35 | $data = $this->request->post();
36 |
37 | $rules = [
38 | 'username|用户名' => 'require|min:2',
39 | 'password|密码' => 'require|length:4,12'
40 | ];
41 | $res = $this->validate($data, $rules);
42 |
43 | if (1 == $res)
44 | {
45 | $model = new Clerk();
46 |
47 | $clerk = $model->where(['username' => $data['username'], 'password' => md5($data['password'])])->find();
48 |
49 | if ($clerk)
50 | {
51 | session('id', $clerk->id);
52 | session('username', $clerk->username);
53 | return $this->redirect('/client/Clerk/index');
54 | }
55 | else
56 | {
57 | return $this->error('登陆失败!');
58 | }
59 | }
60 | else
61 | {
62 | return $this->error('登陆失败!' . $res);
63 | }
64 | }
65 |
66 | /*
67 | * 注销
68 | *
69 | * @return string
70 | */
71 |
72 | public function logout()
73 | {
74 | session('id', null);
75 | session('username', null);
76 | return $this->redirect('/client/Login/index');
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/thinkphp/base.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 | namespace think;
12 |
13 | // 载入Loader类
14 | require __DIR__ . '/library/think/Loader.php';
15 |
16 | // 注册自动加载
17 | Loader::register();
18 |
19 | // 注册错误和异常处理机制
20 | Error::register();
21 |
22 | // 实现日志接口
23 | if (interface_exists('Psr\Log\LoggerInterface')) {
24 | interface LoggerInterface extends \Psr\Log\LoggerInterface
25 | {}
26 | } else {
27 | interface LoggerInterface
28 | {}
29 | }
30 |
31 | // 注册类库别名
32 | Loader::addClassAlias([
33 | 'App' => facade\App::class,
34 | 'Build' => facade\Build::class,
35 | 'Cache' => facade\Cache::class,
36 | 'Config' => facade\Config::class,
37 | 'Cookie' => facade\Cookie::class,
38 | 'Db' => Db::class,
39 | 'Debug' => facade\Debug::class,
40 | 'Env' => facade\Env::class,
41 | 'Facade' => Facade::class,
42 | 'Hook' => facade\Hook::class,
43 | 'Lang' => facade\Lang::class,
44 | 'Log' => facade\Log::class,
45 | 'Request' => facade\Request::class,
46 | 'Response' => facade\Response::class,
47 | 'Route' => facade\Route::class,
48 | 'Session' => facade\Session::class,
49 | 'Url' => facade\Url::class,
50 | 'Validate' => facade\Validate::class,
51 | 'View' => facade\View::class,
52 | ]);
53 |
--------------------------------------------------------------------------------
/config/database.php:
--------------------------------------------------------------------------------
1 |
11 | // +----------------------------------------------------------------------
12 |
13 | return [
14 | // 数据库类型
15 | 'type' => 'mysql',
16 | // 服务器地址
17 | 'hostname' => '127.0.0.1',
18 | // 数据库名
19 | 'database' => 'clerk',
20 | // 用户名
21 | 'username' => 'root',
22 | // 密码
23 | 'password' => '',
24 | // 端口
25 | 'hostport' => '',
26 | // 连接dsn
27 | 'dsn' => '',
28 | // 数据库连接参数
29 | 'params' => [],
30 | // 数据库编码默认采用utf8
31 | 'charset' => 'utf8',
32 | // 数据库表前缀
33 | 'prefix' => 'oim_',
34 | // 数据库调试模式
35 | 'debug' => true,
36 | // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
37 | 'deploy' => 0,
38 | // 数据库读写是否分离 主从式有效
39 | 'rw_separate' => false,
40 | // 读写分离后 主服务器数量
41 | 'master_num' => 1,
42 | // 指定从服务器序号
43 | 'slave_no' => '',
44 | // 自动读取主库数据
45 | 'read_master' => false,
46 | // 是否严格检查字段是否存在
47 | 'fields_strict' => true,
48 | // 数据集返回类型
49 | 'resultset_type' => 'array',
50 | // 自动写入时间戳字段
51 | 'auto_timestamp' => false,
52 | // 时间字段取出后的默认时间格式
53 | 'datetime_format' => 'Y-m-d H:i:s',
54 | // 是否需要进行SQL性能分析
55 | 'sql_explain' => false,
56 | // Builder类
57 | 'builder' => '',
58 | // Query类
59 | 'query' => '\\think\\db\\Query',
60 | // 是否需要断线重连
61 | 'break_reconnect' => false,
62 | // 断线标识字符串
63 | 'break_match_str' => [],
64 | ];
65 |
--------------------------------------------------------------------------------
/thinkphp/library/think/console/output/question/Confirmation.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\console\output\question;
13 |
14 | use think\console\output\Question;
15 |
16 | class Confirmation extends Question
17 | {
18 |
19 | private $trueAnswerRegex;
20 |
21 | /**
22 | * 构造方法
23 | * @param string $question 问题
24 | * @param bool $default 默认答案
25 | * @param string $trueAnswerRegex 验证正则
26 | */
27 | public function __construct($question, $default = true, $trueAnswerRegex = '/^y/i')
28 | {
29 | parent::__construct($question, (bool) $default);
30 |
31 | $this->trueAnswerRegex = $trueAnswerRegex;
32 | $this->setNormalizer($this->getDefaultNormalizer());
33 | }
34 |
35 | /**
36 | * 获取默认的答案回调
37 | * @return callable
38 | */
39 | private function getDefaultNormalizer()
40 | {
41 | $default = $this->getDefault();
42 | $regex = $this->trueAnswerRegex;
43 |
44 | return function ($answer) use ($default, $regex) {
45 | if (is_bool($answer)) {
46 | return $answer;
47 | }
48 |
49 | $answerIsTrue = (bool) preg_match($regex, $answer);
50 | if (false === $default) {
51 | return $answer && $answerIsTrue;
52 | }
53 |
54 | return !$answer || $answerIsTrue;
55 | };
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/thinkphp/library/think/facade/Cache.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\facade;
13 |
14 | use think\Facade;
15 |
16 | /**
17 | * @see \think\Cache
18 | * @mixin \think\Cache
19 | * @method \think\cache\Driver connect(array $options = [], mixed $name = false) static 连接缓存
20 | * @method \think\cache\Driver init(array $options = []) static 初始化缓存
21 | * @method \think\cache\Driver store(string $name = '') static 切换缓存类型
22 | * @method bool has(string $name) static 判断缓存是否存在
23 | * @method mixed get(string $name, mixed $default = false) static 读取缓存
24 | * @method mixed pull(string $name) static 读取缓存并删除
25 | * @method mixed set(string $name, mixed $value, int $expire = null) static 设置缓存
26 | * @method mixed remember(string $name, mixed $value, int $expire = null) static 如果不存在则写入缓存
27 | * @method mixed inc(string $name, int $step = 1) static 自增缓存(针对数值缓存)
28 | * @method mixed dec(string $name, int $step = 1) static 自减缓存(针对数值缓存)
29 | * @method bool rm(string $name) static 删除缓存
30 | * @method bool clear(string $tag = null) static 清除缓存
31 | * @method mixed tag(string $name, mixed $keys = null, bool $overlay = false) static 缓存标签
32 | * @method object handler() static 返回句柄对象,可执行其它高级方法
33 | */
34 | class Cache extends Facade
35 | {
36 | /**
37 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识)
38 | * @access protected
39 | * @return string
40 | */
41 | protected static function getFacadeClass()
42 | {
43 | return 'cache';
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/config/swoole_server.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | use think\facade\Env;
13 |
14 | // +----------------------------------------------------------------------
15 | // | Swoole设置 php think swoole命令行下有效
16 | // +----------------------------------------------------------------------
17 | return [
18 | // 扩展自身配置
19 | 'host' => '0.0.0.0', // 监听地址
20 | 'port' => 9508, // 监听端口
21 | 'type' => 'socket', // 服务类型 支持 socket http server
22 | 'mode' => SWOOLE_PROCESS,
23 | 'socket_type' => SWOOLE_SOCK_TCP,
24 | 'swoole_class' => '', // 自定义服务类名称
25 |
26 | // 可以支持swoole的所有配置参数
27 | 'daemonize' => false,
28 | 'pid_file' => Env::get('runtime_path') . 'swoole_server.pid',
29 | 'log_file' => Env::get('runtime_path') . 'swoole_server.log',
30 |
31 | // 事件回调定义
32 | 'onOpen' => function ($server, $request) {
33 | echo "server: handshake success with fd{$request->fd}\n";
34 | },
35 |
36 | 'onMessage' => function ($server, $frame) {
37 | echo "receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}\n";
38 | $server->push($frame->fd, "this is server");
39 | },
40 |
41 | 'onRequest' => function ($request, $response) {
42 | $response->end("Hello Swoole. #" . rand(1000, 9999) . "
");
43 | },
44 |
45 | 'onClose' => function ($ser, $fd) {
46 | echo "client {$fd} closed\n";
47 | },
48 | ];
49 |
--------------------------------------------------------------------------------
/application/api/controller/Upload.php:
--------------------------------------------------------------------------------
1 | path . 'image/';
32 | $file = request()->file('file');
33 |
34 | $rs = ['code' => 1, 'msg' => '上传失败', 'data' => ['src' => '']];
35 | $info = $file->validate(['size' => $this->limit, 'ext' => $this->allowImageExt])->move($path);
36 | if ($info)
37 | {
38 | $rs['code'] = 0;
39 | $rs['msg'] = '上传成功';
40 | $rs['data']['src'] = substr($info->getPathName(), 1);
41 | }
42 | else
43 | {
44 | $rs['msg'] = $file->getError();
45 | }
46 | return json($rs);
47 | }
48 | /**
49 | * 处理文件上传
50 | *
51 | * @return string
52 | */
53 | public function file()
54 | {
55 | $path = $this->path . 'file/';
56 | $file = request()->file('file');
57 |
58 | $rs = ['code' => 1, 'msg' => '上传失败', 'data' => ['src' => '']];
59 | $info = $file->validate(['size' => $this->limit, 'ext' => $this->allowFileExt])->move($path);
60 | if ($info)
61 | {
62 | $rs['code'] = 0;
63 | $rs['msg'] = '上传成功';
64 | $rs['data']['src'] = substr($info->getPathName(), 1);
65 | }
66 | else
67 | {
68 | $rs['msg'] = $file->getError();
69 | }
70 | return json($rs);
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/thinkphp/library/think/process/exception/Timeout.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\process\exception;
13 |
14 | use think\Process;
15 |
16 | class Timeout extends \RuntimeException
17 | {
18 |
19 | const TYPE_GENERAL = 1;
20 | const TYPE_IDLE = 2;
21 |
22 | private $process;
23 | private $timeoutType;
24 |
25 | public function __construct(Process $process, $timeoutType)
26 | {
27 | $this->process = $process;
28 | $this->timeoutType = $timeoutType;
29 |
30 | parent::__construct(sprintf('The process "%s" exceeded the timeout of %s seconds.', $process->getCommandLine(), $this->getExceededTimeout()));
31 | }
32 |
33 | public function getProcess()
34 | {
35 | return $this->process;
36 | }
37 |
38 | public function isGeneralTimeout()
39 | {
40 | return $this->timeoutType === self::TYPE_GENERAL;
41 | }
42 |
43 | public function isIdleTimeout()
44 | {
45 | return $this->timeoutType === self::TYPE_IDLE;
46 | }
47 |
48 | public function getExceededTimeout()
49 | {
50 | switch ($this->timeoutType) {
51 | case self::TYPE_GENERAL:
52 | return $this->process->getTimeout();
53 |
54 | case self::TYPE_IDLE:
55 | return $this->process->getIdleTimeout();
56 |
57 | default:
58 | throw new \LogicException(sprintf('Unknown timeout type "%d".', $this->timeoutType));
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/thinkphp/library/think/facade/Session.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\facade;
13 |
14 | use think\Facade;
15 |
16 | /**
17 | * @see \think\Session
18 | * @mixin \think\Session
19 | * @method void init(array $config = []) static session初始化
20 | * @method bool has(string $name,string $prefix = null) static 判断session数据
21 | * @method mixed prefix(string $prefix = '') static 设置或者获取session作用域(前缀)
22 | * @method mixed get(string $name = '',string $prefix = null) static session获取
23 | * @method mixed pull(string $name,string $prefix = null) static session获取并删除
24 | * @method void push(string $key, mixed $value) static 添加数据到一个session数组
25 | * @method void set(string $name, mixed $value , string $prefix = null) static 设置session数据
26 | * @method void flash(string $name, mixed $value = null) static session设置 下一次请求有效
27 | * @method void flush() static 清空当前请求的session数据
28 | * @method void delete(string $name, string $prefix = null) static 删除session数据
29 | * @method void clear($prefix = null) static 清空session数据
30 | * @method void start() static 启动session
31 | * @method void destroy() static 销毁session
32 | * @method void pause() static 暂停session
33 | * @method void regenerate(bool $delete = false) static 重新生成session_id
34 | */
35 | class Session extends Facade
36 | {
37 | /**
38 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识)
39 | * @access protected
40 | * @return string
41 | */
42 | protected static function getFacadeClass()
43 | {
44 | return 'session';
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/thinkphp/library/think/console/command/Build.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\console\command;
13 |
14 | use think\console\Command;
15 | use think\console\Input;
16 | use think\console\input\Option;
17 | use think\console\Output;
18 | use think\facade\App;
19 | use think\facade\Build as AppBuild;
20 |
21 | class Build extends Command
22 | {
23 |
24 | /**
25 | * {@inheritdoc}
26 | */
27 | protected function configure()
28 | {
29 | $this->setName('build')
30 | ->setDefinition([
31 | new Option('config', null, Option::VALUE_OPTIONAL, "build.php path"),
32 | new Option('module', null, Option::VALUE_OPTIONAL, "module name"),
33 | ])
34 | ->setDescription('Build Application Dirs');
35 | }
36 |
37 | protected function execute(Input $input, Output $output)
38 | {
39 | if ($input->hasOption('module')) {
40 | AppBuild::module($input->getOption('module'));
41 | $output->writeln("Successed");
42 | return;
43 | }
44 |
45 | if ($input->hasOption('config')) {
46 | $build = include $input->getOption('config');
47 | } else {
48 | $build = include App::getAppPath() . 'build.php';
49 | }
50 |
51 | if (empty($build)) {
52 | $output->writeln("Build Config Is Empty");
53 | return;
54 | }
55 |
56 | AppBuild::run($build);
57 | $output->writeln("Successed");
58 |
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/application/api/controller/ChatRecord.php:
--------------------------------------------------------------------------------
1 | request->param('key');
23 | $page = $this->request->param('page/d');
24 | $result = ['code'=>404, 'data'=>[]];
25 |
26 | if ($key)
27 | {
28 | $record = new MyModel();
29 |
30 | $data = $record->whereOr([['from_key','=',$key],['to_key','=',$key]])
31 | ->order('create_time desc')
32 | ->limit($page, 1)
33 | ->select();
34 |
35 | if(isset($data[0]->content)){
36 |
37 | $result['data'] = json_decode($data[0]->content);
38 | $result['create_time'] = date('Y-m-d H:i:s', $data[0]->create_time);
39 | $result['code'] = 200;
40 | }
41 | // print_r($result);
42 | }
43 | // print_r( json_decode($data));
44 | return json($result);
45 | }
46 |
47 | /**
48 | * 保存聊天记录
49 | *
50 | * @return string
51 | */
52 | public function save()
53 | {
54 | $fromKey = $this->request->post('fromkey');
55 | $toKey = $this->request->post('tokey');
56 | $content = $this->request->post('content');
57 | if ($fromKey && $toKey && $content)
58 | {
59 | $record = new MyModel();
60 | $record->from_key = $fromKey;
61 | $record->to_key = $toKey;
62 | $record->content = $content;
63 | $record->create_time = time();
64 | if ($record->save())
65 | {
66 | return 1;
67 | }
68 | }
69 | return 0;
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/thinkphp/library/think/response/Jsonp.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\response;
13 |
14 | use think\Response;
15 |
16 | class Jsonp extends Response
17 | {
18 | // 输出参数
19 | protected $options = [
20 | 'var_jsonp_handler' => 'callback',
21 | 'default_jsonp_handler' => 'jsonpReturn',
22 | 'json_encode_param' => JSON_UNESCAPED_UNICODE,
23 | ];
24 |
25 | protected $contentType = 'application/javascript';
26 |
27 | /**
28 | * 处理数据
29 | * @access protected
30 | * @param mixed $data 要处理的数据
31 | * @return mixed
32 | * @throws \Exception
33 | */
34 | protected function output($data)
35 | {
36 | try {
37 | // 返回JSON数据格式到客户端 包含状态信息 [当url_common_param为false时是无法获取到$_GET的数据的,故使用Request来获取]
38 | $var_jsonp_handler = $this->app['request']->param($this->options['var_jsonp_handler'], "");
39 | $handler = !empty($var_jsonp_handler) ? $var_jsonp_handler : $this->options['default_jsonp_handler'];
40 |
41 | $data = json_encode($data, $this->options['json_encode_param']);
42 |
43 | if (false === $data) {
44 | throw new \InvalidArgumentException(json_last_error_msg());
45 | }
46 |
47 | $data = $handler . '(' . $data . ');';
48 |
49 | return $data;
50 | } catch (\Exception $e) {
51 | if ($e->getPrevious()) {
52 | throw $e->getPrevious();
53 | }
54 | throw $e;
55 | }
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/thinkphp/library/think/console/command/make/Controller.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\console\command\make;
13 |
14 | use think\console\command\Make;
15 | use think\console\input\Option;
16 | use think\facade\Config;
17 |
18 | class Controller extends Make
19 | {
20 |
21 | protected $type = "Controller";
22 |
23 | protected function configure()
24 | {
25 | parent::configure();
26 | $this->setName('make:controller')
27 | ->addOption('api', null, Option::VALUE_NONE, 'Generate an api controller class.')
28 | ->addOption('plain', null, Option::VALUE_NONE, 'Generate an empty controller class.')
29 | ->setDescription('Create a new resource controller class');
30 | }
31 |
32 | protected function getStub()
33 | {
34 | $stubPath = __DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR;
35 |
36 | if ($this->input->getOption('api')) {
37 | return $stubPath . 'controller.api.stub';
38 | }
39 |
40 | if ($this->input->getOption('plain')) {
41 | return $stubPath . 'controller.plain.stub';
42 | }
43 |
44 | return $stubPath . 'controller.stub';
45 | }
46 |
47 | protected function getClassName($name)
48 | {
49 | return parent::getClassName($name) . (Config::get('controller_suffix') ? ucfirst(Config::get('url_controller_layer')) : '');
50 | }
51 |
52 | protected function getNamespace($appNamespace, $module)
53 | {
54 | return parent::getNamespace($appNamespace, $module) . '\controller';
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 |
3 | language: php
4 |
5 | branches:
6 | only:
7 | - stable
8 |
9 | cache:
10 | directories:
11 | - $HOME/.composer/cache
12 |
13 | before_install:
14 | - composer self-update
15 |
16 | install:
17 | - composer install --no-dev --no-interaction --ignore-platform-reqs
18 | - zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Core.zip .
19 | - composer require --update-no-dev --no-interaction "topthink/think-image:^1.0"
20 | - composer require --update-no-dev --no-interaction "topthink/think-migration:^1.0"
21 | - composer require --update-no-dev --no-interaction "topthink/think-captcha:^1.0"
22 | - composer require --update-no-dev --no-interaction "topthink/think-mongo:^1.0"
23 | - composer require --update-no-dev --no-interaction "topthink/think-worker:^1.0"
24 | - composer require --update-no-dev --no-interaction "topthink/think-helper:^1.0"
25 | - composer require --update-no-dev --no-interaction "topthink/think-queue:^1.0"
26 | - composer require --update-no-dev --no-interaction "topthink/think-angular:^1.0"
27 | - composer require --dev --update-no-dev --no-interaction "topthink/think-testing:^1.0"
28 | - zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Full.zip .
29 |
30 | script:
31 | - php think unit
32 |
33 | deploy:
34 | provider: releases
35 | api_key:
36 | secure: TSF6bnl2JYN72UQOORAJYL+CqIryP2gHVKt6grfveQ7d9rleAEoxlq6PWxbvTI4jZ5nrPpUcBUpWIJHNgVcs+bzLFtyh5THaLqm39uCgBbrW7M8rI26L8sBh/6nsdtGgdeQrO/cLu31QoTzbwuz1WfAVoCdCkOSZeXyT/CclH99qV6RYyQYqaD2wpRjrhA5O4fSsEkiPVuk0GaOogFlrQHx+C+lHnf6pa1KxEoN1A0UxxVfGX6K4y5g4WQDO5zT4bLeubkWOXK0G51XSvACDOZVIyLdjApaOFTwamPcD3S1tfvuxRWWvsCD5ljFvb2kSmx5BIBNwN80MzuBmrGIC27XLGOxyMerwKxB6DskNUO9PflKHDPI61DRq0FTy1fv70SFMSiAtUv9aJRT41NQh9iJJ0vC8dl+xcxrWIjU1GG6+l/ZcRqVx9V1VuGQsLKndGhja7SQ+X1slHl76fRq223sMOql7MFCd0vvvxVQ2V39CcFKao/LB1aPH3VhODDEyxwx6aXoTznvC/QPepgWsHOWQzKj9ftsgDbsNiyFlXL4cu8DWUty6rQy8zT2b4O8b1xjcwSUCsy+auEjBamzQkMJFNlZAIUrukL/NbUhQU37TAbwsFyz7X0E/u/VMle/nBCNAzgkMwAUjiHM6FqrKKBRWFbPrSIixjfjkCnrMEPw=
37 | file:
38 | - ThinkPHP_Core.zip
39 | - ThinkPHP_Full.zip
40 | skip_cleanup: true
41 | on:
42 | tags: true
43 |
--------------------------------------------------------------------------------
/thinkphp/library/think/facade/Response.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\facade;
13 |
14 | use think\Facade;
15 |
16 | /**
17 | * @see \think\Response
18 | * @mixin \think\Response
19 | * @method \think\response create(mixed $data = '', string $type = '', int $code = 200, array $header = [], array $options = []) static 创建Response对象
20 | * @method void send() static 发送数据到客户端
21 | * @method \think\Response options(mixed $options = []) static 输出的参数
22 | * @method \think\Response data(mixed $data) static 输出数据设置
23 | * @method \think\Response header(mixed $name, string $value = null) static 设置响应头
24 | * @method \think\Response content(mixed $content) static 设置页面输出内容
25 | * @method \think\Response code(int $code) static 发送HTTP状态
26 | * @method \think\Response lastModified(string $time) static LastModified
27 | * @method \think\Response expires(string $time) static expires
28 | * @method \think\Response eTag(string $eTag) static eTag
29 | * @method \think\Response cacheControl(string $cache) static 页面缓存控制
30 | * @method \think\Response contentType(string $contentType, string $charset = 'utf-8') static 页面输出类型
31 | * @method mixed getHeader(string $name) static 获取头部信息
32 | * @method mixed getData() static 获取原始数据
33 | * @method mixed getContent() static 获取输出数据
34 | * @method int getCode() static 获取状态码
35 | */
36 | class Response extends Facade
37 | {
38 | /**
39 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识)
40 | * @access protected
41 | * @return string
42 | */
43 | protected static function getFacadeClass()
44 | {
45 | return 'response';
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/thinkphp/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | ThinkPHP 5.1 —— 12载初心,你值得信赖的PHP框架
4 | ===============
5 |
6 | [](https://scrutinizer-ci.com/g/top-think/framework/?branch=5.1)
7 | [](https://travis-ci.org/top-think/framework)
8 | [](https://packagist.org/packages/topthink/framework)
9 | [](https://packagist.org/packages/topthink/framework)
10 | [](http://www.php.net/)
11 | [](https://packagist.org/packages/topthink/framework)
12 |
13 | ThinkPHP5.1对底层架构做了进一步的改进,减少依赖,其主要特性包括:
14 |
15 | + 采用容器统一管理对象
16 | + 支持Facade
17 | + 更易用的路由
18 | + 注解路由支持
19 | + 路由跨域请求支持
20 | + 验证类增强
21 | + 配置和路由目录独立
22 | + 取消系统常量
23 | + 类库别名机制
24 | + 模型和数据库增强
25 | + 依赖注入完善
26 | + 支持PSR-3日志规范
27 | + 中间件支持(`V5.1.6+`)
28 | + 支持`Swoole`/`Workerman`运行(`V5.1.18+`)
29 |
30 |
31 | ### 废除的功能:
32 |
33 | + 聚合模型
34 | + 内置控制器扩展类
35 | + 模型自动验证
36 |
37 | > ThinkPHP5.1的运行环境要求PHP5.6+。
38 |
39 | ## 安装
40 |
41 | 使用composer安装
42 |
43 | ~~~
44 | composer create-project topthink/think tp
45 | ~~~
46 |
47 | 启动服务
48 |
49 | ~~~
50 | cd tp
51 | php think run
52 | ~~~
53 |
54 | 然后就可以在浏览器中访问
55 |
56 | ~~~
57 | http://localhost:8000
58 | ~~~
59 |
60 | 更新框架
61 | ~~~
62 | composer update topthink/framework
63 | ~~~
64 |
65 |
66 | ## 在线手册
67 |
68 | + [完全开发手册](https://www.kancloud.cn/manual/thinkphp5_1/content)
69 | + [升级指导](https://www.kancloud.cn/manual/thinkphp5_1/354155)
70 |
71 | ## 命名规范
72 |
73 | `ThinkPHP5.1`遵循PSR-2命名规范和PSR-4自动加载规范。
74 |
75 | ## 参与开发
76 |
77 | 请参阅 [ThinkPHP5 核心框架包](https://github.com/top-think/framework)。
78 |
79 | ## 版权信息
80 |
81 | ThinkPHP遵循Apache2开源协议发布,并提供免费使用。
82 |
83 | 本项目包含的第三方源码和二进制文件之版权信息另行标注。
84 |
85 | 版权所有Copyright © 2006-2018 by ThinkPHP (http://thinkphp.cn)
86 |
87 | All rights reserved。
88 |
89 | ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
90 |
91 | 更多细节参阅 [LICENSE.txt](LICENSE.txt)
92 |
--------------------------------------------------------------------------------
/thinkphp/library/think/console/command/RunServer.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 | namespace think\console\command;
12 |
13 | use think\console\Command;
14 | use think\console\Input;
15 | use think\console\input\Option;
16 | use think\console\Output;
17 | use think\facade\App;
18 |
19 | class RunServer extends Command
20 | {
21 |
22 | public function configure()
23 | {
24 | $this->setName('run')
25 | ->addOption('host', 'H', Option::VALUE_OPTIONAL,
26 | 'The host to server the application on', '127.0.0.1')
27 | ->addOption('port', 'p', Option::VALUE_OPTIONAL,
28 | 'The port to server the application on', 8000)
29 | ->addOption('root', 'r', Option::VALUE_OPTIONAL,
30 | 'The document root of the application', App::getRootPath() . 'public')
31 | ->setDescription('PHP Built-in Server for ThinkPHP');
32 | }
33 |
34 | public function execute(Input $input, Output $output)
35 | {
36 | $host = $input->getOption('host');
37 | $port = $input->getOption('port');
38 | $root = $input->getOption('root');
39 |
40 | $command = sprintf(
41 | 'php -S %s:%d -t %s %s',
42 | $host,
43 | $port,
44 | escapeshellarg($root),
45 | escapeshellarg($root . DIRECTORY_SEPARATOR . 'router.php')
46 | );
47 |
48 | $output->writeln(sprintf('ThinkPHP Development server is started On ', $host, $port));
49 | $output->writeln(sprintf('You can exit with `CTRL-C`'));
50 | $output->writeln(sprintf('Document root is: %s', $root));
51 | passthru($command);
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/thinkphp/tpl/dispatch_jump.tpl:
--------------------------------------------------------------------------------
1 | {__NOLAYOUT__}
2 |
3 |
4 |
5 |
6 | 跳转提示
7 |
17 |
18 |
19 |
20 |
21 |
22 |
:)
23 |
24 |
25 |
26 |
:(
27 |
28 |
29 |
30 |
31 |
32 | 页面自动 跳转 等待时间:
33 |
34 |
35 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/thinkphp/library/think/facade/Log.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\facade;
13 |
14 | use think\Facade;
15 |
16 | /**
17 | * @see \think\Log
18 | * @mixin \think\Log
19 | * @method \think\Log init(array $config = []) static 日志初始化
20 | * @method mixed getLog(string $type = '') static 获取日志信息
21 | * @method \think\Log record(mixed $msg, string $type = 'info', array $context = []) static 记录日志信息
22 | * @method \think\Log clear() static 清空日志信息
23 | * @method \think\Log key(string $key) static 当前日志记录的授权key
24 | * @method bool check(array $config) static 检查日志写入权限
25 | * @method bool save() static 保存调试信息
26 | * @method void write(mixed $msg, string $type = 'info', bool $force = false) static 实时写入日志信息
27 | * @method void log(string $level,mixed $message, array $context = []) static 记录日志信息
28 | * @method void emergency(mixed $message, array $context = []) static 记录emergency信息
29 | * @method void alert(mixed $message, array $context = []) static 记录alert信息
30 | * @method void critical(mixed $message, array $context = []) static 记录critical信息
31 | * @method void error(mixed $message, array $context = []) static 记录error信息
32 | * @method void warning(mixed $message, array $context = []) static 记录warning信息
33 | * @method void notice(mixed $message, array $context = []) static 记录notice信息
34 | * @method void info(mixed $message, array $context = []) static 记录info信息
35 | * @method void debug(mixed $message, array $context = []) static 记录debug信息
36 | * @method void sql(mixed $message, array $context = []) static 记录sql信息
37 | */
38 | class Log extends Facade
39 | {
40 | /**
41 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识)
42 | * @access protected
43 | * @return string
44 | */
45 | protected static function getFacadeClass()
46 | {
47 | return 'log';
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/thinkphp/library/think/console/command/Help.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\console\command;
13 |
14 | use think\console\Command;
15 | use think\console\Input;
16 | use think\console\input\Argument as InputArgument;
17 | use think\console\input\Option as InputOption;
18 | use think\console\Output;
19 |
20 | class Help extends Command
21 | {
22 |
23 | private $command;
24 |
25 | /**
26 | * {@inheritdoc}
27 | */
28 | protected function configure()
29 | {
30 | $this->ignoreValidationErrors();
31 |
32 | $this->setName('help')->setDefinition([
33 | new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'),
34 | new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command help'),
35 | ])->setDescription('Displays help for a command')->setHelp(<<%command.name% command displays help for a given command:
37 |
38 | php %command.full_name% list
39 |
40 | To display the list of available commands, please use the list command.
41 | EOF
42 | );
43 | }
44 |
45 | /**
46 | * Sets the command.
47 | * @param Command $command The command to set
48 | */
49 | public function setCommand(Command $command)
50 | {
51 | $this->command = $command;
52 | }
53 |
54 | /**
55 | * {@inheritdoc}
56 | */
57 | protected function execute(Input $input, Output $output)
58 | {
59 | if (null === $this->command) {
60 | $this->command = $this->getConsole()->find($input->getArgument('command_name'));
61 | }
62 |
63 | $output->describe($this->command, [
64 | 'raw_text' => $input->getOption('raw'),
65 | ]);
66 |
67 | $this->command = null;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/thinkphp/library/think/template/driver/File.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\template\driver;
13 |
14 | use think\Exception;
15 |
16 | class File
17 | {
18 | protected $cacheFile;
19 |
20 | /**
21 | * 写入编译缓存
22 | * @access public
23 | * @param string $cacheFile 缓存的文件名
24 | * @param string $content 缓存的内容
25 | * @return void|array
26 | */
27 | public function write($cacheFile, $content)
28 | {
29 | // 检测模板目录
30 | $dir = dirname($cacheFile);
31 |
32 | if (!is_dir($dir)) {
33 | mkdir($dir, 0755, true);
34 | }
35 |
36 | // 生成模板缓存文件
37 | if (false === file_put_contents($cacheFile, $content)) {
38 | throw new Exception('cache write error:' . $cacheFile, 11602);
39 | }
40 | }
41 |
42 | /**
43 | * 读取编译编译
44 | * @access public
45 | * @param string $cacheFile 缓存的文件名
46 | * @param array $vars 变量数组
47 | * @return void
48 | */
49 | public function read($cacheFile, $vars = [])
50 | {
51 | $this->cacheFile = $cacheFile;
52 |
53 | if (!empty($vars) && is_array($vars)) {
54 | // 模板阵列变量分解成为独立变量
55 | extract($vars, EXTR_OVERWRITE);
56 | }
57 |
58 | //载入模版缓存文件
59 | include $this->cacheFile;
60 | }
61 |
62 | /**
63 | * 检查编译缓存是否有效
64 | * @access public
65 | * @param string $cacheFile 缓存的文件名
66 | * @param int $cacheTime 缓存时间
67 | * @return boolean
68 | */
69 | public function check($cacheFile, $cacheTime)
70 | {
71 | // 缓存文件不存在, 直接返回false
72 | if (!file_exists($cacheFile)) {
73 | return false;
74 | }
75 |
76 | if (0 != $cacheTime && time() > filemtime($cacheFile) + $cacheTime) {
77 | // 缓存是否在有效期
78 | return false;
79 | }
80 |
81 | return true;
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/thinkphp/library/think/console/command/Lists.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\console\command;
13 |
14 | use think\console\Command;
15 | use think\console\Input;
16 | use think\console\Output;
17 | use think\console\input\Argument as InputArgument;
18 | use think\console\input\Option as InputOption;
19 | use think\console\input\Definition as InputDefinition;
20 |
21 | class Lists extends Command
22 | {
23 |
24 | /**
25 | * {@inheritdoc}
26 | */
27 | protected function configure()
28 | {
29 | $this->setName('list')->setDefinition($this->createDefinition())->setDescription('Lists commands')->setHelp(<<%command.name% command lists all commands:
31 |
32 | php %command.full_name%
33 |
34 | You can also display the commands for a specific namespace:
35 |
36 | php %command.full_name% test
37 |
38 | It's also possible to get raw list of commands (useful for embedding command runner):
39 |
40 | php %command.full_name% --raw
41 | EOF
42 | );
43 | }
44 |
45 | /**
46 | * {@inheritdoc}
47 | */
48 | public function getNativeDefinition()
49 | {
50 | return $this->createDefinition();
51 | }
52 |
53 | /**
54 | * {@inheritdoc}
55 | */
56 | protected function execute(Input $input, Output $output)
57 | {
58 | $output->describe($this->getConsole(), [
59 | 'raw_text' => $input->getOption('raw'),
60 | 'namespace' => $input->getArgument('namespace'),
61 | ]);
62 | }
63 |
64 | /**
65 | * {@inheritdoc}
66 | */
67 | private function createDefinition()
68 | {
69 | return new InputDefinition([
70 | new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
71 | new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list')
72 | ]);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/thinkphp/library/think/model/concern/TimeStamp.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\model\concern;
13 |
14 | /**
15 | * 自动时间戳
16 | */
17 | trait TimeStamp
18 | {
19 | /**
20 | * 是否需要自动写入时间戳 如果设置为字符串 则表示时间字段的类型
21 | * @var bool|string
22 | */
23 | protected $autoWriteTimestamp;
24 |
25 | /**
26 | * 创建时间字段 false表示关闭
27 | * @var false|string
28 | */
29 | protected $createTime = 'create_time';
30 |
31 | /**
32 | * 更新时间字段 false表示关闭
33 | * @var false|string
34 | */
35 | protected $updateTime = 'update_time';
36 |
37 | /**
38 | * 时间字段显示格式
39 | * @var string
40 | */
41 | protected $dateFormat;
42 |
43 | /**
44 | * 时间日期字段格式化处理
45 | * @access protected
46 | * @param mixed $time 时间日期表达式
47 | * @param mixed $format 日期格式
48 | * @param bool $timestamp 是否进行时间戳转换
49 | * @return mixed
50 | */
51 | protected function formatDateTime($time, $format, $timestamp = false)
52 | {
53 | if (empty($time)) {
54 | return;
55 | }
56 |
57 | if (false !== strpos($format, '\\')) {
58 | $time = new $format($time);
59 | } elseif (!$timestamp && false !== $format) {
60 | $time = date($format, $time);
61 | }
62 |
63 | return $time;
64 | }
65 |
66 | /**
67 | * 检查时间字段写入
68 | * @access protected
69 | * @return void
70 | */
71 | protected function checkTimeStampWrite()
72 | {
73 | // 自动写入创建时间和更新时间
74 | if ($this->autoWriteTimestamp) {
75 | if ($this->createTime && !isset($this->data[$this->createTime])) {
76 | $this->data[$this->createTime] = $this->autoWriteTimestamp($this->createTime);
77 | }
78 | if ($this->updateTime && !isset($this->data[$this->updateTime])) {
79 | $this->data[$this->updateTime] = $this->autoWriteTimestamp($this->updateTime);
80 | }
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/thinkphp/library/think/response/View.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\response;
13 |
14 | use think\Response;
15 |
16 | class View extends Response
17 | {
18 | // 输出参数
19 | protected $options = [];
20 | protected $vars = [];
21 | protected $filter;
22 | protected $contentType = 'text/html';
23 |
24 | /**
25 | * 处理数据
26 | * @access protected
27 | * @param mixed $data 要处理的数据
28 | * @return mixed
29 | */
30 | protected function output($data)
31 | {
32 | // 渲染模板输出
33 | return $this->app['view']
34 | ->filter($this->filter)
35 | ->fetch($data, $this->vars);
36 | }
37 |
38 | /**
39 | * 获取视图变量
40 | * @access public
41 | * @param string $name 模板变量
42 | * @return mixed
43 | */
44 | public function getVars($name = null)
45 | {
46 | if (is_null($name)) {
47 | return $this->vars;
48 | } else {
49 | return isset($this->vars[$name]) ? $this->vars[$name] : null;
50 | }
51 | }
52 |
53 | /**
54 | * 模板变量赋值
55 | * @access public
56 | * @param mixed $name 变量名
57 | * @param mixed $value 变量值
58 | * @return $this
59 | */
60 | public function assign($name, $value = '')
61 | {
62 | if (is_array($name)) {
63 | $this->vars = array_merge($this->vars, $name);
64 | } else {
65 | $this->vars[$name] = $value;
66 | }
67 |
68 | return $this;
69 | }
70 |
71 | /**
72 | * 视图内容过滤
73 | * @access public
74 | * @param callable $filter
75 | * @return $this
76 | */
77 | public function filter($filter)
78 | {
79 | $this->filter = $filter;
80 | return $this;
81 | }
82 |
83 | /**
84 | * 检查模板是否存在
85 | * @access private
86 | * @param string|array $name 参数名
87 | * @return bool
88 | */
89 | public function exists($name)
90 | {
91 | return $this->app['view']->exists($name);
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/thinkphp/library/think/process/Utils.php:
--------------------------------------------------------------------------------
1 |
8 | // +----------------------------------------------------------------------
9 |
10 | namespace think\process;
11 |
12 | class Utils
13 | {
14 |
15 | /**
16 | * 转义字符串
17 | * @param string $argument
18 | * @return string
19 | */
20 | public static function escapeArgument($argument)
21 | {
22 |
23 | if ('' === $argument) {
24 | return escapeshellarg($argument);
25 | }
26 | $escapedArgument = '';
27 | $quote = false;
28 | foreach (preg_split('/(")/i', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) {
29 | if ('"' === $part) {
30 | $escapedArgument .= '\\"';
31 | } elseif (self::isSurroundedBy($part, '%')) {
32 | // Avoid environment variable expansion
33 | $escapedArgument .= '^%"' . substr($part, 1, -1) . '"^%';
34 | } else {
35 | // escape trailing backslash
36 | if ('\\' === substr($part, -1)) {
37 | $part .= '\\';
38 | }
39 | $quote = true;
40 | $escapedArgument .= $part;
41 | }
42 | }
43 | if ($quote) {
44 | $escapedArgument = '"' . $escapedArgument . '"';
45 | }
46 | return $escapedArgument;
47 | }
48 |
49 | /**
50 | * 验证并进行规范化Process输入。
51 | * @param string $caller
52 | * @param mixed $input
53 | * @return string
54 | * @throws \InvalidArgumentException
55 | */
56 | public static function validateInput($caller, $input)
57 | {
58 | if (null !== $input) {
59 | if (is_resource($input)) {
60 | return $input;
61 | }
62 | if (is_scalar($input)) {
63 | return (string) $input;
64 | }
65 | throw new \InvalidArgumentException(sprintf('%s only accepts strings or stream resources.', $caller));
66 | }
67 | return $input;
68 | }
69 |
70 | private static function isSurroundedBy($arg, $char)
71 | {
72 | return 2 < strlen($arg) && $char === $arg[0] && $char === $arg[strlen($arg) - 1];
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/thinkphp/library/think/console/command/optimize/Route.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 | namespace think\console\command\optimize;
12 |
13 | use think\console\Command;
14 | use think\console\Input;
15 | use think\console\Output;
16 | use think\Container;
17 |
18 | class Route extends Command
19 | {
20 | /** @var Output */
21 | protected $output;
22 |
23 | protected function configure()
24 | {
25 | $this->setName('optimize:route')
26 | ->setDescription('Build route cache.');
27 | }
28 |
29 | protected function execute(Input $input, Output $output)
30 | {
31 | $filename = Container::get('app')->getRuntimePath() . 'route.php';
32 | if (is_file($filename)) {
33 | unlink($filename);
34 | }
35 | file_put_contents($filename, $this->buildRouteCache());
36 | $output->writeln('Succeed!');
37 | }
38 |
39 | protected function buildRouteCache()
40 | {
41 | Container::get('route')->setName([]);
42 | Container::get('route')->lazy(false);
43 | // 路由检测
44 | $path = Container::get('app')->getRoutePath();
45 |
46 | $files = is_dir($path) ? scandir($path) : [];
47 |
48 | foreach ($files as $file) {
49 | if (strpos($file, '.php')) {
50 | $filename = $path . DIRECTORY_SEPARATOR . $file;
51 | // 导入路由配置
52 | $rules = include $filename;
53 | if (is_array($rules)) {
54 | Container::get('route')->import($rules);
55 | }
56 | }
57 | }
58 |
59 | if (Container::get('config')->get('route_annotation')) {
60 | $suffix = Container::get('config')->get('controller_suffix') || Container::get('config')->get('class_suffix');
61 | include Container::get('build')->buildRoute($suffix);
62 | }
63 |
64 | $content = 'getName(), true) . ';';
66 | return $content;
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/thinkphp/library/think/process/pipes/Pipes.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\process\pipes;
13 |
14 | abstract class Pipes
15 | {
16 |
17 | /** @var array */
18 | public $pipes = [];
19 |
20 | /** @var string */
21 | protected $inputBuffer = '';
22 | /** @var resource|null */
23 | protected $input;
24 |
25 | /** @var bool */
26 | private $blocked = true;
27 |
28 | const CHUNK_SIZE = 16384;
29 |
30 | /**
31 | * 返回用于 proc_open 描述符的数组
32 | * @return array
33 | */
34 | abstract public function getDescriptors();
35 |
36 | /**
37 | * 返回一个数组的索引由其相关的流,以防这些管道使用的临时文件的文件名。
38 | * @return string[]
39 | */
40 | abstract public function getFiles();
41 |
42 | /**
43 | * 文件句柄和管道中读取数据。
44 | * @param bool $blocking 是否使用阻塞调用
45 | * @param bool $close 是否要关闭管道,如果他们已经到达 EOF。
46 | * @return string[]
47 | */
48 | abstract public function readAndWrite($blocking, $close = false);
49 |
50 | /**
51 | * 返回当前状态如果有打开的文件句柄或管道。
52 | * @return bool
53 | */
54 | abstract public function areOpen();
55 |
56 | /**
57 | * {@inheritdoc}
58 | */
59 | public function close()
60 | {
61 | foreach ($this->pipes as $pipe) {
62 | fclose($pipe);
63 | }
64 | $this->pipes = [];
65 | }
66 |
67 | /**
68 | * 检查系统调用已被中断
69 | * @return bool
70 | */
71 | protected function hasSystemCallBeenInterrupted()
72 | {
73 | $lastError = error_get_last();
74 |
75 | return isset($lastError['message']) && false !== stripos($lastError['message'], 'interrupted system call');
76 | }
77 |
78 | protected function unblock()
79 | {
80 | if (!$this->blocked) {
81 | return;
82 | }
83 |
84 | foreach ($this->pipes as $pipe) {
85 | stream_set_blocking($pipe, 0);
86 | }
87 | if (null !== $this->input) {
88 | stream_set_blocking($this->input, 0);
89 | }
90 |
91 | $this->blocked = false;
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/application/client/view/Login/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | 后台登陆
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
后台系统登录
19 |
38 |
39 |
40 |
41 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/application/api/controller/Clerk.php:
--------------------------------------------------------------------------------
1 | request->param('id/d');
24 | $model = new Group();
25 | $data = $model->withAllClerk()->select();
26 | if ($id && $data)
27 | {
28 | $redis = new \Redis();
29 | $redis->connect('127.0.0.1', '6379');
30 | foreach ($data as &$list)
31 | {
32 | $list->list = $list->clerk;
33 | unset($list->clerk);
34 | foreach ($list->list as $key => $clerk)
35 | {
36 | if ($redis->exists($clerk->id . ':' . 'clerk'))
37 | {
38 | $list->list[$key]['status'] = 'online';
39 | }
40 | }
41 |
42 |
43 | //print_r($list);
44 | }
45 | }
46 | $mine = ['username' => 'visitor-'.$id, 'id' => $id, 'usertype' => 'visitor', 'sign' => '电话:8888888', "avatar" => "/pic/00.jpg"];
47 | $result = ['code' => 0, 'msg' => '', 'data' => ['mine' => $mine, 'friend' => $data]];
48 |
49 | return json($result);
50 | }
51 | /**
52 | * 获取客服列表,不包含当前客服
53 | *
54 | * @return string
55 | */
56 | public function getClerkList()
57 | {
58 | $id = $this->request->param('id');
59 | $mine = MyModel::get($id);
60 | $data = [];
61 | if ($mine)
62 | {
63 | $model = new Group();
64 | $data = $model->withClerk($id)->select();
65 | if ($data)
66 | {
67 | $redis = new \Redis();
68 | $redis->connect('127.0.0.1', '6379');
69 | foreach ($data as &$list)
70 | {
71 | $list->list = $list->clerk;
72 | unset($list->clerk);
73 | foreach ($list->list as $key => $clerk)
74 | {
75 | if ($redis->exists($clerk->id . ':' . 'clerk'))
76 | {
77 | $list->list[$key]['status'] = 'online';
78 | }
79 | }
80 | }
81 | }
82 | }
83 | $result = ['code' => 0, 'msg' => '', 'data' => ['mine' => $mine, 'friend' => $data]];
84 |
85 | return json($result);
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/thinkphp/library/think/db/builder/Sqlite.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\db\builder;
13 |
14 | use think\db\Builder;
15 | use think\db\Query;
16 |
17 | /**
18 | * Sqlite数据库驱动
19 | */
20 | class Sqlite extends Builder
21 | {
22 |
23 | /**
24 | * limit
25 | * @access public
26 | * @param Query $query 查询对象
27 | * @param mixed $limit
28 | * @return string
29 | */
30 | public function parseLimit(Query $query, $limit)
31 | {
32 | $limitStr = '';
33 |
34 | if (!empty($limit)) {
35 | $limit = explode(',', $limit);
36 | if (count($limit) > 1) {
37 | $limitStr .= ' LIMIT ' . $limit[1] . ' OFFSET ' . $limit[0] . ' ';
38 | } else {
39 | $limitStr .= ' LIMIT ' . $limit[0] . ' ';
40 | }
41 | }
42 |
43 | return $limitStr;
44 | }
45 |
46 | /**
47 | * 随机排序
48 | * @access protected
49 | * @param Query $query 查询对象
50 | * @return string
51 | */
52 | protected function parseRand(Query $query)
53 | {
54 | return 'RANDOM()';
55 | }
56 |
57 | /**
58 | * 字段和表名处理
59 | * @access public
60 | * @param Query $query 查询对象
61 | * @param mixed $key 字段名
62 | * @param bool $strict 严格检测
63 | * @return string
64 | */
65 | public function parseKey(Query $query, $key, $strict = false)
66 | {
67 | if (is_numeric($key)) {
68 | return $key;
69 | } elseif ($key instanceof Expression) {
70 | return $key->getValue();
71 | }
72 |
73 | $key = trim($key);
74 |
75 | if (strpos($key, '.')) {
76 | list($table, $key) = explode('.', $key, 2);
77 |
78 | $alias = $query->getOptions('alias');
79 |
80 | if ('__TABLE__' == $table) {
81 | $table = $query->getOptions('table');
82 | $table = is_array($table) ? array_shift($table) : $table;
83 | }
84 |
85 | if (isset($alias[$table])) {
86 | $table = $alias[$table];
87 | }
88 | }
89 |
90 | if (isset($table)) {
91 | $key = $table . '.' . $key;
92 | }
93 |
94 | return $key;
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/thinkphp/library/think/console/command/Clear.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 | namespace think\console\command;
12 |
13 | use think\console\Command;
14 | use think\console\Input;
15 | use think\console\input\Option;
16 | use think\console\Output;
17 | use think\facade\App;
18 | use think\facade\Cache;
19 |
20 | class Clear extends Command
21 | {
22 | protected function configure()
23 | {
24 | // 指令配置
25 | $this
26 | ->setName('clear')
27 | ->addOption('path', 'd', Option::VALUE_OPTIONAL, 'path to clear', null)
28 | ->addOption('cache', 'c', Option::VALUE_NONE, 'clear cache file')
29 | ->addOption('route', 'u', Option::VALUE_NONE, 'clear route cache')
30 | ->addOption('log', 'l', Option::VALUE_NONE, 'clear log file')
31 | ->addOption('dir', 'r', Option::VALUE_NONE, 'clear empty dir')
32 | ->setDescription('Clear runtime file');
33 | }
34 |
35 | protected function execute(Input $input, Output $output)
36 | {
37 | if ($input->getOption('route')) {
38 | Cache::clear('route_cache');
39 | } else {
40 | if ($input->getOption('cache')) {
41 | $path = App::getRuntimePath() . 'cache';
42 | } elseif ($input->getOption('log')) {
43 | $path = App::getRuntimePath() . 'log';
44 | } else {
45 | $path = $input->getOption('path') ?: App::getRuntimePath();
46 | }
47 |
48 | $rmdir = $input->getOption('dir') ? true : false;
49 | $this->clear(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR, $rmdir);
50 | }
51 |
52 | $output->writeln("Clear Successed");
53 | }
54 |
55 | protected function clear($path, $rmdir)
56 | {
57 | $files = is_dir($path) ? scandir($path) : [];
58 |
59 | foreach ($files as $file) {
60 | if ('.' != $file && '..' != $file && is_dir($path . $file)) {
61 | array_map('unlink', glob($path . $file . DIRECTORY_SEPARATOR . '*.*'));
62 | if ($rmdir) {
63 | rmdir($path . $file);
64 | }
65 | } elseif ('.gitignore' != $file && is_file($path . $file)) {
66 | unlink($path . $file);
67 | }
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/thinkphp/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | 如何贡献我的源代码
2 | ===
3 |
4 | 此文档介绍了 ThinkPHP 团队的组成以及运转机制,您提交的代码将给 ThinkPHP 项目带来什么好处,以及如何才能加入我们的行列。
5 |
6 | ## 通过 Github 贡献代码
7 |
8 | ThinkPHP 目前使用 Git 来控制程序版本,如果你想为 ThinkPHP 贡献源代码,请先大致了解 Git 的使用方法。我们目前把项目托管在 GitHub 上,任何 GitHub 用户都可以向我们贡献代码。
9 |
10 | 参与的方式很简单,`fork`一份 ThinkPHP 的代码到你的仓库中,修改后提交,并向我们发起`pull request`申请,我们会及时对代码进行审查并处理你的申请并。审查通过后,你的代码将被`merge`进我们的仓库中,这样你就会自动出现在贡献者名单里了,非常方便。
11 |
12 | 我们希望你贡献的代码符合:
13 |
14 | * ThinkPHP 的编码规范
15 | * 适当的注释,能让其他人读懂
16 | * 遵循 Apache2 开源协议
17 |
18 | **如果想要了解更多细节或有任何疑问,请继续阅读下面的内容**
19 |
20 | ### 注意事项
21 |
22 | * 本项目代码格式化标准选用 [**PSR-2**](http://www.kancloud.cn/thinkphp/php-fig-psr/3141);
23 | * 类名和类文件名遵循 [**PSR-4**](http://www.kancloud.cn/thinkphp/php-fig-psr/3144);
24 | * 对于 Issues 的处理,请使用诸如 `fix #xxx(Issue ID)` 的 commit title 直接关闭 issue。
25 | * 系统会自动在 PHP 5.4 5.5 5.6 7.0 和 HHVM 上测试修改,其中 HHVM 下的测试容许报错,请确保你的修改符合 PHP 5.4 ~ 5.6 和 PHP 7.0 的语法规范;
26 | * 管理员不会合并造成 CI faild 的修改,若出现 CI faild 请检查自己的源代码或修改相应的[单元测试文件](tests);
27 |
28 | ## GitHub Issue
29 |
30 | GitHub 提供了 Issue 功能,该功能可以用于:
31 |
32 | * 提出 bug
33 | * 提出功能改进
34 | * 反馈使用体验
35 |
36 | 该功能不应该用于:
37 |
38 | * 提出修改意见(涉及代码署名和修订追溯问题)
39 | * 不友善的言论
40 |
41 | ## 快速修改
42 |
43 | **GitHub 提供了快速编辑文件的功能**
44 |
45 | 1. 登录 GitHub 帐号;
46 | 2. 浏览项目文件,找到要进行修改的文件;
47 | 3. 点击右上角铅笔图标进行修改;
48 | 4. 填写 `Commit changes` 相关内容(Title 必填);
49 | 5. 提交修改,等待 CI 验证和管理员合并。
50 |
51 | **若您需要一次提交大量修改,请继续阅读下面的内容**
52 |
53 | ## 完整流程
54 |
55 | 1. `fork`本项目;
56 | 2. 克隆(`clone`)你 `fork` 的项目到本地;
57 | 3. 新建分支(`branch`)并检出(`checkout`)新分支;
58 | 4. 添加本项目到你的本地 git 仓库作为上游(`upstream`);
59 | 5. 进行修改,若你的修改包含方法或函数的增减,请记得修改[单元测试文件](tests);
60 | 6. 变基(衍合 `rebase`)你的分支到上游 master 分支;
61 | 7. `push` 你的本地仓库到 GitHub;
62 | 8. 提交 `pull request`;
63 | 9. 等待 CI 验证(若不通过则重复 5~7,GitHub 会自动更新你的 `pull request`);
64 | 10. 等待管理员处理,并及时 `rebase` 你的分支到上游 master 分支(若上游 master 分支有修改)。
65 |
66 | *若有必要,可以 `git push -f` 强行推送 rebase 后的分支到自己的 `fork`*
67 |
68 | *绝对不可以使用 `git push -f` 强行推送修改到上游*
69 |
70 | ### 注意事项
71 |
72 | * 若对上述流程有任何不清楚的地方,请查阅 GIT 教程,如 [这个](http://backlogtool.com/git-guide/cn/);
73 | * 对于代码**不同方面**的修改,请在自己 `fork` 的项目中**创建不同的分支**(原因参见`完整流程`第9条备注部分);
74 | * 变基及交互式变基操作参见 [Git 交互式变基](http://pakchoi.me/2015/03/17/git-interactive-rebase/)
75 |
76 | ## 推荐资源
77 |
78 | ### 开发环境
79 |
80 | * XAMPP for Windows 5.5.x
81 | * WampServer (for Windows)
82 | * upupw Apache PHP5.4 ( for Windows)
83 |
84 | 或自行安装
85 |
86 | - Apache / Nginx
87 | - PHP 5.4 ~ 5.6
88 | - MySQL / MariaDB
89 |
90 | *Windows 用户推荐添加 PHP bin 目录到 PATH,方便使用 composer*
91 |
92 | *Linux 用户自行配置环境, Mac 用户推荐使用内置 Apache 配合 Homebrew 安装 PHP 和 MariaDB*
93 |
94 | ### 编辑器
95 |
96 | Sublime Text 3 + phpfmt 插件
97 |
98 | phpfmt 插件参数
99 |
100 | ```json
101 | {
102 | "autocomplete": true,
103 | "enable_auto_align": true,
104 | "format_on_save": true,
105 | "indent_with_space": true,
106 | "psr1_naming": false,
107 | "psr2": true,
108 | "version": 4
109 | }
110 | ```
111 |
112 | 或其他 编辑器 / IDE 配合 PSR2 自动格式化工具
113 |
114 | ### Git GUI
115 |
116 | * SourceTree
117 | * GitHub Desktop
118 |
119 | 或其他 Git 图形界面客户端
120 |
--------------------------------------------------------------------------------
/thinkphp/library/think/model/Collection.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\model;
13 |
14 | use think\Collection as BaseCollection;
15 | use think\Model;
16 |
17 | class Collection extends BaseCollection
18 | {
19 | /**
20 | * 延迟预载入关联查询
21 | * @access public
22 | * @param mixed $relation 关联
23 | * @return $this
24 | */
25 | public function load($relation)
26 | {
27 | $item = current($this->items);
28 | $item->eagerlyResultSet($this->items, $relation);
29 |
30 | return $this;
31 | }
32 |
33 | /**
34 | * 设置需要隐藏的输出属性
35 | * @access public
36 | * @param array $hidden 属性列表
37 | * @param bool $override 是否覆盖
38 | * @return $this
39 | */
40 | public function hidden($hidden = [], $override = false)
41 | {
42 | $this->each(function ($model) use ($hidden, $override) {
43 | /** @var Model $model */
44 | $model->hidden($hidden, $override);
45 | });
46 |
47 | return $this;
48 | }
49 |
50 | /**
51 | * 设置需要输出的属性
52 | * @access public
53 | * @param array $visible
54 | * @param bool $override 是否覆盖
55 | * @return $this
56 | */
57 | public function visible($visible = [], $override = false)
58 | {
59 | $this->each(function ($model) use ($visible, $override) {
60 | /** @var Model $model */
61 | $model->visible($visible, $override);
62 | });
63 |
64 | return $this;
65 | }
66 |
67 | /**
68 | * 设置需要追加的输出属性
69 | * @access public
70 | * @param array $append 属性列表
71 | * @param bool $override 是否覆盖
72 | * @return $this
73 | */
74 | public function append($append = [], $override = false)
75 | {
76 | $this->each(function ($model) use ($append, $override) {
77 | /** @var Model $model */
78 | $model && $model->append($append, $override);
79 | });
80 |
81 | return $this;
82 | }
83 |
84 | /**
85 | * 设置数据字段获取器
86 | * @access public
87 | * @param string|array $name 字段名
88 | * @param callable $callback 闭包获取器
89 | * @return $this
90 | */
91 | public function withAttr($name, $callback = null)
92 | {
93 | $this->each(function ($model) use ($name, $callback) {
94 | /** @var Model $model */
95 | $model && $model->withAttribute($name, $callback);
96 | });
97 |
98 | return $this;
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/thinkphp/library/think/console/output/formatter/Stack.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\console\output\formatter;
13 |
14 | class Stack
15 | {
16 |
17 | /**
18 | * @var Style[]
19 | */
20 | private $styles;
21 |
22 | /**
23 | * @var Style
24 | */
25 | private $emptyStyle;
26 |
27 | /**
28 | * 构造方法
29 | * @param Style|null $emptyStyle
30 | */
31 | public function __construct(Style $emptyStyle = null)
32 | {
33 | $this->emptyStyle = $emptyStyle ?: new Style();
34 | $this->reset();
35 | }
36 |
37 | /**
38 | * 重置堆栈
39 | */
40 | public function reset()
41 | {
42 | $this->styles = [];
43 | }
44 |
45 | /**
46 | * 推一个样式进入堆栈
47 | * @param Style $style
48 | */
49 | public function push(Style $style)
50 | {
51 | $this->styles[] = $style;
52 | }
53 |
54 | /**
55 | * 从堆栈中弹出一个样式
56 | * @param Style|null $style
57 | * @return Style
58 | * @throws \InvalidArgumentException
59 | */
60 | public function pop(Style $style = null)
61 | {
62 | if (empty($this->styles)) {
63 | return $this->emptyStyle;
64 | }
65 |
66 | if (null === $style) {
67 | return array_pop($this->styles);
68 | }
69 |
70 | /**
71 | * @var int $index
72 | * @var Style $stackedStyle
73 | */
74 | foreach (array_reverse($this->styles, true) as $index => $stackedStyle) {
75 | if ($style->apply('') === $stackedStyle->apply('')) {
76 | $this->styles = array_slice($this->styles, 0, $index);
77 |
78 | return $stackedStyle;
79 | }
80 | }
81 |
82 | throw new \InvalidArgumentException('Incorrectly nested style tag found.');
83 | }
84 |
85 | /**
86 | * 计算堆栈的当前样式。
87 | * @return Style
88 | */
89 | public function getCurrent()
90 | {
91 | if (empty($this->styles)) {
92 | return $this->emptyStyle;
93 | }
94 |
95 | return $this->styles[count($this->styles) - 1];
96 | }
97 |
98 | /**
99 | * @param Style $emptyStyle
100 | * @return Stack
101 | */
102 | public function setEmptyStyle(Style $emptyStyle)
103 | {
104 | $this->emptyStyle = $emptyStyle;
105 |
106 | return $this;
107 | }
108 |
109 | /**
110 | * @return Style
111 | */
112 | public function getEmptyStyle()
113 | {
114 | return $this->emptyStyle;
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/thinkphp/library/think/Env.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think;
13 |
14 | class Env
15 | {
16 | /**
17 | * 环境变量数据
18 | * @var array
19 | */
20 | protected $data = [];
21 |
22 | public function __construct()
23 | {
24 | $this->data = $_ENV;
25 | }
26 |
27 | /**
28 | * 读取环境变量定义文件
29 | * @access public
30 | * @param string $file 环境变量定义文件
31 | * @return void
32 | */
33 | public function load($file)
34 | {
35 | $env = parse_ini_file($file, true);
36 | $this->set($env);
37 | }
38 |
39 | /**
40 | * 获取环境变量值
41 | * @access public
42 | * @param string $name 环境变量名
43 | * @param mixed $default 默认值
44 | * @return mixed
45 | */
46 | public function get($name = null, $default = null)
47 | {
48 | if (is_null($name)) {
49 | return $this->data;
50 | }
51 |
52 | $name = strtoupper(str_replace('.', '_', $name));
53 |
54 | if (isset($this->data[$name])) {
55 | return $this->data[$name];
56 | }
57 |
58 | return $this->getEnv($name, $default);
59 | }
60 |
61 | protected function getEnv($name, $default = null)
62 | {
63 | $result = getenv('PHP_' . $name);
64 |
65 | if (false === $result) {
66 | return $default;
67 | }
68 |
69 | if ('false' === $result) {
70 | $result = false;
71 | } elseif ('true' === $result) {
72 | $result = true;
73 | }
74 |
75 | if (!isset($this->data[$name])) {
76 | $this->data[$name] = $result;
77 | }
78 |
79 | return $result;
80 | }
81 |
82 | /**
83 | * 设置环境变量值
84 | * @access public
85 | * @param string|array $env 环境变量
86 | * @param mixed $value 值
87 | * @return void
88 | */
89 | public function set($env, $value = null)
90 | {
91 | if (is_array($env)) {
92 | $env = array_change_key_case($env, CASE_UPPER);
93 |
94 | foreach ($env as $key => $val) {
95 | if (is_array($val)) {
96 | foreach ($val as $k => $v) {
97 | $this->data[$key . '_' . strtoupper($k)] = $v;
98 | }
99 | } else {
100 | $this->data[$key] = $val;
101 | }
102 | }
103 | } else {
104 | $name = strtoupper(str_replace('.', '_', $env));
105 |
106 | $this->data[$name] = $value;
107 | }
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/thinkphp/library/think/facade/App.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\facade;
13 |
14 | use think\Facade;
15 |
16 | /**
17 | * @see \think\App
18 | * @mixin \think\App
19 | * @method \think\App bind(string $bind) static 绑定模块或者控制器
20 | * @method void initialize() static 初始化应用
21 | * @method void init(string $module='') static 初始化模块
22 | * @method \think\Response run() static 执行应用
23 | * @method \think\App dispatch(\think\route\Dispatch $dispatch) static 设置当前请求的调度信息
24 | * @method void log(mixed $log, string $type = 'info') static 记录调试信息
25 | * @method mixed config(string $name='') static 获取配置参数
26 | * @method \think\route\Dispatch routeCheck() static URL路由检测(根据PATH_INFO)
27 | * @method \think\App routeMust(bool $must = false) static 设置应用的路由检测机制
28 | * @method \think\Model model(string $name = '', string $layer = 'model', bool $appendSuffix = false, string $common = 'common') static 实例化模型
29 | * @method object controller(string $name, string $layer = 'controller', bool $appendSuffix = false, string $empty = '') static 实例化控制器
30 | * @method \think\Validate validate(string $name = '', string $layer = 'validate', bool $appendSuffix = false, string $common = 'common') static 实例化验证器类
31 | * @method \think\db\Query db(mixed $config = [], mixed $name = false) static 数据库初始化
32 | * @method mixed action(string $url, $vars = [], $layer = 'controller', $appendSuffix = false) static 调用模块的操作方法
33 | * @method string parseClass(string $module, string $layer, string $name, bool $appendSuffix = false) static 解析应用类的类名
34 | * @method string version() static 获取框架版本
35 | * @method bool isDebug() static 是否为调试模式
36 | * @method string getModulePath() static 获取当前模块路径
37 | * @method void setModulePath(string $path) static 设置当前模块路径
38 | * @method string getRootPath() static 获取应用根目录
39 | * @method string getAppPath() static 获取应用类库目录
40 | * @method string getRuntimePath() static 获取应用运行时目录
41 | * @method string getThinkPath() static 获取核心框架目录
42 | * @method string getRoutePath() static 获取路由目录
43 | * @method string getConfigPath() static 获取应用配置目录
44 | * @method string getConfigExt() static 获取配置后缀
45 | * @method string setNamespace(string $namespace) static 设置应用类库命名空间
46 | * @method string getNamespace() static 获取应用类库命名空间
47 | * @method string getSuffix() static 是否启用类库后缀
48 | * @method float getBeginTime() static 获取应用开启时间
49 | * @method integer getBeginMem() static 获取应用初始内存占用
50 | * @method \think\Container container() static 获取容器实例
51 | */
52 | class App extends Facade
53 | {
54 | /**
55 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识)
56 | * @access protected
57 | * @return string
58 | */
59 | protected static function getFacadeClass()
60 | {
61 | return 'app';
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/thinkphp/library/think/response/Redirect.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\response;
13 |
14 | use think\Response;
15 |
16 | class Redirect extends Response
17 | {
18 |
19 | protected $options = [];
20 |
21 | // URL参数
22 | protected $params = [];
23 |
24 | public function __construct($data = '', $code = 302, array $header = [], array $options = [])
25 | {
26 | parent::__construct($data, $code, $header, $options);
27 |
28 | $this->cacheControl('no-cache,must-revalidate');
29 | }
30 |
31 | /**
32 | * 处理数据
33 | * @access protected
34 | * @param mixed $data 要处理的数据
35 | * @return mixed
36 | */
37 | protected function output($data)
38 | {
39 | $this->header['Location'] = $this->getTargetUrl();
40 |
41 | return;
42 | }
43 |
44 | /**
45 | * 重定向传值(通过Session)
46 | * @access protected
47 | * @param string|array $name 变量名或者数组
48 | * @param mixed $value 值
49 | * @return $this
50 | */
51 | public function with($name, $value = null)
52 | {
53 | $session = $this->app['session'];
54 |
55 | if (is_array($name)) {
56 | foreach ($name as $key => $val) {
57 | $session->flash($key, $val);
58 | }
59 | } else {
60 | $session->flash($name, $value);
61 | }
62 |
63 | return $this;
64 | }
65 |
66 | /**
67 | * 获取跳转地址
68 | * @access public
69 | * @return string
70 | */
71 | public function getTargetUrl()
72 | {
73 | if (strpos($this->data, '://') || (0 === strpos($this->data, '/') && empty($this->params))) {
74 | return $this->data;
75 | } else {
76 | return $this->app['url']->build($this->data, $this->params);
77 | }
78 | }
79 |
80 | public function params($params = [])
81 | {
82 | $this->params = $params;
83 |
84 | return $this;
85 | }
86 |
87 | /**
88 | * 记住当前url后跳转
89 | * @access public
90 | * @return $this
91 | */
92 | public function remember()
93 | {
94 | $this->app['session']->set('redirect_url', $this->app['request']->url());
95 |
96 | return $this;
97 | }
98 |
99 | /**
100 | * 跳转到上次记住的url
101 | * @access public
102 | * @return $this
103 | */
104 | public function restore()
105 | {
106 | $session = $this->app['session'];
107 |
108 | if ($session->has('redirect_url')) {
109 | $this->data = $session->get('redirect_url');
110 | $session->delete('redirect_url');
111 | }
112 |
113 | return $this;
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/thinkphp/library/think/db/builder/Pgsql.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\db\builder;
13 |
14 | use think\db\Builder;
15 | use think\db\Query;
16 |
17 | /**
18 | * Pgsql数据库驱动
19 | */
20 | class Pgsql extends Builder
21 | {
22 |
23 | protected $insertSql = 'INSERT INTO %TABLE% (%FIELD%) VALUES (%DATA%) %COMMENT%';
24 | protected $insertAllSql = 'INSERT INTO %TABLE% (%FIELD%) %DATA% %COMMENT%';
25 |
26 | /**
27 | * limit分析
28 | * @access protected
29 | * @param Query $query 查询对象
30 | * @param mixed $limit
31 | * @return string
32 | */
33 | public function parseLimit(Query $query, $limit)
34 | {
35 | $limitStr = '';
36 |
37 | if (!empty($limit)) {
38 | $limit = explode(',', $limit);
39 | if (count($limit) > 1) {
40 | $limitStr .= ' LIMIT ' . $limit[1] . ' OFFSET ' . $limit[0] . ' ';
41 | } else {
42 | $limitStr .= ' LIMIT ' . $limit[0] . ' ';
43 | }
44 | }
45 |
46 | return $limitStr;
47 | }
48 |
49 | /**
50 | * 字段和表名处理
51 | * @access public
52 | * @param Query $query 查询对象
53 | * @param mixed $key 字段名
54 | * @param bool $strict 严格检测
55 | * @return string
56 | */
57 | public function parseKey(Query $query, $key, $strict = false)
58 | {
59 | if (is_numeric($key)) {
60 | return $key;
61 | } elseif ($key instanceof Expression) {
62 | return $key->getValue();
63 | }
64 |
65 | $key = trim($key);
66 |
67 | if (strpos($key, '->') && false === strpos($key, '(')) {
68 | // JSON字段支持
69 | list($field, $name) = explode('->', $key);
70 | $key = $field . '->>\'' . $name . '\'';
71 | } elseif (strpos($key, '.')) {
72 | list($table, $key) = explode('.', $key, 2);
73 |
74 | $alias = $query->getOptions('alias');
75 |
76 | if ('__TABLE__' == $table) {
77 | $table = $query->getOptions('table');
78 | $table = is_array($table) ? array_shift($table) : $table;
79 | }
80 |
81 | if (isset($alias[$table])) {
82 | $table = $alias[$table];
83 | }
84 | }
85 |
86 | if (isset($table)) {
87 | $key = $table . '.' . $key;
88 | }
89 |
90 | return $key;
91 | }
92 |
93 | /**
94 | * 随机排序
95 | * @access protected
96 | * @param Query $query 查询对象
97 | * @return string
98 | */
99 | protected function parseRand(Query $query)
100 | {
101 | return 'RANDOM()';
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/thinkphp/library/think/db/connector/Sqlite.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\db\connector;
13 |
14 | use PDO;
15 | use think\db\Connection;
16 |
17 | /**
18 | * Sqlite数据库驱动
19 | */
20 | class Sqlite extends Connection
21 | {
22 |
23 | protected $builder = '\\think\\db\\builder\\Sqlite';
24 |
25 | /**
26 | * 解析pdo连接的dsn信息
27 | * @access protected
28 | * @param array $config 连接信息
29 | * @return string
30 | */
31 | protected function parseDsn($config)
32 | {
33 | $dsn = 'sqlite:' . $config['database'];
34 |
35 | return $dsn;
36 | }
37 |
38 | /**
39 | * 取得数据表的字段信息
40 | * @access public
41 | * @param string $tableName
42 | * @return array
43 | */
44 | public function getFields($tableName)
45 | {
46 | list($tableName) = explode(' ', $tableName);
47 | $sql = 'PRAGMA table_info( ' . $tableName . ' )';
48 |
49 | $pdo = $this->query($sql, [], false, true);
50 | $result = $pdo->fetchAll(PDO::FETCH_ASSOC);
51 | $info = [];
52 |
53 | if ($result) {
54 | foreach ($result as $key => $val) {
55 | $val = array_change_key_case($val);
56 | $info[$val['name']] = [
57 | 'name' => $val['name'],
58 | 'type' => $val['type'],
59 | 'notnull' => 1 === $val['notnull'],
60 | 'default' => $val['dflt_value'],
61 | 'primary' => '1' == $val['pk'],
62 | 'autoinc' => '1' == $val['pk'],
63 | ];
64 | }
65 | }
66 |
67 | return $this->fieldCase($info);
68 | }
69 |
70 | /**
71 | * 取得数据库的表信息
72 | * @access public
73 | * @param string $dbName
74 | * @return array
75 | */
76 | public function getTables($dbName = '')
77 | {
78 | $sql = "SELECT name FROM sqlite_master WHERE type='table' "
79 | . "UNION ALL SELECT name FROM sqlite_temp_master "
80 | . "WHERE type='table' ORDER BY name";
81 |
82 | $pdo = $this->query($sql, [], false, true);
83 | $result = $pdo->fetchAll(PDO::FETCH_ASSOC);
84 | $info = [];
85 |
86 | foreach ($result as $key => $val) {
87 | $info[$key] = current($val);
88 | }
89 |
90 | return $info;
91 | }
92 |
93 | /**
94 | * SQL性能分析
95 | * @access protected
96 | * @param string $sql
97 | * @return array
98 | */
99 | protected function getExplain($sql)
100 | {
101 | return [];
102 | }
103 |
104 | protected function supportSavepoint()
105 | {
106 | return true;
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/thinkphp/library/think/console/input/Argument.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\console\input;
13 |
14 | class Argument
15 | {
16 |
17 | const REQUIRED = 1;
18 | const OPTIONAL = 2;
19 | const IS_ARRAY = 4;
20 |
21 | private $name;
22 | private $mode;
23 | private $default;
24 | private $description;
25 |
26 | /**
27 | * 构造方法
28 | * @param string $name 参数名
29 | * @param int $mode 参数类型: self::REQUIRED 或者 self::OPTIONAL
30 | * @param string $description 描述
31 | * @param mixed $default 默认值 (仅 self::OPTIONAL 类型有效)
32 | * @throws \InvalidArgumentException
33 | */
34 | public function __construct($name, $mode = null, $description = '', $default = null)
35 | {
36 | if (null === $mode) {
37 | $mode = self::OPTIONAL;
38 | } elseif (!is_int($mode) || $mode > 7 || $mode < 1) {
39 | throw new \InvalidArgumentException(sprintf('Argument mode "%s" is not valid.', $mode));
40 | }
41 |
42 | $this->name = $name;
43 | $this->mode = $mode;
44 | $this->description = $description;
45 |
46 | $this->setDefault($default);
47 | }
48 |
49 | /**
50 | * 获取参数名
51 | * @return string
52 | */
53 | public function getName()
54 | {
55 | return $this->name;
56 | }
57 |
58 | /**
59 | * 是否必须
60 | * @return bool
61 | */
62 | public function isRequired()
63 | {
64 | return self::REQUIRED === (self::REQUIRED & $this->mode);
65 | }
66 |
67 | /**
68 | * 该参数是否接受数组
69 | * @return bool
70 | */
71 | public function isArray()
72 | {
73 | return self::IS_ARRAY === (self::IS_ARRAY & $this->mode);
74 | }
75 |
76 | /**
77 | * 设置默认值
78 | * @param mixed $default 默认值
79 | * @throws \LogicException
80 | */
81 | public function setDefault($default = null)
82 | {
83 | if (self::REQUIRED === $this->mode && null !== $default) {
84 | throw new \LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.');
85 | }
86 |
87 | if ($this->isArray()) {
88 | if (null === $default) {
89 | $default = [];
90 | } elseif (!is_array($default)) {
91 | throw new \LogicException('A default value for an array argument must be an array.');
92 | }
93 | }
94 |
95 | $this->default = $default;
96 | }
97 |
98 | /**
99 | * 获取默认值
100 | * @return mixed
101 | */
102 | public function getDefault()
103 | {
104 | return $this->default;
105 | }
106 |
107 | /**
108 | * 获取描述
109 | * @return string
110 | */
111 | public function getDescription()
112 | {
113 | return $this->description;
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/thinkphp/library/think/facade/Route.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\facade;
13 |
14 | use think\Facade;
15 |
16 | /**
17 | * @see \think\Route
18 | * @mixin \think\Route
19 | * @method \think\route\Domain domain(mixed $name, mixed $rule = '', array $option = [], array $pattern = []) static 注册域名路由
20 | * @method \think\Route pattern(mixed $name, string $rule = '') static 注册变量规则
21 | * @method \think\Route option(mixed $name, mixed $value = '') static 注册路由参数
22 | * @method \think\Route bind(string $bind) static 设置路由绑定
23 | * @method mixed getBind(string $bind) static 读取路由绑定
24 | * @method \think\Route name(string $name) static 设置当前路由标识
25 | * @method mixed getName(string $name) static 读取路由标识
26 | * @method void setName(string $name) static 批量导入路由标识
27 | * @method void import(array $rules, string $type = '*') static 导入配置文件的路由规则
28 | * @method \think\route\RuleItem rule(string $rule, mixed $route, string $method = '*', array $option = [], array $pattern = []) static 注册路由规则
29 | * @method void rules(array $rules, string $method = '*', array $option = [], array $pattern = []) static 批量注册路由规则
30 | * @method \think\route\RuleGroup group(string|array $name, mixed $route, string $method = '*', array $option = [], array $pattern = []) static 注册路由分组
31 | * @method \think\route\RuleItem any(string $rule, mixed $route, array $option = [], array $pattern = []) static 注册路由
32 | * @method \think\route\RuleItem get(string $rule, mixed $route, array $option = [], array $pattern = []) static 注册路由
33 | * @method \think\route\RuleItem post(string $rule, mixed $route, array $option = [], array $pattern = []) static 注册路由
34 | * @method \think\route\RuleItem put(string $rule, mixed $route, array $option = [], array $pattern = []) static 注册路由
35 | * @method \think\route\RuleItem delete(string $rule, mixed $route, array $option = [], array $pattern = []) static 注册路由
36 | * @method \think\route\RuleItem patch(string $rule, mixed $route, array $option = [], array $pattern = []) static 注册路由
37 | * @method \think\route\Resource resource(string $rule, mixed $route, array $option = [], array $pattern = []) static 注册资源路由
38 | * @method \think\Route controller(string $rule, mixed $route, array $option = [], array $pattern = []) static 注册控制器路由
39 | * @method \think\Route alias(string $rule, mixed $route, array $option = [], array $pattern = []) static 注册别名路由
40 | * @method \think\Route setMethodPrefix(mixed $method, string $prefix = '') static 设置不同请求类型下面的方法前缀
41 | * @method \think\Route rest(string $name, array $resource = []) static rest方法定义和修改
42 | * @method \think\Route\RuleItem miss(string $route, string $method = '*', array $option = []) static 注册未匹配路由规则后的处理
43 | * @method \think\Route\RuleItem auto(string $route) static 注册一个自动解析的URL路由
44 | * @method \think\Route\Dispatch check(string $url, string $depr = '/', bool $must = false, bool $completeMatch = false) static 检测URL路由
45 | */
46 | class Route extends Facade
47 | {
48 | /**
49 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识)
50 | * @access protected
51 | * @return string
52 | */
53 | protected static function getFacadeClass()
54 | {
55 | return 'route';
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/thinkphp/library/think/console/command/Make.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\console\command;
13 |
14 | use think\console\Command;
15 | use think\console\Input;
16 | use think\console\input\Argument;
17 | use think\console\Output;
18 | use think\facade\App;
19 | use think\facade\Config;
20 | use think\facade\Env;
21 |
22 | abstract class Make extends Command
23 | {
24 |
25 | protected $type;
26 |
27 | abstract protected function getStub();
28 |
29 | protected function configure()
30 | {
31 | $this->addArgument('name', Argument::REQUIRED, "The name of the class");
32 | }
33 |
34 | protected function execute(Input $input, Output $output)
35 | {
36 |
37 | $name = trim($input->getArgument('name'));
38 |
39 | $classname = $this->getClassName($name);
40 |
41 | $pathname = $this->getPathName($classname);
42 |
43 | if (is_file($pathname)) {
44 | $output->writeln('' . $this->type . ' already exists!');
45 | return false;
46 | }
47 |
48 | if (!is_dir(dirname($pathname))) {
49 | mkdir(dirname($pathname), 0755, true);
50 | }
51 |
52 | file_put_contents($pathname, $this->buildClass($classname));
53 |
54 | $output->writeln('' . $this->type . ' created successfully.');
55 |
56 | }
57 |
58 | protected function buildClass($name)
59 | {
60 | $stub = file_get_contents($this->getStub());
61 |
62 | $namespace = trim(implode('\\', array_slice(explode('\\', $name), 0, -1)), '\\');
63 |
64 | $class = str_replace($namespace . '\\', '', $name);
65 |
66 | return str_replace(['{%className%}', '{%namespace%}', '{%app_namespace%}'], [
67 | $class,
68 | $namespace,
69 | App::getNamespace(),
70 | ], $stub);
71 |
72 | }
73 |
74 | protected function getPathName($name)
75 | {
76 | $name = str_replace(App::getNamespace() . '\\', '', $name);
77 |
78 | return Env::get('app_path') . ltrim(str_replace('\\', '/', $name), '/') . '.php';
79 | }
80 |
81 | protected function getClassName($name)
82 | {
83 | $appNamespace = App::getNamespace();
84 |
85 | if (strpos($name, $appNamespace . '\\') !== false) {
86 | return $name;
87 | }
88 |
89 | if (Config::get('app_multi_module')) {
90 | if (strpos($name, '/')) {
91 | list($module, $name) = explode('/', $name, 2);
92 | } else {
93 | $module = 'common';
94 | }
95 | } else {
96 | $module = null;
97 | }
98 |
99 | if (strpos($name, '/') !== false) {
100 | $name = str_replace('/', '\\', $name);
101 | }
102 |
103 | return $this->getNamespace($appNamespace, $module) . '\\' . $name;
104 | }
105 |
106 | protected function getNamespace($appNamespace, $module)
107 | {
108 | return $module ? ($appNamespace . '\\' . $module) : $appNamespace;
109 | }
110 |
111 | }
112 |
--------------------------------------------------------------------------------