├── CONTRIBUTING.md
├── LICENSE.txt
├── README.md
├── application
├── build.php
├── common.php
├── config.php
├── database.php
├── hitokoto
│ ├── config.php
│ └── controller
│ │ ├── Add.php
│ │ └── Main.php
├── img
│ ├── config.php
│ └── controller
│ │ ├── Index.php
│ │ ├── Proxy.php
│ │ ├── Qrcode.php
│ │ ├── icon.png
│ │ ├── phpqrcode.php
│ │ └── saeqrcode.class.php
├── index
│ └── controller
│ │ └── Index.php
├── music
│ ├── config.php
│ ├── controller
│ │ ├── Netease.php
│ │ └── Xiami.php
│ └── event
│ │ └── Netease.php
├── route.php
└── stats
│ ├── config.php
│ └── controller
│ ├── Index.php
│ └── Program.php
├── build.php
├── composer.json
├── composer.lock
├── console
├── lwl_api_数据库文件.zip
├── public
├── .htaccess
├── dsavatar
│ └── index.php
├── errpage
│ ├── 403.html
│ ├── 404.html
│ ├── 451.html
│ ├── 500.html
│ ├── 502.html
│ ├── 503.html
│ ├── Maintain.html
│ └── error.css
├── hitokoto
│ └── index.php
├── index.php
├── qrcode
│ └── index.php
├── robots.txt
├── router.php
├── static
│ └── .gitignore
└── wordpress
│ └── plugin
│ └── wpplus
│ ├── index.php
│ └── post.php
└── thinkphp
├── base.php
├── convention.php
├── extend
└── .gitignore
├── helper.php
├── lang
└── .gitignore
├── library
├── think
│ ├── App.php
│ ├── Build.php
│ ├── Cache.php
│ ├── Config.php
│ ├── Console.php
│ ├── Controller.php
│ ├── Cookie.php
│ ├── Db.php
│ ├── Debug.php
│ ├── Error.php
│ ├── Exception.php
│ ├── Hook.php
│ ├── Input.php
│ ├── Lang.php
│ ├── Loader.php
│ ├── Log.php
│ ├── Model.php
│ ├── ORM.php
│ ├── Process.php
│ ├── Response.php
│ ├── Route.php
│ ├── Session.php
│ ├── Template.php
│ ├── Url.php
│ ├── View.php
│ ├── cache
│ │ └── driver
│ │ │ ├── Apc.php
│ │ │ ├── Db.php
│ │ │ ├── File.php
│ │ │ ├── Lite.php
│ │ │ ├── Memcache.php
│ │ │ ├── Memcached.php
│ │ │ ├── Redis.php
│ │ │ ├── Sae.php
│ │ │ ├── Secache.php
│ │ │ ├── Sqlite.php
│ │ │ ├── Test.php
│ │ │ ├── Wincache.php
│ │ │ └── Xcache.php
│ ├── config
│ │ └── driver
│ │ │ ├── Ini.php
│ │ │ └── Xml.php
│ ├── console
│ │ ├── Input.php
│ │ ├── Output.php
│ │ ├── bin
│ │ │ ├── README.md
│ │ │ └── hiddeninput.exe
│ │ ├── command
│ │ │ ├── Build.php
│ │ │ ├── Command.php
│ │ │ ├── Help.php
│ │ │ ├── Lists.php
│ │ │ └── make
│ │ │ │ ├── Controller.php
│ │ │ │ └── Model.php
│ │ ├── helper
│ │ │ ├── Debug.php
│ │ │ ├── Descriptor.php
│ │ │ ├── Formatter.php
│ │ │ ├── Helper.php
│ │ │ ├── Process.php
│ │ │ ├── Question.php
│ │ │ ├── Set.php
│ │ │ ├── descriptor
│ │ │ │ ├── Console.php
│ │ │ │ └── Descriptor.php
│ │ │ └── question
│ │ │ │ ├── Choice.php
│ │ │ │ ├── Confirmation.php
│ │ │ │ └── Question.php
│ │ ├── input
│ │ │ ├── Argument.php
│ │ │ ├── Definition.php
│ │ │ └── Option.php
│ │ └── output
│ │ │ ├── Formatter.php
│ │ │ ├── Stream.php
│ │ │ └── formatter
│ │ │ ├── Stack.php
│ │ │ └── Style.php
│ ├── controller
│ │ ├── Hprose.php
│ │ ├── Jsonrpc.php
│ │ ├── Rest.php
│ │ ├── Rpc.php
│ │ └── Yar.php
│ ├── db
│ │ ├── Driver.php
│ │ └── driver
│ │ │ ├── Mongo.php
│ │ │ ├── Mysql.php
│ │ │ ├── Oracle.php
│ │ │ ├── Pgsql.php
│ │ │ ├── Sqlite.php
│ │ │ └── Sqlsrv.php
│ ├── exception
│ │ ├── DbBindParamException.php
│ │ ├── DbException.php
│ │ ├── ErrorException.php
│ │ ├── NotFoundException.php
│ │ └── PDOException.php
│ ├── log
│ │ ├── alarm
│ │ │ └── Email.php
│ │ └── driver
│ │ │ ├── File.php
│ │ │ ├── Sae.php
│ │ │ ├── Socket.php
│ │ │ ├── Test.php
│ │ │ └── Trace.php
│ ├── model
│ │ ├── Adv.php
│ │ ├── Mongo.php
│ │ ├── Relation.php
│ │ └── View.php
│ ├── process
│ │ ├── Builder.php
│ │ ├── Utils.php
│ │ ├── exception
│ │ │ ├── Faild.php
│ │ │ └── Timeout.php
│ │ └── pipes
│ │ │ ├── Pipes.php
│ │ │ ├── Unix.php
│ │ │ └── Windows.php
│ ├── session
│ │ └── driver
│ │ │ ├── Memcache.php
│ │ │ ├── Memcached.php
│ │ │ └── Redis.php
│ ├── template
│ │ ├── TagLib.php
│ │ ├── driver
│ │ │ ├── File.php
│ │ │ └── Sae.php
│ │ └── taglib
│ │ │ └── Cx.php
│ └── view
│ │ └── driver
│ │ └── Think.php
└── traits
│ ├── controller
│ ├── Jump.php
│ └── View.php
│ ├── model
│ ├── Adv.php
│ ├── Auto.php
│ ├── Bulk.php
│ ├── Relation.php
│ ├── Transaction.php
│ └── View.php
│ └── think
│ └── Instance.php
├── mode
├── common.php
├── console.php
└── sae.php
├── phpunit.xml
├── start.php
├── tests
├── README.md
├── conf
│ ├── apcu.ini
│ ├── apcu_bc.ini
│ ├── memcached.ini
│ └── redis.ini
├── extensions
│ ├── 5.4
│ │ └── apcu.so
│ ├── 5.5
│ │ └── apcu.so
│ ├── 5.6
│ │ └── apcu.so
│ └── 7.0
│ │ ├── apc.so
│ │ ├── apcu.so
│ │ ├── memcached.so
│ │ └── redis.so
├── mock.php
├── script
│ └── install.sh
└── thinkphp
│ ├── baseTest.php
│ └── library
│ ├── think
│ ├── appTest.php
│ ├── cache
│ │ └── driver
│ │ │ ├── apcTest.php
│ │ │ ├── cacheTestCase.php
│ │ │ ├── dbTest.php
│ │ │ ├── memcachedTest.php
│ │ │ └── redisTest.php
│ ├── config
│ │ └── driver
│ │ │ ├── fixtures
│ │ │ ├── config.ini
│ │ │ └── config.xml
│ │ │ ├── iniTest.php
│ │ │ └── xmlTest.php
│ ├── configTest.php
│ ├── controller
│ │ └── .gitignore
│ ├── controllerTest.php
│ ├── cookieTest.php
│ ├── db
│ │ └── driver
│ │ │ └── .gitignore
│ ├── debugTest.php
│ ├── display.html
│ ├── extend.html
│ ├── extend2.html
│ ├── include.html
│ ├── inputTest.php
│ ├── layout.html
│ ├── log
│ │ └── driver
│ │ │ └── fileTest.php
│ ├── model
│ │ └── .gitignore
│ ├── responseTest.php
│ ├── session
│ │ └── .gitignore
│ ├── sessionTest.php
│ ├── template
│ │ ├── driver
│ │ │ └── .gitignore
│ │ └── taglib
│ │ │ └── cxTest.php
│ ├── templateTest.php
│ ├── view
│ │ └── driver
│ │ │ └── .gitignore
│ └── viewTest.php
│ └── traits
│ ├── controller
│ └── .gitignore
│ └── model
│ └── .gitignore
├── tpl
├── default_index.tpl
├── dispatch_jump.tpl
├── page_trace.tpl
└── think_exception.tpl
└── vendor
└── .gitignore
/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 请检查自己的源代码或修改相应的[单元测试文件](thinkphp/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. 进行修改,若你的修改包含方法或函数的增减,请记得修改[单元测试文件](thinkphp/tests);
60 | 6. 变基(衍合 `rebase`)你的分支到上游 master 分支;
61 | 7. `push` 你的本地仓库到 GitHub;
62 | 8. 提交 ``pull request`s`;
63 | 9. 等待 CI 验证(若不通过则重复 5~7,GitHub 会自动更新你的 ``pull request`s`);
64 | 10. 等待管理员处理,并及时 `rebase` 你的分支到上游 master 分支(若上游 master 分支有修改)。
65 |
66 | *若有必要,可以 `git push -f` 强行推送 rebase 后的分支到自己的 GitHub `fork`*
67 |
68 | ### 注意事项
69 |
70 | * 若对上述流程有任何不清楚的地方,请查阅 GIT 教程,如 [这个](http://backlogtool.com/git-guide/cn/);
71 | * 对于代码**不同方面**的修改,请在自己 `fork` 的项目中**创建不同的分支**(原因参见`完整流程`第9条备注部分);
72 | * 变基及交互式变基操作参见 [Git 交互式变基](http://pakchoi.me/2015/03/17/git-interactive-rebase/)
73 |
74 | ## 推荐资源
75 |
76 | ### 开发环境
77 |
78 | * XAMPP for Windows 5.5.x
79 | * WampServer (for Windows)
80 | * upupw Apache PHP5.4 ( for Windows)
81 |
82 | 或自行安装
83 |
84 | - Apache / Nginx
85 | - PHP 5.4 ~ 5.6
86 | - MySQL / MariaDB
87 |
88 | *Windows 用户推荐添加 PHP bin 目录到 PATH,方便使用 composer*
89 |
90 | *Linux 用户自行配置环境, Mac 用户推荐使用内嵌 Apache 配合 Homebrew 安装 PHP 和 MariaDB*
91 |
92 | ### 编辑器
93 |
94 | Sublime Text 3 + phpfmt 插件
95 |
96 | phpfmt 插件参数
97 |
98 | ```json
99 | {
100 | "enable_auto_align": true,
101 | "indent_with_space": true,
102 | "psr1_naming": true,
103 | "psr2": true,
104 | "version": 1
105 | }
106 | ```
107 |
108 | 或其他 编辑器 / IDE 配合 PSR2 自动格式化工具
109 |
110 | ### Git GUI
111 |
112 | * SourceTree
113 | * GitHub Desktop
114 |
115 | 或其他 Git 图形界面客户端
116 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # LWL API
2 | 本项目目前已停止开源版本更新
3 |
--------------------------------------------------------------------------------
/application/build.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 | // $Id$
12 |
13 | return [
14 | // 生成运行时目录
15 | '__dir__' => ['runtime/cache', 'runtime/log', 'runtime/temp', 'runtime/template'],
16 | '__file__' => ['common.php'],
17 |
18 | // 定义index模块的自动生成
19 | 'music' => [
20 | 'controller' => ['Netease', 'Xiami'],
21 | ],
22 | 'img' => [
23 | 'controller' => ['Proxy', 'Qrcode'],
24 | ],
25 | 'hitokoto' => [
26 | 'controller' => ['Get', 'Add'],
27 | ],
28 | 'stats' => [
29 | 'controller' => ['Program'],
30 | ],
31 |
32 | // 。。。 其他更多的模块定义
33 | ];
34 |
--------------------------------------------------------------------------------
/application/common.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 | // $Id$
12 |
13 | return [
14 | 'url_route_on' => true,
15 | 'DEFAULT_TIMEZONE' => 'Asia/Shanghai',
16 | ];
17 |
--------------------------------------------------------------------------------
/application/database.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 | // $Id$
12 |
13 | return [
14 | // 数据库类型
15 | 'type' => 'mysql',
16 | // 数据库连接DSN配置
17 | 'dsn' => '',
18 | // 服务器地址
19 | 'hostname' => '',
20 | //'hostname' => 'localhost',
21 | // 数据库名
22 | 'database' => 'lwl_api',
23 | // 数据库用户名
24 | 'username' => '',
25 | // 数据库密码
26 | 'password' => '',
27 | // 数据库连接端口
28 | 'hostport' => '3306',
29 | // 数据库连接参数
30 | 'params' => [],
31 | // 数据库编码默认采用utf8
32 | 'charset' => 'utf8',
33 | // 数据库表前缀
34 | 'prefix' => '',
35 | // 数据库调试模式
36 | 'debug' => false,
37 | // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
38 | 'deploy' => 0,
39 | // 数据库读写是否分离 主从式有效
40 | 'rw_separate' => false,
41 | // 读写分离后 主服务器数量
42 | 'master_num' => 1,
43 | // 指定从服务器序号
44 | 'slave_no' => '',
45 | ];
46 |
--------------------------------------------------------------------------------
/application/hitokoto/config.php:
--------------------------------------------------------------------------------
1 | [
4 | // 'type' => 'redis',
5 | // 'prefix' => 'Api_Hitokoto_',
6 | // 'expire' => 0,
7 | // 'REDIS_HOST'=>'127.0.0.1',
8 | // 'REDIS_PORT'=>'6379',
9 | // ],
10 | ];
11 |
--------------------------------------------------------------------------------
/application/hitokoto/controller/Add.php:
--------------------------------------------------------------------------------
1 | connect('127.0.0.1',6379);
14 | $hitokoto_num = $redis->get('Api_hitokoto_num');
15 | if (empty($hitokoto_num)) {
16 | header('X-reload: reload');
17 | $Model = M();
18 | $all_hitokoto = $Model->query('select * from hitokoto');
19 | foreach ($all_hitokoto as $toredis) {
20 | $redis->set("Api_hitokoto_" . $toredis['id'],$toredis['hitokoto']);
21 | }
22 | $redis->set('Api_hitokoto_num', count($all_hitokoto));
23 | $hitokoto_num = $redis->get('Api_hitokoto_num');
24 | }
25 | $hitokoto = $redis->get("Api_hitokoto_" . mt_rand(0, $hitokoto_num));
26 |
27 | //开始输出
28 | if (isset($_GET["charset"])) {
29 | if ($_GET["charset"] == "gbk") {
30 | header("Content-type: text/html; charset=gbk");
31 | $hitokoto = iconv("UTF-8", "GBK", $hitokoto);
32 | if (!isset($_GET["encode"])) {
33 | echo $hitokoto;
34 | exit();
35 | }
36 | if ($_GET["encode"] == "js") {
37 | header('Content-type: application/x-javascript');
38 | echo "function lwlhitokoto(){document.write(\"" . $hitokoto . "\");}";
39 | exit();
40 | } else if ($_GET["encode"] == "json") {
41 | header('Content-type: application/json');
42 | echo 'echokoto(' . json_encode(array('code' => 200, 'hitokoto' => $hitokoto)) . ');';
43 | exit();
44 | } else {
45 | echo $hitokoto;
46 | exit();
47 | }
48 | } else {
49 | header("Content-type: text/html; charset=utf-8");
50 | if (!isset($_GET["encode"])) {
51 | echo $hitokoto;
52 | exit();
53 | }
54 | if ($_GET["encode"] == "js") {
55 | header('Content-type: application/x-javascript');
56 | echo "function lwlhitokoto(){document.write(\"" . $hitokoto . "\");}";
57 | exit();
58 | } else if ($_GET["encode"] == "json") {
59 | header('Content-type: application/json');
60 | echo 'echokoto(' . json_encode(array('code' => 200, 'hitokoto' => $hitokoto)) . ');';
61 | exit();
62 | } else {
63 | echo $hitokoto;
64 | exit();
65 | }
66 | }
67 | }
68 | header("Content-type: text/html; charset=utf-8");
69 | if (!isset($_GET["encode"])) {
70 | echo $hitokoto;
71 | exit();
72 | }
73 | if ($_GET["encode"] == "js") {
74 | header('Content-type: application/x-javascript');
75 | echo "function lwlhitokoto(){document.write(\"" . $hitokoto . "\");}";
76 | exit();
77 | } else if ($_GET["encode"] == "json") {
78 | header('Content-type: application/json');
79 | echo 'echokoto(' . json_encode(array('code' => 200, 'hitokoto' => $hitokoto)) . ');';
80 | exit();
81 | } else {
82 | echo $hitokoto;
83 | exit();
84 | }
85 |
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/application/img/config.php:
--------------------------------------------------------------------------------
1 | [
4 | 'type' => 'memcache',
5 | 'prefix' => 'Api_Img_',
6 | 'expire' => 2592000,
7 | ],
8 | ];
9 |
--------------------------------------------------------------------------------
/application/img/controller/Index.php:
--------------------------------------------------------------------------------
1 | *{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px }
:)
欢迎使用 LWL API服务!
此为新API测试地址 /w\正在努力重构代码';
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/application/music/config.php:
--------------------------------------------------------------------------------
1 | 400,
11 | 'msg' => 'Parameter songid is missing',
12 | );
13 | return json_encode($return);
14 | }
15 | $Netease = A('Netease', 'event');
16 | if (($getMP3 = $Netease->getMP3(intval($_GET["id"]))) == false) {
17 | $return = array(
18 | 'code' => 501,
19 | 'msg' => 'Invalid song or Netease server error',
20 | );
21 | return json_encode($return);
22 | } else {
23 | Header("Location: " . $getMP3['url']);
24 | return true;
25 | }
26 | }
27 |
28 | public function pic()
29 | {
30 | if (empty($_GET["id"])) {
31 | $return = array(
32 | 'code' => 400,
33 | 'msg' => 'Parameter songid is missing',
34 | );
35 | return json_encode($return);
36 | }
37 | $Netease = A('Netease', 'event');
38 | if (($songinfo = $Netease->SongInfo(intval($_GET["id"]))) == false) {
39 | $return = array(
40 | 'code' => 501,
41 | 'msg' => 'Invalid song or Netease server error',
42 | );
43 | return json_encode($return);
44 | } else {
45 | Header("Location: " . $songinfo['album']['picUrl']);
46 | return true;
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/application/music/controller/Xiami.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 | // $Id$
12 |
13 | return [
14 | '__pattern__' => [
15 | 'name' => '\w+',
16 | ],
17 | '[hello]' => [
18 | ':id' => ['index/hello', ['method' => 'get'], ['id' => '\d+']],
19 | ':name' => ['index/hello', ['method' => 'post']],
20 | ],
21 |
22 | ];
23 |
--------------------------------------------------------------------------------
/application/stats/config.php:
--------------------------------------------------------------------------------
1 | *{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px }
';
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/application/stats/controller/Program.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 | // $Id$
12 |
13 | return [
14 | // 生成运行时目录
15 | '__dir__' => ['runtime/cache', 'runtime/log', 'runtime/temp', 'runtime/template'],
16 | '__file__' => ['common.php'],
17 |
18 | // 定义index模块的自动生成
19 | 'index' => [
20 | '__file__' => ['common.php'],
21 | '__dir__' => ['behavior', 'controller', 'model', 'view'],
22 | 'controller' => ['Index', 'Test', 'UserType'],
23 | 'model' => [],
24 | 'view' => ['index/index'],
25 | ],
26 | // 。。。 其他更多的模块定义
27 | ];
28 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "topthink/think",
3 | "description": "the new thinkphp framework",
4 | "type": "project",
5 | "keywords": ["framework", "thinkphp", "ORM"],
6 | "homepage": "http://thinkphp.cn/",
7 | "license": "Apache2",
8 | "authors": [
9 | {
10 | "name": "liu21st",
11 | "email": "liu21st@gmail.com"
12 | }
13 | ],
14 | "require": {
15 | "php": ">=5.4.0"
16 | },
17 | "require-dev": {
18 | "johnkary/phpunit-speedtrap": "^1.0",
19 | "mikey179/vfsStream": "~1.6",
20 | "phploc/phploc": "*",
21 | "phpunit/phpunit": "4.8.*",
22 | "sebastian/phpcpd": "*",
23 | "squizlabs/php_codesniffer": "2.*"
24 | },
25 | "config": {
26 | "vendor-dir": "thinkphp/vendor"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/console:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 |
11 | // +----------------------------------------------------------------------
12 |
13 | // 定义项目路径
14 | define('APP_PATH', './application/');
15 |
16 | define('APP_MODE', 'console');
17 |
18 | define('APP_DEBUG',true);
19 | // 加载框架引导文件
20 | require './thinkphp/start.php';
21 |
22 | $console = new \think\Console('Think Console', '0.1');
23 |
24 | $commands = \think\Config::get('commands');
25 |
26 | if (is_array($commands)) {
27 | foreach ($commands as $command) {
28 | if (class_exists($command) && $command instanceof \think\console\command\Command) {
29 | $console->add(new $command());
30 | }
31 | }
32 | }
33 |
34 | $console->run();
--------------------------------------------------------------------------------
/lwl_api_数据库文件.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lwl12/LWL-API/3b6fd88a58ec60fc8cc9587939e55bcb45431ce9/lwl_api_数据库文件.zip
--------------------------------------------------------------------------------
/public/.htaccess:
--------------------------------------------------------------------------------
1 |
2 | Options +FollowSymlinks
3 | RewriteEngine On
4 |
5 | RewriteCond %{REQUEST_FILENAME} !-d
6 | RewriteCond %{REQUEST_FILENAME} !-f
7 | RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
8 |
--------------------------------------------------------------------------------
/public/dsavatar/index.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
Error - 403
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
LWL的自由天空
15 |
16 |
System Error - 403
17 |
Forbidden
18 |
禁止访问-服务器已经理解请求,但是拒绝执行它。
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/public/errpage/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
Error - 404
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
LWL的自由天空
15 |
16 |
System Error - 404
17 |
Not Found
18 |
请求失败,请求所希望得到的资源未被在服务器上发现。
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/public/errpage/451.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
Error - 451
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
LWL的自由天空
15 |
16 |
Network Error - 451
17 |
Forbidden (Political)
18 |
禁止访问-根据相关政策与法律法规,部分内容不予显示。
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/public/errpage/500.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
Error - 500
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
LWL的自由天空
15 |
16 |
Server Error - 500
17 |
Internal Server Error
18 |
服务器遇到了一个未曾预料的状况,导致无法完成对请求的处理。
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/public/errpage/502.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
Error - 502
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
LWL的自由天空
15 |
16 |
Server Error - 502
17 |
Bad Gateway
18 |
作为网关或者代理工作的服务器尝试执行请求时,从上游服务器接收到无效的响应。
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/public/errpage/503.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
Error - 503
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
LWL的自由天空
15 |
16 |
Server Error - 503
17 |
Bad Gateway
18 |
由于临时的服务器维护或者过载,服务器当前无法处理请求。这个状况是临时的,并且将在一段时间以后恢复。
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/public/errpage/Maintain.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
Error - 正在维护
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
LWL的自由天空
15 |
16 |
Server Error - Maintenance
17 |
正在维护
18 |
由于临时的站点维护,LWL的自由天空 当前无法处理请求。这个状况是临时的,并且将在一段时间以后恢复。
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/public/errpage/error.css:
--------------------------------------------------------------------------------
1 | html,body{width:100%;height:100%;cursor:default}
2 | html,body,p,h2,div{margin:0;padding:0}
3 | body{background:#99D19C;text-align:center;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none}
4 | html{font:12px "Segoe UI","Microsoft YaHei",FreeSans,Arimo,"Droid Sans","Hiragino Sans GB","Hiragino Sans GB W3",Arial,sans-serif}
5 | h2{margin-bottom:25px;font-size:30px;font-weight:300;color:#e05d6f}
6 | p{line-height:1.5em;font-size:12px;color:#95a2a9;margin-bottom:5px}
7 | .title{position:relative;top:75px;margin-bottom:.7em;line-height:30px;font-size:26px;font-weight:300;color:#fff;text-shadow:0 0 4px #666666}
8 | .box{position:relative;top:80px;width:600px;max-width:85%;margin:0 auto;background:#fff;padding:15px;box-shadow:0 0 50px #5D916B}
9 | .main{font-size:18px;color:#000;font-weight:500;line-height:1.7em;margin:0 0 10px}
10 | .foot{position:relative;top:80px;margin:15px 15px 0;font-size:12px;color:#5D916B}
11 | pre{font-family: Microsoft YaHei, Tahoma, Helvetica, Arial, "\5b8b\4f53", sans-serif;background:#7CB4B8;color:#ffffff;padding:15px 20px;margin:25px -15px -15px;line-height:1.4em;font-size:14px;text-align:left;word-break:break-all;white-space:pre-wrap}
12 | .main,pre{user-select:text;-webkit-user-select:text;-moz-user-select:text;-ms-user-select:text;cursor:text}
13 | ::selection{background:rgba(78,176,248,0.3)}
14 | pre::selection{background:rgba(255,255,255,0.99);color:#3498DB}
--------------------------------------------------------------------------------
/public/hitokoto/index.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | // 应用入口文件
13 |
14 | // 定义项目路径
15 | define('APP_PATH', dirname(__DIR__) . '/application/');
16 | // 开启调试模式
17 | define('APP_DEBUG', true);
18 | //发送头部信息
19 | header('X-Powered-By:Liwanglin12 API (api.lwl12.com)');
20 | //自动生成
21 | //define('APP_AUTO_BUILD', true);
22 | // 加载框架引导文件
23 | require __DIR__ . '/../thinkphp/start.php';
24 | // 执行应用
25 | \think\App::run();
26 |
--------------------------------------------------------------------------------
/public/qrcode/index.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 | // $Id$
12 |
13 | if (file_exists($_SERVER["DOCUMENT_ROOT"] . $_SERVER["REQUEST_URI"])) {
14 | return false;
15 | } else {
16 | require "index.php";
17 | }
--------------------------------------------------------------------------------
/public/static/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/public/wordpress/plugin/wpplus/index.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | // 开始运行时间和内存使用
13 | define('START_TIME', microtime(true));
14 | define('START_MEM', memory_get_usage());
15 | // 版本信息
16 | define('THINK_VERSION', '5.0.0 RC1');
17 | // 系统常量
18 | defined('DS') or define('DS', DIRECTORY_SEPARATOR);
19 | defined('THINK_PATH') or define('THINK_PATH', dirname(__FILE__) . DS);
20 | defined('LIB_PATH') or define('LIB_PATH', THINK_PATH . 'library' . DS);
21 | defined('EXTEND_PATH') or define('EXTEND_PATH', THINK_PATH . 'extend' . DS);
22 | defined('MODE_PATH') or define('MODE_PATH', THINK_PATH . 'mode' . DS); // 系统应用模式目录
23 | defined('CORE_PATH') or define('CORE_PATH', LIB_PATH . 'think' . DS);
24 | defined('ORG_PATH') or define('ORG_PATH', LIB_PATH . 'org' . DS);
25 | defined('TRAIT_PATH') or define('TRAIT_PATH', LIB_PATH . 'traits' . DS);
26 | defined('APP_PATH') or define('APP_PATH', dirname($_SERVER['SCRIPT_FILENAME']) . DS);
27 | defined('APP_NAMESPACE') or define('APP_NAMESPACE', 'app');
28 | defined('COMMON_MODULE') or define('COMMON_MODULE', 'common');
29 | defined('RUNTIME_PATH') or define('RUNTIME_PATH', realpath(APP_PATH) . DS . 'runtime' . DS);
30 | defined('DATA_PATH') or define('DATA_PATH', RUNTIME_PATH . 'data' . DS);
31 | defined('LOG_PATH') or define('LOG_PATH', RUNTIME_PATH . 'log' . DS);
32 | defined('CACHE_PATH') or define('CACHE_PATH', RUNTIME_PATH . 'cache' . DS);
33 | defined('TEMP_PATH') or define('TEMP_PATH', RUNTIME_PATH . 'temp' . DS);
34 | defined('VENDOR_PATH') or define('VENDOR_PATH', THINK_PATH . 'vendor' . DS);
35 | defined('EXT') or define('EXT', '.php');
36 | defined('MODEL_LAYER') or define('MODEL_LAYER', 'model');
37 | defined('VIEW_LAYER') or define('VIEW_LAYER', 'view');
38 | defined('CONTROLLER_LAYER') or define('CONTROLLER_LAYER', 'controller');
39 | defined('APP_MULTI_MODULE') or define('APP_MULTI_MODULE', true); // 是否多模块
40 | defined('APP_DEBUG') or define('APP_DEBUG', false); // 是否调试模式
41 | defined('APP_HOOK') or define('APP_HOOK', false); // 是否开启HOOK
42 | defined('ENV_PREFIX') or define('ENV_PREFIX', 'T_'); // 环境变量的配置前缀
43 | defined('IS_API') or define('IS_API', false); // 是否API接口
44 | defined('APP_AUTO_BUILD') or define('APP_AUTO_BUILD', false); // 是否自动生成应用模块
45 | defined('APP_AUTO_RUN') or define('APP_AUTO_RUN', false); // 是否自动运行
46 |
47 | // 应用模式 默认为普通模式
48 | defined('APP_MODE') or define('APP_MODE', function_exists('saeAutoLoader') ? 'sae' : 'common');
49 |
50 | // 环境常量
51 | define('IS_CGI', strpos(PHP_SAPI, 'cgi') === 0 ? 1 : 0);
52 | define('IS_WIN', strstr(PHP_OS, 'WIN') ? 1 : 0);
53 | define('IS_CLI', PHP_SAPI == 'cli' ? 1 : 0);
54 | define('IS_AJAX', (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') ? true : false);
55 | define('NOW_TIME', $_SERVER['REQUEST_TIME']);
56 | define('REQUEST_METHOD', IS_CLI ? 'GET' : $_SERVER['REQUEST_METHOD']);
57 | define('IS_GET', REQUEST_METHOD == 'GET' ? true : false);
58 | define('IS_POST', REQUEST_METHOD == 'POST' ? true : false);
59 | define('IS_PUT', REQUEST_METHOD == 'PUT' ? true : false);
60 | define('IS_DELETE', REQUEST_METHOD == 'DELETE' ? true : false);
61 |
--------------------------------------------------------------------------------
/thinkphp/extend/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/thinkphp/lang/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/thinkphp/library/think/Cache.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think;
13 |
14 | class Cache
15 | {
16 | protected static $instance = [];
17 | public static $readTimes = 0;
18 | public static $writeTimes = 0;
19 |
20 | /**
21 | * 操作句柄
22 | * @var object
23 | * @access protected
24 | */
25 | protected static $handler = null;
26 |
27 | /**
28 | * 连接缓存
29 | * @access public
30 | * @param array $options 配置数组
31 | * @return object
32 | */
33 | public static function connect(array $options = [])
34 | {
35 | $md5 = md5(serialize($options));
36 | if (!isset(self::$instance[$md5])) {
37 | $type = !empty($options['type']) ? $options['type'] : 'File';
38 | $class = (!empty($options['namespace']) ? $options['namespace'] : '\\think\\cache\\driver\\') . ucwords($type);
39 | unset($options['type']);
40 | self::$instance[$md5] = new $class($options);
41 | // 记录初始化信息
42 | APP_DEBUG && Log::record('[ CACHE ] INIT ' . $type . ':' . var_export($options, true), 'info');
43 | }
44 | self::$handler = self::$instance[$md5];
45 | return self::$handler;
46 | }
47 |
48 | public static function __callStatic($method, $params)
49 | {
50 | if (is_null(self::$handler)) {
51 | // 自动初始化缓存
52 | self::connect(Config::get('cache'));
53 | }
54 | return call_user_func_array([self::$handler, $method], $params);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/thinkphp/library/think/Controller.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think;
13 |
14 | T('controller/View');
15 | T('controller/Jump');
16 |
17 | class Controller
18 | {
19 | use \traits\controller\Jump;
20 | use \traits\controller\View;
21 |
22 | /**
23 | * 前置操作方法列表
24 | * @var array $beforeActionList
25 | * @access protected
26 | */
27 | protected $beforeActionList = [];
28 |
29 | /**
30 | * 架构函数
31 | * @access public
32 | */
33 | public function __construct()
34 | {
35 | // 控制器初始化
36 | if (method_exists($this, '_initialize')) {
37 | $this->_initialize();
38 | }
39 | // 前置操作方法
40 | // 支持 ['action1','action2'] 或者 ['action1'=>['only'=>'index'],'action2'=>['except'=>'login']]
41 | if ($this->beforeActionList) {
42 | foreach ($this->beforeActionList as $method => $options) {
43 | is_numeric($method) ?
44 | $this->beforeAction($options) :
45 | $this->beforeAction($method, $options);
46 | }
47 | }
48 | }
49 |
50 | /**
51 | * 前置操作
52 | * @access protected
53 | * @param string $method 前置操作方法名
54 | * @param array $options 调用参数 ['only'=>[...]] 或者['except'=>[...]]
55 | */
56 | protected function beforeAction($method, $options = [])
57 | {
58 | if (isset($options['only'])) {
59 | if (is_string($options['only'])) {
60 | $options['only'] = explode(',', $options['only']);
61 | }
62 | if (!in_array(ACTION_NAME, $options['only'])) {
63 | return;
64 | }
65 | } elseif (isset($options['except'])) {
66 | if (is_string($options['except'])) {
67 | $options['except'] = explode(',', $options['except']);
68 | }
69 | if (in_array(ACTION_NAME, $options['except'])) {
70 | return;
71 | }
72 | }
73 |
74 | if (method_exists($this, $method)) {
75 | call_user_func([$this, $method]);
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/thinkphp/library/think/Db.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think;
13 |
14 | /**
15 | * ThinkPHP 数据库中间层实现类
16 | */
17 | class Db
18 | {
19 | // 数据库连接实例
20 | private static $instances = [];
21 | // 当前数据库连接实例
22 | private static $instance = null;
23 | // 查询次数
24 | public static $queryTimes = 0;
25 | // 执行次数
26 | public static $executeTimes = 0;
27 |
28 | /**
29 | * 数据库初始化 并取得数据库类实例
30 | * @static
31 | * @access public
32 | * @param mixed $config 连接配置
33 | * @return Object 返回数据库驱动类
34 | */
35 | public static function connect($config = [])
36 | {
37 | $md5 = md5(serialize($config));
38 | if (!isset(self::$instances[$md5])) {
39 | // 解析连接参数 支持数组和字符串
40 | $options = self::parseConfig($config);
41 | if (empty($options['type'])) {
42 | throw new Exception('db type error');
43 | }
44 | $class = (!empty($options['namespace']) ? $options['namespace'] : '\\think\\db\\driver\\') . ucwords($options['type']);
45 | self::$instances[$md5] = new $class($options);
46 | // 记录初始化信息
47 | APP_DEBUG && Log::record('[ DB ] INIT ' . $options['type'] . ':' . var_export($options, true), 'info');
48 | }
49 | self::$instance = self::$instances[$md5];
50 | return self::$instance;
51 | }
52 |
53 | /**
54 | * 数据库连接参数解析
55 | * @static
56 | * @access private
57 | * @param mixed $config
58 | * @return array
59 | */
60 | private static function parseConfig($config)
61 | {
62 | if (empty($config)) {
63 | $config = Config::get('database');
64 | if (Config::get('use_db_switch')) {
65 | $status = Config::get('app_status');
66 | $config = $config[$status ?: 'default'];
67 | }
68 | } elseif (is_string($config) && false === strpos($config, '/')) {
69 | // 支持读取配置参数
70 | $config = Config::get($config);
71 | }
72 | if (is_string($config)) {
73 | return self::parseDsn($config);
74 | } else {
75 | return $config;
76 | }
77 | }
78 |
79 | /**
80 | * DSN解析
81 | * 格式: mysql://username:passwd@localhost:3306/DbName?param1=val1¶m2=val2#utf8
82 | * @static
83 | * @access private
84 | * @param string $dsnStr
85 | * @return array
86 | */
87 | private static function parseDsn($dsnStr)
88 | {
89 | $info = parse_url($dsnStr);
90 | if (!$info) {
91 | return [];
92 | }
93 | $dsn = [
94 | 'type' => $info['scheme'],
95 | 'username' => isset($info['user']) ? $info['user'] : '',
96 | 'password' => isset($info['pass']) ? $info['pass'] : '',
97 | 'hostname' => isset($info['host']) ? $info['host'] : '',
98 | 'hostport' => isset($info['port']) ? $info['port'] : '',
99 | 'database' => !empty($info['path']) ? ltrim($info['path'], '/') : '',
100 | 'charset' => isset($info['fragment']) ? $info['fragment'] : 'utf8',
101 | ];
102 |
103 | if (isset($info['query'])) {
104 | parse_str($info['query'], $dsn['params']);
105 | } else {
106 | $dsn['params'] = [];
107 | }
108 | return $dsn;
109 | }
110 |
111 | // 调用驱动类的方法
112 | public static function __callStatic($method, $params)
113 | {
114 | if (is_null(self::$instance)) {
115 | // 自动初始化数据库
116 | self::connect();
117 | }
118 | return call_user_func_array([self::$instance, $method], $params);
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/thinkphp/library/think/Exception.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think;
13 |
14 | /**
15 | * ThinkPHP核心异常类
16 | * 所有系统异常必须继承该类
17 | */
18 | class Exception extends \Exception
19 | {
20 | /**
21 | * 系统异常后发送给客户端的HTTP Status
22 | * @var integer
23 | */
24 | protected $httpStatus = 500;
25 |
26 | /**
27 | * 保存异常页面显示的额外Debug数据
28 | * @var array
29 | */
30 | protected $data = [];
31 |
32 | /**
33 | * 设置异常额外的Debug数据
34 | * 数据将会显示为下面的格式
35 | *
36 | * Exception Data
37 | * --------------------------------------------------
38 | * Label 1
39 | * key1 value1
40 | * key2 value2
41 | * Label 2
42 | * key1 value1
43 | * key2 value2
44 | *
45 | * @param string $label 数据分类,用于异常页面显示
46 | * @param Array $data 需要显示的数据,必须为关联数组
47 | */
48 | final protected function setData($label, array $data)
49 | {
50 | $this->data[$label] = $data;
51 | }
52 |
53 | /**
54 | * 获取异常额外Debug数据
55 | * 主要用于输出到异常页面便于调试
56 | * @return array 由setData设置的Debug数据
57 | */
58 | final public function getData()
59 | {
60 | return $this->data;
61 | }
62 |
63 | /**
64 | * 获取要发送给客户端的HTTP Status
65 | * @return integer HTTP Status
66 | */
67 | final public function getHttpStatus()
68 | {
69 | return $this->httpStatus;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/thinkphp/library/think/Log.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think;
13 |
14 | class Log
15 | {
16 | const LOG = 'log';
17 | const ERROR = 'error';
18 | const INFO = 'info';
19 | const SQL = 'sql';
20 | const NOTICE = 'notice';
21 | const ALERT = 'alert';
22 |
23 | // 日志信息
24 | protected static $log = [];
25 | // 日志类型
26 | protected static $type = ['log', 'error', 'info', 'sql', 'notice', 'alert'];
27 | // 日志写入驱动
28 | protected static $driver = null;
29 | // 通知发送驱动
30 | protected static $alarm = null;
31 |
32 | // 日志初始化
33 | public static function init($config = [])
34 | {
35 | $type = isset($config['type']) ? $config['type'] : 'File';
36 | $class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\log\\driver\\') . ucwords($type);
37 | unset($config['type']);
38 | self::$driver = new $class($config);
39 | // 记录初始化信息
40 | APP_DEBUG && Log::record('[ LOG ] INIT ' . $type . ': ' . var_export($config, true), 'info');
41 | }
42 |
43 | // 通知初始化
44 | public static function alarm($config = [])
45 | {
46 | $type = isset($config['type']) ? $config['type'] : 'Email';
47 | $class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\log\\alarm\\') . ucwords($type);
48 | unset($config['type']);
49 | self::$alarm = new $class($config['alarm']);
50 | // 记录初始化信息
51 | APP_DEBUG && Log::record('[ CACHE ] ALARM ' . $type . ': ' . var_export($config, true), 'info');
52 | }
53 |
54 | /**
55 | * 获取全部日志信息
56 | * @return array
57 | */
58 | public static function getLog()
59 | {
60 | return self::$log;
61 | }
62 |
63 | /**
64 | * 记录调试信息
65 | * @param mixed $msg 调试信息
66 | * @param string $type 信息类型
67 | * @return void
68 | */
69 | public static function record($msg, $type = 'log')
70 | {
71 | if (!is_string($msg)) {
72 | $msg = var_export($msg, true);
73 | }
74 | self::$log[] = ['type' => $type, 'msg' => $msg];
75 | }
76 |
77 | /**
78 | * 保存调试信息
79 | * @return void
80 | */
81 | public static function save()
82 | {
83 | if (is_null(self::$driver)) {
84 | self::init(Config::get('log'));
85 | }
86 | self::$driver->save(self::$log);
87 | }
88 |
89 | /**
90 | * 实时写入日志信息 并支持行为
91 | * @param mixed $msg 调试信息
92 | * @param string $type 信息类型
93 | * @return void
94 | */
95 | public static function write($msg, $type = 'log')
96 | {
97 | if (!is_string($msg)) {
98 | $msg = var_export($msg, true);
99 | }
100 | // 封装日志信息
101 | $log[] = ['type' => $type, 'msg' => $msg];
102 |
103 | // 监听log_write
104 | APP_HOOK && Hook::listen('log_write', $log);
105 | if (is_null(self::$driver)) {
106 | self::init(Config::get('log'));
107 | }
108 | // 写入日志
109 | self::$driver->save($log);
110 | }
111 |
112 | /**
113 | * 发送预警通知
114 | * @param mixed $msg 调试信息
115 | * @return void
116 | */
117 | public static function send($msg)
118 | {
119 | self::$alarm && self::$alarm->send($msg);
120 | }
121 |
122 | // 静态调用
123 | public static function __callStatic($method, $args)
124 | {
125 | if (in_array($method, self::$type)) {
126 | array_push($args, $method);
127 | return call_user_func_array('\\think\\Log::record', $args);
128 | }
129 | }
130 |
131 | }
132 |
--------------------------------------------------------------------------------
/thinkphp/library/think/ORM.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think;
13 |
14 | class ORM
15 | {
16 | protected static $instance = [];
17 | protected static $config = [];
18 |
19 | /**
20 | * 设置数据对象的值
21 | * @access public
22 | * @param string $name 名称
23 | * @param mixed $value 值
24 | * @return void
25 | */
26 | public function __set($name, $value)
27 | {
28 | self::__callStatic('__set', [$name, $value]);
29 | }
30 |
31 | /**
32 | * 获取数据对象的值
33 | * @access public
34 | * @param string $name 名称
35 | * @return mixed
36 | */
37 | public function __get($name)
38 | {
39 | return self::__callStatic('__get', [$name]);
40 | }
41 |
42 | /**
43 | * 检测数据对象的值
44 | * @access public
45 | * @param string $name 名称
46 | * @return boolean
47 | */
48 | public function __isset($name)
49 | {
50 | return self::__callStatic('__isset', [$name]);
51 | }
52 |
53 | /**
54 | * 销毁数据对象的值
55 | * @access public
56 | * @param string $name 名称
57 | * @return void
58 | */
59 | public function __unset($name)
60 | {
61 | self::__callStatic('__unset', [$name]);
62 | }
63 |
64 | public function __call($method, $params)
65 | {
66 | return self::__callStatic($method, $params);
67 | }
68 |
69 | public static function __callStatic($method, $params)
70 | {
71 | $name = basename(str_replace('\\', '/', get_called_class()));
72 | if (!isset(self::$instance[$name])) {
73 | // 自动实例化模型类
74 | self::$instance[$name] = new \think\Model($name, static::$config);
75 | }
76 | return call_user_func_array([self::$instance[$name], $method], $params);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/thinkphp/library/think/cache/driver/Apc.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\cache\driver;
13 |
14 | use think\Cache;
15 | use think\Exception;
16 |
17 | /**
18 | * Apc缓存驱动
19 | * @author liu21st
20 | */
21 | class Apc
22 | {
23 |
24 | protected $options = [
25 | 'expire' => 0,
26 | 'prefix' => '',
27 | 'length' => 0,
28 | ];
29 | /*****************************
30 | 需要支持apc_cli模式
31 | ******************************/
32 | /**
33 | * 架构函数
34 | * @param array $options 缓存参数
35 | * @throws Exception
36 | * @access public
37 | */
38 | public function __construct($options = [])
39 | {
40 | if (!function_exists('apc_cache_info')) {
41 | throw new Exception('_NOT_SUPPERT_:Apc');
42 | }
43 | if (!empty($options)) {
44 | $this->options = array_merge($this->options, $options);
45 | }
46 | }
47 |
48 | /**
49 | * 读取缓存
50 | * @access public
51 | * @param string $name 缓存变量名
52 | * @return mixed
53 | */
54 | public function get($name)
55 | {
56 | Cache::$readTimes++;
57 | return apc_fetch($this->options['prefix'] . $name);
58 | }
59 |
60 | /**
61 | * 写入缓存
62 | * @access public
63 | * @param string $name 缓存变量名
64 | * @param mixed $value 存储数据
65 | * @param integer $expire 有效时间(秒)
66 | * @return bool
67 | */
68 | public function set($name, $value, $expire = null)
69 | {
70 | Cache::$writeTimes++;
71 | if (is_null($expire)) {
72 | $expire = $this->options['expire'];
73 | }
74 | $name = $this->options['prefix'] . $name;
75 | if ($result = apc_store($name, $value, $expire)) {
76 | if ($this->options['length'] > 0) {
77 | // 记录缓存队列
78 | $queue = apc_fetch('__info__');
79 | if (!$queue) {
80 | $queue = [];
81 | }
82 | if (false === array_search($name, $queue)) {
83 | array_push($queue, $name);
84 | }
85 |
86 | if (count($queue) > $this->options['length']) {
87 | // 出列
88 | $key = array_shift($queue);
89 | // 删除缓存
90 | apc_delete($key);
91 | }
92 | apc_store('__info__', $queue);
93 | }
94 | }
95 | return $result;
96 | }
97 |
98 | /**
99 | * 删除缓存
100 | * @access public
101 | * @param string $name 缓存变量名
102 | * @return bool|\string[]
103 | */
104 | public function rm($name)
105 | {
106 | return apc_delete($this->options['prefix'] . $name);
107 | }
108 |
109 | /**
110 | * 清除缓存
111 | * @access public
112 | * @return bool
113 | */
114 | public function clear()
115 | {
116 | return apc_clear_cache('user');
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/thinkphp/library/think/cache/driver/Lite.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\cache\driver;
13 |
14 | use think\Cache;
15 |
16 | /**
17 | * 文件类型缓存类
18 | * @author liu21st
19 | */
20 | class Lite
21 | {
22 | protected $options = [
23 | 'prefix' => '',
24 | 'path' => '',
25 | 'expire' => 0, // 等于 10*365*24*3600(10年)
26 | ];
27 |
28 | /**
29 | * 架构函数
30 | * @access public
31 | *
32 | * @param array $options
33 | */
34 | public function __construct($options = [])
35 | {
36 | if (!empty($options)) {
37 | $this->options = array_merge($this->options, $options);
38 | }
39 | if (substr($this->options['path'], -1) != '/') {
40 | $this->options['path'] .= '/';
41 | }
42 |
43 | }
44 |
45 | /**
46 | * 取得变量的存储文件名
47 | * @access private
48 | * @param string $name 缓存变量名
49 | * @return string
50 | */
51 | private function filename($name)
52 | {
53 | return $this->options['path'] . $this->options['prefix'] . md5($name) . '.php';
54 | }
55 |
56 | /**
57 | * 读取缓存
58 | * @access public
59 | * @param string $name 缓存变量名
60 | * @return mixed
61 | */
62 | public function get($name)
63 | {
64 | Cache::$readTimes++;
65 | $filename = $this->filename($name);
66 | if (is_file($filename)) {
67 | // 判断是否过期
68 | $mtime = filemtime($filename);
69 | if ($mtime < time()) {
70 | // 清除已经过期的文件
71 | unlink($filename);
72 | return false;
73 | }
74 | return include $filename;
75 | } else {
76 | return false;
77 | }
78 | }
79 |
80 | /**
81 | * 写入缓存
82 | * @access public
83 | * @param string $name 缓存变量名
84 | * @param mixed $value 存储数据
85 | * @internal param int $expire 有效时间 0为永久
86 | * @return bool
87 | */
88 | public function set($name, $value, $expire = null)
89 | {
90 | Cache::$writeTimes++;
91 | if (is_null($expire)) {
92 | $expire = $this->options['expire'];
93 | }
94 | // 模拟永久
95 | if (0 === $expire) {
96 | $expire = 10 * 365 * 24 * 3600;
97 | }
98 | $filename = $this->filename($name);
99 | // 缓存数据
100 | /*
101 | $dir = dirname($filename);
102 | // 目录不存在则创建
103 | if (!is_dir($dir))
104 | mkdir($dir,0755,true);
105 | */
106 | $ret = file_put_contents($filename, ("filename($name));
123 | }
124 |
125 | /**
126 | * 清除缓存
127 | * @access public
128 | * @return bool
129 | * @internal param string $name 缓存变量名
130 | */
131 | public function clear()
132 | {
133 | $filename = $this->filename('*');
134 | array_map("unlink", glob($filename));
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/thinkphp/library/think/cache/driver/Test.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\cache\driver;
13 |
14 | use think\Cache;
15 |
16 | /**
17 | * 测试缓存类
18 | * @author liu21st
19 | */
20 | class Test
21 | {
22 |
23 | /**
24 | * 读取缓存
25 | * @access public
26 | * @param string $name 缓存变量名
27 | * @return mixed
28 | */
29 | public function get($name)
30 | {
31 | return false;
32 | }
33 |
34 | /**
35 | * 写入缓存
36 | * @access public
37 | * @param string $name 缓存变量名
38 | * @param mixed $value 存储数据
39 | * @param int $expire 有效时间 0为永久
40 | * @return boolean
41 | */
42 | public function set($name, $value, $expire = null)
43 | {
44 | return true;
45 | }
46 |
47 | /**
48 | * 删除缓存
49 | * @access public
50 | * @param string $name 缓存变量名
51 | * @return boolean
52 | */
53 | public function rm($name)
54 | {
55 | return true;
56 | }
57 |
58 | /**
59 | * 清除缓存
60 | * @access public
61 | * @return boolean
62 | */
63 | public function clear()
64 | {
65 | return true;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/thinkphp/library/think/cache/driver/Wincache.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\cache\driver;
13 |
14 | use think\Cache;
15 | use think\Exception;
16 |
17 | /**
18 | * Wincache缓存驱动
19 | * @author liu21st
20 | */
21 | class Wincache
22 | {
23 |
24 | protected $options = [
25 | 'prefix' => '',
26 | 'expire' => 0,
27 | 'length' => 0,
28 | ];
29 |
30 | /**
31 | * 架构函数
32 | * @param array $options 缓存参数
33 | * @throws Exception
34 | * @access public
35 | */
36 | public function __construct($options = [])
37 | {
38 | if (!function_exists('wincache_ucache_info')) {
39 | throw new Exception('_NOT_SUPPERT_:WinCache');
40 | }
41 | if (!empty($options)) {
42 | $this->options = array_merge($this->options, $options);
43 | }
44 | }
45 |
46 | /**
47 | * 读取缓存
48 | * @access public
49 | * @param string $name 缓存变量名
50 | * @return mixed
51 | */
52 | public function get($name)
53 | {
54 | Cache::$readTimes++;
55 | $name = $this->options['prefix'] . $name;
56 | return wincache_ucache_exists($name) ? wincache_ucache_get($name) : false;
57 | }
58 |
59 | /**
60 | * 写入缓存
61 | * @access public
62 | * @param string $name 缓存变量名
63 | * @param mixed $value 存储数据
64 | * @param integer $expire 有效时间(秒)
65 | * @return boolean
66 | */
67 | public function set($name, $value, $expire = null)
68 | {
69 | Cache::$writeTimes++;
70 | if (is_null($expire)) {
71 | $expire = $this->options['expire'];
72 | }
73 | $name = $this->options['prefix'] . $name;
74 | if (wincache_ucache_set($name, $value, $expire)) {
75 | if ($this->options['length'] > 0) {
76 | // 记录缓存队列
77 | $queue = wincache_ucache_get('__info__');
78 | if (!$queue) {
79 | $queue = [];
80 | }
81 | if (false === array_search($name, $queue)) {
82 | array_push($queue, $name);
83 | }
84 |
85 | if (count($queue) > $this->options['length']) {
86 | // 出列
87 | $key = array_shift($queue);
88 | // 删除缓存
89 | wincache_ucache_delete($key);
90 | }
91 | wincache_ucache_set('__info__', $queue);
92 | }
93 | return true;
94 | }
95 | return false;
96 | }
97 |
98 | /**
99 | * 删除缓存
100 | * @access public
101 | * @param string $name 缓存变量名
102 | * @return boolean
103 | */
104 | public function rm($name)
105 | {
106 | return wincache_ucache_delete($this->options['prefix'] . $name);
107 | }
108 |
109 | /**
110 | * 清除缓存
111 | * @access public
112 | * @return boolean
113 | */
114 | public function clear()
115 | {
116 | return;
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/thinkphp/library/think/cache/driver/Xcache.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\cache\driver;
13 |
14 | use think\Cache;
15 | use think\Exception;
16 |
17 | /**
18 | * Xcache缓存驱动
19 | * @author liu21st
20 | */
21 | class Xcache
22 | {
23 |
24 | protected $options = [
25 | 'prefix' => '',
26 | 'expire' => 0,
27 | 'length' => 0,
28 | ];
29 |
30 | /**
31 | * 架构函数
32 | * @param array $options 缓存参数
33 | * @access public
34 | */
35 | public function __construct($options = [])
36 | {
37 | if (!function_exists('xcache_info')) {
38 | throw new Exception('_NOT_SUPPERT_:Xcache');
39 | }
40 | if (!empty($options)) {
41 | $this->options = array_merge($this->options, $options);
42 | }
43 | }
44 |
45 | /**
46 | * 读取缓存
47 | * @access public
48 | * @param string $name 缓存变量名
49 | * @return mixed
50 | */
51 | public function get($name)
52 | {
53 | Cache::$readTimes++;
54 | $name = $this->options['prefix'] . $name;
55 | if (xcache_isset($name)) {
56 | return xcache_get($name);
57 | }
58 | return false;
59 | }
60 |
61 | /**
62 | * 写入缓存
63 | * @access public
64 | * @param string $name 缓存变量名
65 | * @param mixed $value 存储数据
66 | * @param integer $expire 有效时间(秒)
67 | * @return boolean
68 | */
69 | public function set($name, $value, $expire = null)
70 | {
71 | Cache::$writeTimes++;
72 | if (is_null($expire)) {
73 | $expire = $this->options['expire'];
74 | }
75 | $name = $this->options['prefix'] . $name;
76 | if (xcache_set($name, $value, $expire)) {
77 | if ($this->options['length'] > 0) {
78 | // 记录缓存队列
79 | $queue = xcache_get('__info__');
80 | if (!$queue) {
81 | $queue = [];
82 | }
83 | if (false === array_search($name, $queue)) {
84 | array_push($queue, $name);
85 | }
86 |
87 | if (count($queue) > $this->options['length']) {
88 | // 出列
89 | $key = array_shift($queue);
90 | // 删除缓存
91 | xcache_unset($key);
92 | }
93 | xcache_set('__info__', $queue);
94 | }
95 | return true;
96 | }
97 | return false;
98 | }
99 |
100 | /**
101 | * 删除缓存
102 | * @access public
103 | * @param string $name 缓存变量名
104 | * @return boolean
105 | */
106 | public function rm($name)
107 | {
108 | return xcache_unset($this->options['prefix'] . $name);
109 | }
110 |
111 | /**
112 | * 清除缓存
113 | * @access public
114 | * @return boolean
115 | */
116 | public function clear()
117 | {
118 | return;
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/thinkphp/library/think/config/driver/Ini.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\config\driver;
13 |
14 | class Ini
15 | {
16 | public function parse($config)
17 | {
18 | if (is_file($config)) {
19 | return parse_ini_file($config, true);
20 | } else {
21 | return parse_ini_string($config, true);
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/thinkphp/library/think/config/driver/Xml.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\config\driver;
13 |
14 | class Xml
15 | {
16 | public function parse($config)
17 | {
18 | if (is_file($config)) {
19 | $content = simplexml_load_file($config);
20 | } else {
21 | $content = simplexml_load_string($config);
22 | }
23 | $result = (array) $content;
24 | foreach ($result as $key => $val) {
25 | if (is_object($val)) {
26 | $result[$key] = (array) $val;
27 | }
28 | }
29 | return $result;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/thinkphp/library/think/console/Output.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\console;
13 |
14 | use think\console\output\Formatter;
15 | use think\console\output\Stream;
16 |
17 | class Output extends Stream
18 | {
19 |
20 | /** @var Stream */
21 | private $stderr;
22 |
23 | public function __construct()
24 | {
25 | $outputStream = 'php://stdout';
26 | if (!$this->hasStdoutSupport()) {
27 | $outputStream = 'php://output';
28 | }
29 |
30 | parent::__construct(fopen($outputStream, 'w'));
31 |
32 | $this->stderr = new Stream(fopen('php://stderr', 'w'), $this->getFormatter());
33 | }
34 |
35 | /**
36 | * {@inheritdoc}
37 | */
38 | public function setDecorated($decorated)
39 | {
40 | parent::setDecorated($decorated);
41 | $this->stderr->setDecorated($decorated);
42 | }
43 |
44 | /**
45 | * {@inheritdoc}
46 | */
47 | public function setFormatter(Formatter $formatter)
48 | {
49 | parent::setFormatter($formatter);
50 | $this->stderr->setFormatter($formatter);
51 | }
52 |
53 | /**
54 | * {@inheritdoc}
55 | */
56 | public function setVerbosity($level)
57 | {
58 | parent::setVerbosity($level);
59 | $this->stderr->setVerbosity($level);
60 | }
61 |
62 | /**
63 | * {@inheritdoc}
64 | */
65 | public function getErrorOutput()
66 | {
67 | return $this->stderr;
68 | }
69 |
70 | /**
71 | * {@inheritdoc}
72 | */
73 | public function setErrorOutput(Output $error)
74 | {
75 | $this->stderr = $error;
76 | }
77 |
78 | /**
79 | * 检查当前环境是否支持控制台输出写入标准输出。
80 | * @return bool
81 | */
82 | protected function hasStdoutSupport()
83 | {
84 | return ('OS400' != php_uname('s'));
85 | }
86 | }
--------------------------------------------------------------------------------
/thinkphp/library/think/console/bin/README.md:
--------------------------------------------------------------------------------
1 | console 工具使用 hiddeninput.exe 在 windows 上隐藏密码输入,该二进制文件由第三方提供,相关源码和其他细节可以在 [Hidden Input](https://github.com/Seldaek/hidden-input) 找到。
2 |
--------------------------------------------------------------------------------
/thinkphp/library/think/console/bin/hiddeninput.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lwl12/LWL-API/3b6fd88a58ec60fc8cc9587939e55bcb45431ce9/thinkphp/library/think/console/bin/hiddeninput.exe
--------------------------------------------------------------------------------
/thinkphp/library/think/console/command/Build.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\console\command;
13 |
14 |
15 | use think\console\Input;
16 | use think\console\input\Option;
17 | use think\console\Output;
18 |
19 | class Build extends Command
20 | {
21 |
22 | /**
23 | * {@inheritdoc}
24 | */
25 | protected function configure()
26 | {
27 | $this->setName('build')
28 | ->setDefinition([new Option('config', null, Option::VALUE_OPTIONAL, "build.php path")])
29 | ->setDescription('Build Application Dirs');
30 | }
31 |
32 | protected function execute(Input $input, Output $output)
33 | {
34 |
35 | if ($input->hasOption('config')) {
36 | $build = include $input->getOption('config');
37 | } else {
38 | $build = include APP_PATH . 'build.php';
39 | }
40 | if (empty($build)) {
41 | $output->writeln("Build Config Is Empty");
42 | return;
43 | }
44 | \think\Build::run($build);
45 | $output->writeln("Successed");
46 |
47 | }
48 | }
--------------------------------------------------------------------------------
/thinkphp/library/think/console/command/Help.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\console\command;
13 |
14 | use think\console\Input;
15 | use think\console\input\Argument as InputArgument;
16 | use think\console\input\Option as InputOption;
17 | use think\console\Output;
18 | use think\console\helper\Descriptor as DescriptorHelper;
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 |
64 | $helper = new DescriptorHelper();
65 | $helper->describe($output, $this->command, [
66 | 'raw_text' => $input->getOption('raw'),
67 | ]);
68 |
69 | $this->command = null;
70 | }
71 | }
--------------------------------------------------------------------------------
/thinkphp/library/think/console/command/Lists.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\console\command;
13 |
14 |
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 | use think\console\helper\Descriptor as DescriptorHelper;
21 |
22 | class Lists extends Command
23 | {
24 |
25 | /**
26 | * {@inheritdoc}
27 | */
28 | protected function configure()
29 | {
30 | $this->setName('list')->setDefinition($this->createDefinition())->setDescription('Lists commands')->setHelp(<<%command.name% command lists all commands:
32 |
33 | php %command.full_name%
34 |
35 | You can also display the commands for a specific namespace:
36 |
37 | php %command.full_name% test
38 |
39 | It's also possible to get raw list of commands (useful for embedding command runner):
40 |
41 | php %command.full_name% --raw
42 | EOF
43 | );
44 | }
45 |
46 | /**
47 | * {@inheritdoc}
48 | */
49 | public function getNativeDefinition()
50 | {
51 | return $this->createDefinition();
52 | }
53 |
54 | /**
55 | * {@inheritdoc}
56 | */
57 | protected function execute(Input $input, Output $output)
58 | {
59 |
60 | $helper = new DescriptorHelper();
61 | $helper->describe($output, $this->getConsole(), [
62 | 'raw_text' => $input->getOption('raw'),
63 | 'namespace' => $input->getArgument('namespace'),
64 | ]);
65 | }
66 |
67 | /**
68 | * {@inheritdoc}
69 | */
70 | private function createDefinition()
71 | {
72 | return new InputDefinition([
73 | new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
74 | new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list')
75 | ]);
76 | }
77 | }
--------------------------------------------------------------------------------
/thinkphp/library/think/console/command/make/Controller.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\console\command\make;
13 |
14 | use think\console\command\Command;
15 |
16 | class Controller extends Command
17 | {
18 |
19 | public function __construct()
20 | {
21 | parent::__construct("make:controller");
22 | }
23 | }
--------------------------------------------------------------------------------
/thinkphp/library/think/console/command/make/Model.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\console\command\make;
13 |
14 |
15 | use think\console\command\Command;
16 |
17 |
18 | class Model extends Command
19 | {
20 |
21 | public function __construct()
22 | {
23 | parent::__construct("make:model");
24 | }
25 |
26 | }
--------------------------------------------------------------------------------
/thinkphp/library/think/console/helper/Descriptor.php:
--------------------------------------------------------------------------------
1 |
8 | // +----------------------------------------------------------------------
9 |
10 | namespace think\console\helper;
11 |
12 | use think\console\helper\descriptor\Descriptor as OutputDescriptor;
13 | use think\console\Output;
14 |
15 | class Descriptor extends Helper
16 | {
17 |
18 | /**
19 | * @var OutputDescriptor
20 | */
21 | private $descriptor;
22 |
23 | /**
24 | * 构造方法
25 | */
26 | public function __construct()
27 | {
28 | $this->descriptor = new OutputDescriptor();
29 | }
30 |
31 | /**
32 | * 描述
33 | * @param Output $output
34 | * @param object $object
35 | * @param array $options
36 | * @throws \InvalidArgumentException
37 | */
38 | public function describe(Output $output, $object, array $options = [])
39 | {
40 | $options = array_merge([
41 | 'raw_text' => false
42 | ], $options);
43 |
44 | $this->descriptor->describe($output, $object, $options);
45 | }
46 |
47 | /**
48 | * {@inheritdoc}
49 | */
50 | public function getName()
51 | {
52 | return 'descriptor';
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/thinkphp/library/think/console/helper/Formatter.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\console\helper;
13 |
14 | use think\console\output\Formatter as OutputFormatter;
15 |
16 | class Formatter extends Helper
17 | {
18 |
19 | /**
20 | * 设置消息在某一节的格式
21 | * @param string $section 节名称
22 | * @param string $message 消息
23 | * @param string $style 样式
24 | * @return string
25 | */
26 | public function formatSection($section, $message, $style = 'info')
27 | {
28 | return sprintf('<%s>[%s]%s> %s', $style, $section, $style, $message);
29 | }
30 |
31 | /**
32 | * 设置消息作为文本块的格式
33 | * @param string|array $messages 消息
34 | * @param string $style 样式
35 | * @param bool $large 是否返回一个大段文本
36 | * @return string The formatter message
37 | */
38 | public function formatBlock($messages, $style, $large = false)
39 | {
40 | if (!is_array($messages)) {
41 | $messages = [$messages];
42 | }
43 |
44 | $len = 0;
45 | $lines = [];
46 | foreach ($messages as $message) {
47 | $message = OutputFormatter::escape($message);
48 | $lines[] = sprintf($large ? ' %s ' : ' %s ', $message);
49 | $len = max($this->strlen($message) + ($large ? 4 : 2), $len);
50 | }
51 |
52 | $messages = $large ? [str_repeat(' ', $len)] : [];
53 | for ($i = 0; isset($lines[$i]); ++$i) {
54 | $messages[] = $lines[$i] . str_repeat(' ', $len - $this->strlen($lines[$i]));
55 | }
56 | if ($large) {
57 | $messages[] = str_repeat(' ', $len);
58 | }
59 |
60 | for ($i = 0; isset($messages[$i]); ++$i) {
61 | $messages[$i] = sprintf('<%s>%s%s>', $style, $messages[$i], $style);
62 | }
63 |
64 | return implode("\n", $messages);
65 | }
66 |
67 | /**
68 | * {@inheritdoc}
69 | */
70 | public function getName()
71 | {
72 | return 'formatter';
73 | }
74 | }
--------------------------------------------------------------------------------
/thinkphp/library/think/console/helper/Helper.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\console\helper;
13 |
14 | use think\console\helper\Set as HelperSet;
15 | use think\console\output\Formatter;
16 |
17 | abstract class Helper
18 | {
19 |
20 | protected $helperSet = null;
21 |
22 | /**
23 | * 设置与此助手关联的助手集。
24 | * @param HelperSet $helperSet
25 | */
26 | public function setHelperSet(HelperSet $helperSet = null)
27 | {
28 | $this->helperSet = $helperSet;
29 | }
30 |
31 | /**
32 | * 获取与此助手关联的助手集。
33 | * @return HelperSet
34 | */
35 | public function getHelperSet()
36 | {
37 | return $this->helperSet;
38 | }
39 |
40 | /**
41 | * 获取名称
42 | * @return string
43 | */
44 | abstract public function getName();
45 |
46 | /**
47 | * 返回字符串的长度
48 | * @param string $string
49 | * @return int
50 | */
51 | public static function strlen($string)
52 | {
53 | if (!function_exists('mb_strwidth')) {
54 | return strlen($string);
55 | }
56 |
57 | if (false === $encoding = mb_detect_encoding($string)) {
58 | return strlen($string);
59 | }
60 |
61 | return mb_strwidth($string, $encoding);
62 | }
63 |
64 | public static function formatTime($secs)
65 | {
66 | static $timeFormats = [
67 | [0, '< 1 sec'],
68 | [2, '1 sec'],
69 | [59, 'secs', 1],
70 | [60, '1 min'],
71 | [3600, 'mins', 60],
72 | [5400, '1 hr'],
73 | [86400, 'hrs', 3600],
74 | [129600, '1 day'],
75 | [604800, 'days', 86400],
76 | ];
77 |
78 | foreach ($timeFormats as $format) {
79 | if ($secs >= $format[0]) {
80 | continue;
81 | }
82 |
83 | if (2 == count($format)) {
84 | return $format[1];
85 | }
86 |
87 | return ceil($secs / $format[2]) . ' ' . $format[1];
88 | }
89 | return null;
90 | }
91 |
92 | public static function formatMemory($memory)
93 | {
94 | if ($memory >= 1024 * 1024 * 1024) {
95 | return sprintf('%.1f GiB', $memory / 1024 / 1024 / 1024);
96 | }
97 |
98 | if ($memory >= 1024 * 1024) {
99 | return sprintf('%.1f MiB', $memory / 1024 / 1024);
100 | }
101 |
102 | if ($memory >= 1024) {
103 | return sprintf('%d KiB', $memory / 1024);
104 | }
105 |
106 | return sprintf('%d B', $memory);
107 | }
108 |
109 | public static function strlenWithoutDecoration(Formatter $formatter, $string)
110 | {
111 | $isDecorated = $formatter->isDecorated();
112 | $formatter->setDecorated(false);
113 | // remove <...> formatting
114 | $string = $formatter->format($string);
115 | // remove already formatted characters
116 | $string = preg_replace("/\033\[[^m]*m/", '', $string);
117 | $formatter->setDecorated($isDecorated);
118 |
119 | return self::strlen($string);
120 | }
121 | }
--------------------------------------------------------------------------------
/thinkphp/library/think/console/helper/Set.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\console\helper;
13 |
14 |
15 | use think\console\command\Command;
16 |
17 | class Set implements \IteratorAggregate
18 | {
19 |
20 | private $helpers = [];
21 | private $command;
22 |
23 | /**
24 | * 构造方法
25 | * @param Helper[] $helpers 助手实例数组
26 | */
27 | public function __construct(array $helpers = [])
28 | {
29 | /**
30 | * @var int|string $alias
31 | * @var Helper $helper
32 | */
33 | foreach ($helpers as $alias => $helper) {
34 | $this->set($helper, is_int($alias) ? null : $alias);
35 | }
36 | }
37 |
38 | /**
39 | * 添加一个助手
40 | * @param Helper $helper 助手实例
41 | * @param string $alias 别名
42 | */
43 | public function set(Helper $helper, $alias = null)
44 | {
45 | $this->helpers[$helper->getName()] = $helper;
46 | if (null !== $alias) {
47 | $this->helpers[$alias] = $helper;
48 | }
49 |
50 | $helper->setHelperSet($this);
51 | }
52 |
53 | /**
54 | * 是否有某个助手
55 | * @param string $name 助手名称
56 | * @return bool
57 | */
58 | public function has($name)
59 | {
60 | return isset($this->helpers[$name]);
61 | }
62 |
63 | /**
64 | * 获取助手
65 | * @param string $name 助手名称
66 | * @return Helper
67 | * @throws \InvalidArgumentException
68 | */
69 | public function get($name)
70 | {
71 | if (!$this->has($name)) {
72 | throw new \InvalidArgumentException(sprintf('The helper "%s" is not defined.', $name));
73 | }
74 |
75 | return $this->helpers[$name];
76 | }
77 |
78 | /**
79 | * 设置与这个助手关联的命令集
80 | * @param Command $command
81 | */
82 | public function setCommand(Command $command = null)
83 | {
84 | $this->command = $command;
85 | }
86 |
87 | /**
88 | * 获取与这个助手关联的命令集
89 | * @return Command
90 | */
91 | public function getCommand()
92 | {
93 | return $this->command;
94 | }
95 |
96 | public function getIterator()
97 | {
98 | return new \ArrayIterator($this->helpers);
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/thinkphp/library/think/console/helper/question/Confirmation.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\console\helper\question;
13 |
14 |
15 | class Confirmation extends Question
16 | {
17 |
18 | private $trueAnswerRegex;
19 |
20 | /**
21 | * 构造方法
22 | * @param string $question 问题
23 | * @param bool $default 默认答案
24 | * @param string $trueAnswerRegex 验证正则
25 | */
26 | public function __construct($question, $default = true, $trueAnswerRegex = '/^y/i')
27 | {
28 | parent::__construct($question, (bool)$default);
29 |
30 | $this->trueAnswerRegex = $trueAnswerRegex;
31 | $this->setNormalizer($this->getDefaultNormalizer());
32 | }
33 |
34 | /**
35 | * 获取默认的答案回调
36 | * @return callable
37 | */
38 | private function getDefaultNormalizer()
39 | {
40 | $default = $this->getDefault();
41 | $regex = $this->trueAnswerRegex;
42 |
43 | return function ($answer) use ($default, $regex) {
44 | if (is_bool($answer)) {
45 | return $answer;
46 | }
47 |
48 | $answerIsTrue = (bool)preg_match($regex, $answer);
49 | if (false === $default) {
50 | return $answer && $answerIsTrue;
51 | }
52 |
53 | return !$answer || $answerIsTrue;
54 | };
55 | }
56 | }
--------------------------------------------------------------------------------
/thinkphp/library/think/console/input/Argument.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\console\input;
13 |
14 |
15 | class Argument
16 | {
17 |
18 | const REQUIRED = 1;
19 | const OPTIONAL = 2;
20 | const IS_ARRAY = 4;
21 |
22 | private $name;
23 | private $mode;
24 | private $default;
25 | private $description;
26 |
27 | /**
28 | * 构造方法
29 | * @param string $name 参数名
30 | * @param int $mode 参数类型: self::REQUIRED 或者 self::OPTIONAL
31 | * @param string $description 描述
32 | * @param mixed $default 默认值 (仅 self::OPTIONAL 类型有效)
33 | * @throws \InvalidArgumentException
34 | */
35 | public function __construct($name, $mode = null, $description = '', $default = null)
36 | {
37 | if (null === $mode) {
38 | $mode = self::OPTIONAL;
39 | } elseif (!is_int($mode) || $mode > 7 || $mode < 1) {
40 | throw new \InvalidArgumentException(sprintf('Argument mode "%s" is not valid.', $mode));
41 | }
42 |
43 | $this->name = $name;
44 | $this->mode = $mode;
45 | $this->description = $description;
46 |
47 | $this->setDefault($default);
48 | }
49 |
50 | /**
51 | * 获取参数名
52 | * @return string
53 | */
54 | public function getName()
55 | {
56 | return $this->name;
57 | }
58 |
59 | /**
60 | * 是否必须
61 | * @return bool
62 | */
63 | public function isRequired()
64 | {
65 | return self::REQUIRED === (self::REQUIRED & $this->mode);
66 | }
67 |
68 | /**
69 | * 该参数是否接受数组
70 | * @return bool
71 | */
72 | public function isArray()
73 | {
74 | return self::IS_ARRAY === (self::IS_ARRAY & $this->mode);
75 | }
76 |
77 | /**
78 | * 设置默认值
79 | * @param mixed $default 默认值
80 | * @throws \LogicException
81 | */
82 | public function setDefault($default = null)
83 | {
84 | if (self::REQUIRED === $this->mode && null !== $default) {
85 | throw new \LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.');
86 | }
87 |
88 | if ($this->isArray()) {
89 | if (null === $default) {
90 | $default = [];
91 | } elseif (!is_array($default)) {
92 | throw new \LogicException('A default value for an array argument must be an array.');
93 | }
94 | }
95 |
96 | $this->default = $default;
97 | }
98 |
99 | /**
100 | * 获取默认值
101 | * @return mixed
102 | */
103 | public function getDefault()
104 | {
105 | return $this->default;
106 | }
107 |
108 | /**
109 | * 获取描述
110 | * @return string
111 | */
112 | public function getDescription()
113 | {
114 | return $this->description;
115 | }
116 | }
--------------------------------------------------------------------------------
/thinkphp/library/think/console/output/formatter/Stack.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\console\output\formatter;
13 |
14 |
15 | class Stack
16 | {
17 |
18 | /**
19 | * @var Style[]
20 | */
21 | private $styles;
22 |
23 | /**
24 | * @var Style
25 | */
26 | private $emptyStyle;
27 |
28 | /**
29 | * 构造方法
30 | * @param Style|null $emptyStyle
31 | */
32 | public function __construct(Style $emptyStyle = null)
33 | {
34 | $this->emptyStyle = $emptyStyle ?: new Style();
35 | $this->reset();
36 | }
37 |
38 | /**
39 | * 重置堆栈
40 | */
41 | public function reset()
42 | {
43 | $this->styles = [];
44 | }
45 |
46 | /**
47 | * 推一个样式进入堆栈
48 | * @param Style $style
49 | */
50 | public function push(Style $style)
51 | {
52 | $this->styles[] = $style;
53 | }
54 |
55 | /**
56 | * 从堆栈中弹出一个样式
57 | * @param Style|null $style
58 | * @return Style
59 | * @throws \InvalidArgumentException
60 | */
61 | public function pop(Style $style = null)
62 | {
63 | if (empty($this->styles)) {
64 | return $this->emptyStyle;
65 | }
66 |
67 | if (null === $style) {
68 | return array_pop($this->styles);
69 | }
70 |
71 | /**
72 | * @var int $index
73 | * @var Style $stackedStyle
74 | */
75 | foreach (array_reverse($this->styles, true) as $index => $stackedStyle) {
76 | if ($style->apply('') === $stackedStyle->apply('')) {
77 | $this->styles = array_slice($this->styles, 0, $index);
78 |
79 | return $stackedStyle;
80 | }
81 | }
82 |
83 | throw new \InvalidArgumentException('Incorrectly nested style tag found.');
84 | }
85 |
86 | /**
87 | * 计算堆栈的当前样式。
88 | * @return Style
89 | */
90 | public function getCurrent()
91 | {
92 | if (empty($this->styles)) {
93 | return $this->emptyStyle;
94 | }
95 |
96 | return $this->styles[count($this->styles) - 1];
97 | }
98 |
99 | /**
100 | * @param Style $emptyStyle
101 | * @return Stack
102 | */
103 | public function setEmptyStyle(Style $emptyStyle)
104 | {
105 | $this->emptyStyle = $emptyStyle;
106 |
107 | return $this;
108 | }
109 |
110 | /**
111 | * @return Style
112 | */
113 | public function getEmptyStyle()
114 | {
115 | return $this->emptyStyle;
116 | }
117 | }
--------------------------------------------------------------------------------
/thinkphp/library/think/controller/Hprose.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 | namespace think\controller;
12 |
13 | /**
14 | * ThinkPHP Hprose控制器类
15 | */
16 | abstract class Hprose
17 | {
18 |
19 | protected $allowMethodList = '';
20 | protected $crossDomain = false;
21 | protected $P3P = false;
22 | protected $get = true;
23 | protected $debug = false;
24 |
25 | /**
26 | * 架构函数
27 | * @access public
28 | */
29 | public function __construct()
30 | {
31 | //控制器初始化
32 | if (method_exists($this, '_initialize')) {
33 | $this->_initialize();
34 | }
35 |
36 | //导入类库
37 | \think\Loader::import('vendor.Hprose.HproseHttpServer');
38 | //实例化HproseHttpServer
39 | $server = new \HproseHttpServer();
40 | if ($this->allowMethodList) {
41 | $methods = $this->allowMethodList;
42 | } else {
43 | $methods = get_class_methods($this);
44 | $methods = array_diff($methods, array('__construct', '__call', '_initialize'));
45 | }
46 | $server->addMethods($methods, $this);
47 | if (APP_DEBUG || $this->debug) {
48 | $server->setDebugEnabled(true);
49 | }
50 | // Hprose设置
51 | $server->setCrossDomainEnabled($this->crossDomain);
52 | $server->setP3PEnabled($this->P3P);
53 | $server->setGetEnabled($this->get);
54 | // 启动server
55 | $server->start();
56 | }
57 |
58 | /**
59 | * 魔术方法 有不存在的操作的时候执行
60 | * @access public
61 | * @param string $method 方法名
62 | * @param array $args 参数
63 | * @return mixed
64 | */
65 | public function __call($method, $args)
66 | {}
67 | }
68 |
--------------------------------------------------------------------------------
/thinkphp/library/think/controller/Jsonrpc.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 | namespace think\controller;
12 |
13 | /**
14 | * ThinkPHP JsonRPC控制器类
15 | */
16 | abstract class Jsonrpc
17 | {
18 |
19 | /**
20 | * 架构函数
21 | * @access public
22 | */
23 | public function __construct()
24 | {
25 | //控制器初始化
26 | if (method_exists($this, '_initialize')) {
27 | $this->_initialize();
28 | }
29 |
30 | //导入类库
31 | \think\Loader::import('vendor.jsonrpc.jsonRPCServer');
32 | // 启动server
33 | \jsonRPCServer::handle($this);
34 | }
35 |
36 | /**
37 | * 魔术方法 有不存在的操作的时候执行
38 | * @access public
39 | * @param string $method 方法名
40 | * @param array $args 参数
41 | * @return mixed
42 | */
43 | public function __call($method, $args)
44 | {}
45 | }
46 |
--------------------------------------------------------------------------------
/thinkphp/library/think/controller/Rpc.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 | namespace think\controller;
12 |
13 | /**
14 | * ThinkPHP RPC控制器类
15 | */
16 | abstract class Rpc
17 | {
18 |
19 | protected $allowMethodList = '';
20 | protected $debug = false;
21 |
22 | /**
23 | * 架构函数
24 | * @access public
25 | */
26 | public function __construct()
27 | {
28 | //控制器初始化
29 | if (method_exists($this, '_initialize')) {
30 | $this->_initialize();
31 | }
32 |
33 | //导入类库
34 | \think\Loader::import('vendor.phprpc.phprpc_server');
35 | //实例化phprpc
36 | $server = new \PHPRPC_Server();
37 | if ($this->allowMethodList) {
38 | $methods = $this->allowMethodList;
39 | } else {
40 | $methods = get_class_methods($this);
41 | $methods = array_diff($methods, array('__construct', '__call', '_initialize'));
42 | }
43 | $server->add($methods, $this);
44 |
45 | if (APP_DEBUG || $this->debug) {
46 | $server->setDebugMode(true);
47 | }
48 | $server->setEnableGZIP(true);
49 | $server->start();
50 | echo $server->comment();
51 | }
52 |
53 | /**
54 | * 魔术方法 有不存在的操作的时候执行
55 | * @access public
56 | * @param string $method 方法名
57 | * @param array $args 参数
58 | * @return mixed
59 | */
60 | public function __call($method, $args)
61 | {}
62 | }
63 |
--------------------------------------------------------------------------------
/thinkphp/library/think/controller/Yar.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 | namespace think\controller;
12 |
13 | /**
14 | * ThinkPHP Yar控制器类
15 | */
16 | abstract class Yar
17 | {
18 |
19 | /**
20 | * 架构函数
21 | * @access public
22 | */
23 | public function __construct()
24 | {
25 | //控制器初始化
26 | if (method_exists($this, '_initialize')) {
27 | $this->_initialize();
28 | }
29 |
30 | //判断扩展是否存在
31 | if (!extension_loaded('yar')) {
32 | throw new Exception('not support yar');
33 | }
34 |
35 | //实例化Yar_Server
36 | $server = new \Yar_Server($this);
37 | // 启动server
38 | $server->handle();
39 | }
40 |
41 | /**
42 | * 魔术方法 有不存在的操作的时候执行
43 | * @access public
44 | * @param string $method 方法名
45 | * @param array $args 参数
46 | * @return mixed
47 | */
48 | public function __call($method, $args)
49 | {}
50 | }
51 |
--------------------------------------------------------------------------------
/thinkphp/library/think/db/driver/Sqlite.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\db\driver;
13 |
14 | use think\db\Driver;
15 |
16 | /**
17 | * Sqlite数据库驱动
18 | */
19 | class Sqlite extends Driver
20 | {
21 |
22 | /**
23 | * 解析pdo连接的dsn信息
24 | * @access public
25 | * @param array $config 连接信息
26 | * @return string
27 | */
28 | protected function parseDsn($config)
29 | {
30 | $dsn = 'sqlite:' . $config['database'];
31 | return $dsn;
32 | }
33 |
34 | /**
35 | * 取得数据表的字段信息
36 | * @access public
37 | * @return array
38 | */
39 | public function getFields($tableName)
40 | {
41 | list($tableName) = explode(' ', $tableName);
42 | $result = $this->query('PRAGMA table_info( ' . $tableName . ' )');
43 | $info = [];
44 | if ($result) {
45 | foreach ($result as $key => $val) {
46 | $val = array_change_key_case($val);
47 | $info[$val['name']] = [
48 | 'name' => $val['name'],
49 | 'type' => $val['type'],
50 | 'notnull' => 1 === $val['notnull'],
51 | 'default' => $val['dflt_value'],
52 | 'primary' => '1' == $val['pk'],
53 | 'autoinc' => '1' == $val['pk'],
54 | ];
55 | }
56 | }
57 | return $info;
58 | }
59 |
60 | /**
61 | * 取得数据库的表信息
62 | * @access public
63 | * @return array
64 | */
65 | public function getTables($dbName = '')
66 | {
67 | $result = $this->query("SELECT name FROM sqlite_master WHERE type='table' "
68 | . "UNION ALL SELECT name FROM sqlite_temp_master "
69 | . "WHERE type='table' ORDER BY name");
70 | $info = [];
71 | foreach ($result as $key => $val) {
72 | $info[$key] = current($val);
73 | }
74 | return $info;
75 | }
76 |
77 | /**
78 | * limit
79 | * @access public
80 | * @return string
81 | */
82 | public function parseLimit($limit)
83 | {
84 | $limitStr = '';
85 | if (!empty($limit)) {
86 | $limit = explode(',', $limit);
87 | if (count($limit) > 1) {
88 | $limitStr .= ' LIMIT ' . $limit[1] . ' OFFSET ' . $limit[0] . ' ';
89 | } else {
90 | $limitStr .= ' LIMIT ' . $limit[0] . ' ';
91 | }
92 | }
93 | return $limitStr;
94 | }
95 |
96 | /**
97 | * 随机排序
98 | * @access protected
99 | * @return string
100 | */
101 | protected function parseRand()
102 | {
103 | return 'RANDOM()';
104 | }
105 |
106 | /**
107 | * SQL性能分析
108 | * @access protected
109 | * @param string $sql
110 | * @return array
111 | */
112 | protected function getExplain($sql)
113 | {
114 |
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/thinkphp/library/think/exception/DbBindParamException.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\exception;
13 |
14 | use think\exception\DbException;
15 |
16 | /**
17 | * PDO参数绑定异常
18 | */
19 | class DbBindParamException extends DbException
20 | {
21 | public function __construct($message, $config, $sql, $bind, $code = 10502)
22 | {
23 | $this->setData('Bind Param', $bind);
24 | parent::__construct($message, $config, $sql, $code);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/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 | public function __construct($message, Array $config, $sql, $code = 10500)
22 | {
23 | $this->message = $message;
24 | $this->code = $code;
25 |
26 | $this->setData('Database Status', [
27 | 'Error Code' => $code,
28 | 'Error Message' => $message,
29 | 'Error SQL' => $sql
30 | ]);
31 |
32 | $this->setData('Database Config', $config);
33 | }
34 |
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/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 | * @param integer $severity 错误级别
33 | * @param string $message 错误详细信息
34 | * @param string $file 出错文件路径
35 | * @param integer $line 出错行号
36 | * @param array $context 错误上下文,会包含错误触发处作用域内所有变量的数组
37 | */
38 | public function __construct($severity, $message, $file, $line, array $context = [])
39 | {
40 | $this->severity = $severity;
41 | $this->message = $message;
42 | $this->file = $file;
43 | $this->line = $line;
44 | $this->code = 0;
45 |
46 | empty($context) || $this->setData('Error Context', $context);
47 | }
48 |
49 | /**
50 | * 获取错误级别
51 | * @return integer 错误级别
52 | */
53 | final public function getSeverity()
54 | {
55 | return $this->severity;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/thinkphp/library/think/exception/NotFoundException.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\exception;
13 |
14 | use think\Exception;
15 |
16 | /**
17 | * Database相关异常处理类
18 | */
19 | class NotFoundException extends Exception
20 | {
21 | /**
22 | * 系统异常后发送给客户端的HTTP Status
23 | * @var integer
24 | */
25 | protected $httpStatus = 404;
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/thinkphp/library/think/exception/PDOException.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\exception;
13 |
14 | use think\exception\DbException;
15 |
16 | /**
17 | * PDO异常处理类
18 | * 重新封装了系统的\PDOException类
19 | */
20 | class PDOException extends DbException
21 | {
22 | public function __construct(\PDOException $exception, Array $config, $sql, $code = 10501)
23 | {
24 | $error = $exception->errorInfo;
25 |
26 | $this->setData('PDO Error Info', [
27 | 'SQLSTATE' => $error[0],
28 | 'Driver Error Code' => $error[1],
29 | 'Driver Error Message' => isset($error[2]) ? $error[2] : ''
30 | ]);
31 |
32 | parent::__construct($exception->getMessage(), $config, $sql, $code);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/thinkphp/library/think/log/alarm/Email.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 | namespace think\log\alarm;
12 |
13 | /**
14 | * 邮件通知驱动
15 | */
16 | class Email
17 | {
18 |
19 | protected $config = [
20 | 'address' => '',
21 | ];
22 |
23 | // 实例化并传入参数
24 | public function __construct($config = [])
25 | {
26 | $this->config = array_merge($this->config, $config);
27 | }
28 |
29 | /**
30 | * 通知发送接口
31 | * @access public
32 | * @param string $msg 日志信息
33 | * @return void
34 | */
35 | public function send($msg = '')
36 | {
37 | error_log($msg, 1, $this->config['address']);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/thinkphp/library/think/log/driver/File.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 | namespace think\log\driver;
12 |
13 | /**
14 | * 本地化调试输出到文件
15 | */
16 | class File
17 | {
18 | protected $config = [
19 | 'time_format' => ' c ',
20 | 'file_size' => 2097152,
21 | 'path' => LOG_PATH,
22 | ];
23 |
24 | // 实例化并传入参数
25 | public function __construct($config = [])
26 | {
27 | if (is_array($config)) {
28 | $this->config = array_merge($this->config, $config);
29 | }
30 | }
31 |
32 | /**
33 | * 日志写入接口
34 | * @access public
35 | * @param array $log 日志信息
36 | * @return void
37 | */
38 | public function save(array $log = [])
39 | {
40 | $now = date($this->config['time_format']);
41 | $destination = $this->config['path'] . date('y_m_d') . '.log';
42 |
43 | !is_dir($this->config['path']) && mkdir($this->config['path'], 0755, true);
44 |
45 | //检测日志文件大小,超过配置大小则备份日志文件重新生成
46 | if (is_file($destination) && floor($this->config['file_size']) <= filesize($destination)) {
47 | rename($destination, dirname($destination) . DS . time() . '-' . basename($destination));
48 | }
49 |
50 | // 获取基本信息
51 | if (isset($_SERVER['HTTP_HOST'])) {
52 | $current_uri = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
53 | } else {
54 | $current_uri = "cmd:" . implode(' ', $_SERVER['argv']);
55 | }
56 | $runtime = number_format(microtime(true) - START_TIME, 6);
57 | $reqs = number_format(1 / $runtime, 2);
58 | $time_str = " [运行时间:{$runtime}s] [吞吐率:{$reqs}req/s]";
59 | $memory_use = number_format((memory_get_usage() - START_MEM) / 1024, 2);
60 | $memory_str = " [内存消耗:{$memory_use}kb]";
61 | $file_load = " [文件加载:" . count(get_included_files()) . "]";
62 |
63 | array_unshift($log, [
64 | 'type' => 'log',
65 | 'msg' => $current_uri . $time_str . $memory_str . $file_load,
66 | ]);
67 |
68 | $info = '';
69 | foreach ($log as $line) {
70 | $info .= '[' . $line['type'] . '] ' . $line['msg'] . "\r\n";
71 | }
72 |
73 | $server = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '0.0.0.0';
74 | $remote = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0';
75 | $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
76 | error_log("[{$now}] {$server} {$remote} {$uri}\r\n{$info}\r\n", 3, $destination);
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/thinkphp/library/think/log/driver/Sae.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 | namespace think\log\driver;
12 |
13 | /**
14 | * 调试输出到SAE
15 | */
16 | class Sae
17 | {
18 | protected $config = [
19 | 'log_time_format' => ' c ',
20 | ];
21 |
22 | // 实例化并传入参数
23 | public function __construct(array $config = [])
24 | {
25 | $this->config = array_merge($this->config, $config);
26 | }
27 |
28 | /**
29 | * 日志写入接口
30 | * @access public
31 | * @param array $log 日志信息
32 | * @return void
33 | */
34 | public function save(array $log = [])
35 | {
36 | static $is_debug = null;
37 | $now = date($this->config['log_time_format']);
38 | // 获取基本信息
39 | if (isset($_SERVER['HTTP_HOST'])) {
40 | $current_uri = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
41 | } else {
42 | $current_uri = "cmd:" . implode(' ', $_SERVER['argv']);
43 | }
44 | $runtime = number_format(microtime(true) - START_TIME, 6);
45 | $reqs = number_format(1 / $runtime, 2);
46 | $time_str = " [运行时间:{$runtime}s] [吞吐率:{$reqs}req/s]";
47 | $memory_use = number_format((memory_get_usage() - START_MEM) / 1024, 2);
48 | $memory_str = " [内存消耗:{$memory_use}kb]";
49 | $file_load = " [文件加载:" . count(get_included_files()) . "]";
50 |
51 | array_unshift($log, [
52 | 'type' => 'log',
53 | 'msg' => $current_uri . $time_str . $memory_str . $file_load,
54 | ]);
55 |
56 | $info = '';
57 | foreach ($log as $line) {
58 | $info .= '[' . $line['type'] . '] ' . $line['msg'] . "\r\n";
59 | }
60 |
61 | $logstr = "[{$now}] {$_SERVER['SERVER_ADDR']} {$_SERVER['REMOTE_ADDR']} {$_SERVER['REQUEST_URI']}\r\n{$info}\r\n";
62 | if (is_null($is_debug)) {
63 | $appSettings = [];
64 | preg_replace_callback('@(\w+)\=([^;]*)@', function ($match) use (&$appSettings) {
65 | $appSettings[$match['1']] = $match['2'];
66 | }, $_SERVER['HTTP_APPCOOKIE']);
67 | $is_debug = in_array($_SERVER['HTTP_APPVERSION'], explode(',', $appSettings['debug'])) ? true : false;
68 | }
69 | if ($is_debug) {
70 | sae_set_display_errors(false); //记录日志不将日志打印出来
71 | }
72 | sae_debug($logstr);
73 | if ($is_debug) {
74 | sae_set_display_errors(true);
75 | }
76 |
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/thinkphp/library/think/log/driver/Test.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 | namespace think\log\driver;
12 |
13 | /**
14 | * 模拟测试输出
15 | */
16 | class Test
17 | {
18 | /**
19 | * 日志写入接口
20 | * @access public
21 | * @param array $log 日志信息
22 | * @return void
23 | */
24 | public function save(array $log = [])
25 | {
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/thinkphp/library/think/log/driver/Trace.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 | namespace think\log\driver;
12 |
13 | use think\Config;
14 | use think\Debug;
15 |
16 | /**
17 | * 页面Trace调试 需要设置 'response_exit' => false 才能生效
18 | */
19 | class Trace
20 | {
21 | protected $tabs = ['base' => '基本', 'file' => '文件', 'info' => '流程', 'notice|error' => '错误', 'sql' => 'SQL', 'debug|log' => '调试'];
22 | protected $config = [
23 | 'trace_file' => '',
24 | ];
25 |
26 | // 实例化并传入参数
27 | public function __construct(array $config = [])
28 | {
29 | $this->config['trace_file'] = THINK_PATH . 'tpl/page_trace.tpl';
30 | $this->config = array_merge($this->config, $config);
31 | }
32 |
33 | /**
34 | * 日志写入接口
35 | * @access public
36 | * @param array $log 日志信息
37 | * @return void
38 | */
39 | public function save(array $log = [])
40 | {
41 | if (IS_AJAX || IS_CLI || IS_API || 'html' != Config::get('default_return_type')) {
42 | // ajax cli api方式下不输出
43 | return;
44 | }
45 | // 获取基本信息
46 | $runtime = number_format(microtime(true) - START_TIME, 6);
47 | $reqs = number_format(1 / $runtime, 2);
48 | $mem = number_format((memory_get_usage() - START_MEM) / 1024, 2);
49 |
50 | // 页面Trace信息
51 | $base = [
52 | '请求信息' => date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']) . ' ' . $_SERVER['SERVER_PROTOCOL'] . ' ' . $_SERVER['REQUEST_METHOD'] . ' : ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
53 | '运行时间' => "{$runtime}s [ 吞吐率:{$reqs}req/s ] 内存消耗:{$mem}kb 文件加载:" . count(get_included_files()),
54 | '查询信息' => \think\Db::$queryTimes . ' queries ' . \think\Db::$executeTimes . ' writes ',
55 | '缓存信息' => \think\Cache::$readTimes . ' reads,' . \think\Cache::$writeTimes . ' writes',
56 | '配置加载' => count(Config::get()),
57 | '会话信息' => 'SESSION_ID=' . session_id(),
58 | ];
59 |
60 | $info = Debug::getFile(true);
61 |
62 | // 获取调试日志
63 | $debug = [];
64 | foreach ($log as $line) {
65 | $debug[$line['type']][] = $line['msg'];
66 | }
67 |
68 | // 页面Trace信息
69 | $trace = [];
70 | foreach ($this->tabs as $name => $title) {
71 | $name = strtolower($name);
72 | switch ($name) {
73 | case 'base': // 基本信息
74 | $trace[$title] = $base;
75 | break;
76 | case 'file': // 文件信息
77 | $trace[$title] = $info;
78 | break;
79 | default: // 调试信息
80 | if (strpos($name, '|')) {
81 | // 多组信息
82 | $names = explode('|', $name);
83 | $result = [];
84 | foreach ($names as $name) {
85 | $result = array_merge($result, isset($debug[$name]) ? $debug[$name] : []);
86 | }
87 | $trace[$title] = $result;
88 | } else {
89 | $trace[$title] = isset($debug[$name]) ? $debug[$name] : '';
90 | }
91 | }
92 | }
93 | // 调用Trace页面模板
94 | ob_start();
95 | include $this->config['trace_file'];
96 | echo ob_get_clean();
97 | }
98 |
99 | }
100 |
--------------------------------------------------------------------------------
/thinkphp/library/think/model/Adv.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\model;
13 |
14 | T('model/Adv');
15 | T('model/Transaction');
16 |
17 | class Adv extends \think\Model
18 | {
19 | use \traits\model\Adv;
20 | use \traits\model\Transaction;
21 | }
22 |
--------------------------------------------------------------------------------
/thinkphp/library/think/model/Relation.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\model;
13 |
14 | T('model/Relation');
15 | class Relation extends \think\Model
16 | {
17 | use \traits\model\Relation;
18 | }
19 |
--------------------------------------------------------------------------------
/thinkphp/library/think/model/View.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\model;
13 |
14 | T('model/View');
15 | class View extends \think\Model
16 | {
17 | use \traits\model\View;
18 | }
19 |
--------------------------------------------------------------------------------
/thinkphp/library/think/process/Utils.php:
--------------------------------------------------------------------------------
1 |
8 | // +----------------------------------------------------------------------
9 |
10 | namespace think\process;
11 |
12 |
13 | class Utils
14 | {
15 |
16 | /**
17 | * 转义字符串
18 | * @param string $argument
19 | * @return string
20 | */
21 | public static function escapeArgument($argument)
22 | {
23 |
24 | if ('' === $argument) {
25 | return escapeshellarg($argument);
26 | }
27 | $escapedArgument = '';
28 | $quote = false;
29 | foreach (preg_split('/(")/i', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) {
30 | if ('"' === $part) {
31 | $escapedArgument .= '\\"';
32 | } elseif (self::isSurroundedBy($part, '%')) {
33 | // Avoid environment variable expansion
34 | $escapedArgument .= '^%"' . substr($part, 1, -1) . '"^%';
35 | } else {
36 | // escape trailing backslash
37 | if ('\\' === substr($part, -1)) {
38 | $part .= '\\';
39 | }
40 | $quote = true;
41 | $escapedArgument .= $part;
42 | }
43 | }
44 | if ($quote) {
45 | $escapedArgument = '"' . $escapedArgument . '"';
46 | }
47 | return $escapedArgument;
48 | }
49 |
50 | /**
51 | * 验证并进行规范化Process输入。
52 | * @param string $caller
53 | * @param mixed $input
54 | * @return string
55 | * @throws \InvalidArgumentException
56 | */
57 | public static function validateInput($caller, $input)
58 | {
59 | if (null !== $input) {
60 | if (is_resource($input)) {
61 | return $input;
62 | }
63 | if (is_scalar($input)) {
64 | return (string)$input;
65 | }
66 | throw new \InvalidArgumentException(sprintf('%s only accepts strings or stream resources.', $caller));
67 | }
68 | return $input;
69 | }
70 |
71 | private static function isSurroundedBy($arg, $char)
72 | {
73 | return 2 < strlen($arg) && $char === $arg[0] && $char === $arg[strlen($arg) - 1];
74 | }
75 |
76 | }
--------------------------------------------------------------------------------
/thinkphp/library/think/process/exception/Faild.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\process\exception;
13 |
14 |
15 | use think\Process;
16 |
17 | class Failed extends \RuntimeException
18 | {
19 |
20 | private $process;
21 |
22 | public function __construct(Process $process)
23 | {
24 | if ($process->isSuccessful()) {
25 | throw new \InvalidArgumentException('Expected a failed process, but the given process was successful.');
26 | }
27 |
28 | $error = sprintf('The command "%s" failed.' . "\nExit Code: %s(%s)", $process->getCommandLine(), $process->getExitCode(), $process->getExitCodeText());
29 |
30 | if (!$process->isOutputDisabled()) {
31 | $error .= sprintf("\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s", $process->getOutput(), $process->getErrorOutput());
32 | }
33 |
34 | parent::__construct($error);
35 |
36 | $this->process = $process;
37 | }
38 |
39 | public function getProcess()
40 | {
41 | return $this->process;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/thinkphp/library/think/process/exception/Timeout.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\process\exception;
13 |
14 |
15 | use think\Process;
16 |
17 | class Timeout extends \RuntimeException
18 | {
19 |
20 | const TYPE_GENERAL = 1;
21 | const TYPE_IDLE = 2;
22 |
23 | private $process;
24 | private $timeoutType;
25 |
26 | public function __construct(Process $process, $timeoutType)
27 | {
28 | $this->process = $process;
29 | $this->timeoutType = $timeoutType;
30 |
31 | parent::__construct(sprintf('The process "%s" exceeded the timeout of %s seconds.', $process->getCommandLine(), $this->getExceededTimeout()));
32 | }
33 |
34 | public function getProcess()
35 | {
36 | return $this->process;
37 | }
38 |
39 | public function isGeneralTimeout()
40 | {
41 | return $this->timeoutType === self::TYPE_GENERAL;
42 | }
43 |
44 | public function isIdleTimeout()
45 | {
46 | return $this->timeoutType === self::TYPE_IDLE;
47 | }
48 |
49 | public function getExceededTimeout()
50 | {
51 | switch ($this->timeoutType) {
52 | case self::TYPE_GENERAL:
53 | return $this->process->getTimeout();
54 |
55 | case self::TYPE_IDLE:
56 | return $this->process->getIdleTimeout();
57 |
58 | default:
59 | throw new \LogicException(sprintf('Unknown timeout type "%d".', $this->timeoutType));
60 | }
61 | }
62 | }
--------------------------------------------------------------------------------
/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 | /**
58 | * {@inheritdoc}
59 | */
60 | public function close()
61 | {
62 | foreach ($this->pipes as $pipe) {
63 | fclose($pipe);
64 | }
65 | $this->pipes = [];
66 | }
67 |
68 | /**
69 | * 检查系统调用已被中断
70 | * @return bool
71 | */
72 | protected function hasSystemCallBeenInterrupted()
73 | {
74 | $lastError = error_get_last();
75 |
76 | return isset($lastError['message']) && false !== stripos($lastError['message'], 'interrupted system call');
77 | }
78 |
79 | protected function unblock()
80 | {
81 | if (!$this->blocked) {
82 | return;
83 | }
84 |
85 | foreach ($this->pipes as $pipe) {
86 | stream_set_blocking($pipe, 0);
87 | }
88 | if (null !== $this->input) {
89 | stream_set_blocking($this->input, 0);
90 | }
91 |
92 | $this->blocked = false;
93 | }
94 | }
--------------------------------------------------------------------------------
/thinkphp/library/think/session/driver/Memcache.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\session\driver;
13 |
14 | use SessionHandler;
15 | use think\Exception;
16 |
17 | class Memcache extends SessionHandler
18 | {
19 | protected $handler = null;
20 | protected $config = [
21 | 'host' => '127.0.0.1', // memcache主机
22 | 'port' => 1121, // memcache端口
23 | 'expire' => 3600, // session有效期
24 | 'timeout' => 0, // 连接超时时间(单位:毫秒)
25 | 'persistent' => true, // 长连接
26 | 'session_name' => '', // memcache key前缀
27 | ];
28 |
29 | public function __construct($config = [])
30 | {
31 | $this->config = array_merge($this->config, $config);
32 | }
33 |
34 | /**
35 | * 打开Session
36 | * @access public
37 | * @param string $savePath
38 | * @param mixed $sessName
39 | */
40 | public function open($savePath, $sessName)
41 | {
42 | // 检测php环境
43 | if (!extension_loaded('memcache')) {
44 | throw new Exception('_NOT_SUPPERT_:memcache');
45 | }
46 | $this->handler = new \Memcache;
47 | // 支持集群
48 | $hosts = explode(',', $this->config['host']);
49 | $ports = explode(',', $this->config['port']);
50 | if (empty($ports[0])) {
51 | $ports[0] = 11211;
52 | }
53 | // 建立连接
54 | foreach ((array) $hosts as $i => $host) {
55 | $port = isset($ports[$i]) ? $ports[$i] : $ports[0];
56 | $this->config['timeout'] > 0 ?
57 | $this->handler->addServer($host, $port, $this->config['persistent'], 1, $this->config['timeout']) :
58 | $this->handler->addServer($host, $port, $this->config['persistent'], 1);
59 | }
60 | return true;
61 | }
62 |
63 | /**
64 | * 关闭Session
65 | * @access public
66 | */
67 | public function close()
68 | {
69 | $this->gc(ini_get('session.gc_maxlifetime'));
70 | $this->handler->close();
71 | $this->handler = null;
72 | return true;
73 | }
74 |
75 | /**
76 | * 读取Session
77 | * @access public
78 | * @param string $sessID
79 | */
80 | public function read($sessID)
81 | {
82 | return $this->handler->get($this->config['session_name'] . $sessID);
83 | }
84 |
85 | /**
86 | * 写入Session
87 | * @access public
88 | * @param string $sessID
89 | * @param String $sessData
90 | */
91 | public function write($sessID, $sessData)
92 | {
93 | return $this->handler->set($this->config['session_name'] . $sessID, $sessData, 0, $this->config['expire']);
94 | }
95 |
96 | /**
97 | * 删除Session
98 | * @access public
99 | * @param string $sessID
100 | */
101 | public function destroy($sessID)
102 | {
103 | return $this->handler->delete($this->config['session_name'] . $sessID);
104 | }
105 |
106 | /**
107 | * Session 垃圾回收
108 | * @access public
109 | * @param string $sessMaxLifeTime
110 | */
111 | public function gc($sessMaxLifeTime)
112 | {
113 | return true;
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/thinkphp/library/think/session/driver/Memcached.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\session\driver;
13 |
14 | use SessionHandler;
15 | use think\Exception;
16 |
17 | class Memcached extends SessionHandler
18 | {
19 | protected $handler = null;
20 | protected $config = [
21 | 'host' => '127.0.0.1', // memcache主机
22 | 'port' => 1121, // memcache端口
23 | 'expire' => 3600, // session有效期
24 | 'timeout' => 0, // 连接超时时间(单位:毫秒)
25 | 'session_name' => '', // memcache key前缀
26 | ];
27 |
28 | public function __construct($config = [])
29 | {
30 | $this->config = array_merge($this->config, $config);
31 | }
32 |
33 | /**
34 | * 打开Session
35 | * @access public
36 | * @param string $savePath
37 | * @param mixed $sessName
38 | */
39 | public function open($savePath, $sessName)
40 | {
41 | // 检测php环境
42 | if (!extension_loaded('memcached')) {
43 | throw new Exception('_NOT_SUPPERT_:memcached');
44 | }
45 | $this->handler = new \Memcached;
46 | // 设置连接超时时间(单位:毫秒)
47 | if ($this->config['timeout'] > 0) {
48 | $this->handler->setOption(\Memcached::OPT_CONNECT_TIMEOUT, $this->config['timeout']);
49 | }
50 | // 支持集群
51 | $hosts = explode(',', $this->config['host']);
52 | $ports = explode(',', $this->config['port']);
53 | if (empty($ports[0])) {
54 | $ports[0] = 11211;
55 | }
56 | // 建立连接
57 | $servers = [];
58 | foreach ((array) $hosts as $i => $host) {
59 | $servers[] = [$host, (isset($ports[$i]) ? $ports[$i] : $ports[0]), 1];
60 | }
61 | $this->handler->addServers($servers);
62 | return true;
63 | }
64 |
65 | /**
66 | * 关闭Session
67 | * @access public
68 | */
69 | public function close()
70 | {
71 | $this->gc(ini_get('session.gc_maxlifetime'));
72 | $this->handler->close();
73 | $this->handler = null;
74 | return true;
75 | }
76 |
77 | /**
78 | * 读取Session
79 | * @access public
80 | * @param string $sessID
81 | */
82 | public function read($sessID)
83 | {
84 | return $this->handler->get($this->config['session_name'] . $sessID);
85 | }
86 |
87 | /**
88 | * 写入Session
89 | * @access public
90 | * @param string $sessID
91 | * @param String $sessData
92 | */
93 | public function write($sessID, $sessData)
94 | {
95 | return $this->handler->set($this->config['session_name'] . $sessID, $sessData, $this->config['expire']);
96 | }
97 |
98 | /**
99 | * 删除Session
100 | * @access public
101 | * @param string $sessID
102 | */
103 | public function destroy($sessID)
104 | {
105 | return $this->handler->delete($this->config['session_name'] . $sessID);
106 | }
107 |
108 | /**
109 | * Session 垃圾回收
110 | * @access public
111 | * @param string $sessMaxLifeTime
112 | */
113 | public function gc($sessMaxLifeTime)
114 | {
115 | return true;
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/thinkphp/library/think/session/driver/Redis.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\session\driver;
13 |
14 | use SessionHandler;
15 | use think\Exception;
16 |
17 | class Redis extends SessionHandler
18 | {
19 | protected $handler = null;
20 | protected $config = [
21 | 'host' => '127.0.0.1', // redis主机
22 | 'port' => 6379, // redis端口
23 | 'password' => '', // 密码
24 | 'expire' => 3600, // 有效期(秒)
25 | 'timeout' => 0, // 超时时间(秒)
26 | 'persistent' => true, // 是否长连接
27 | 'session_name' => '', // sessionkey前缀
28 | ];
29 |
30 | public function __construct($config = [])
31 | {
32 | $this->config = array_merge($this->config, $config);
33 | }
34 |
35 | /**
36 | * 打开Session
37 | * @access public
38 | * @param string $savePath
39 | * @param mixed $sessName
40 | */
41 | public function open($savePath, $sessName)
42 | {
43 | // 检测php环境
44 | if (!extension_loaded('redis')) {
45 | throw new Exception('_NOT_SUPPERT_:redis');
46 | }
47 | $this->handler = new \Redis;
48 | // 建立连接
49 | $func = $this->config['persistent'] ? 'pconnect' : 'connect';
50 | $this->config['timeout'] > 0 ?
51 | $this->handler->$func($this->config['host'], $this->config['port'], $this->config['timeout']) :
52 | $this->handler->$func($this->config['host'], $this->config['port']);
53 | if ('' != $this->config['password']) {
54 | $this->handler->auth($this->config['password']);
55 | }
56 | return true;
57 | }
58 |
59 | /**
60 | * 关闭Session
61 | * @access public
62 | */
63 | public function close()
64 | {
65 | $this->gc(ini_get('session.gc_maxlifetime'));
66 | $this->handler->close();
67 | $this->handler = null;
68 | return true;
69 | }
70 |
71 | /**
72 | * 读取Session
73 | * @access public
74 | * @param string $sessID
75 | */
76 | public function read($sessID)
77 | {
78 | return $this->handler->get($this->config['session_name'] . $sessID);
79 | }
80 |
81 | /**
82 | * 写入Session
83 | * @access public
84 | * @param string $sessID
85 | * @param String $sessData
86 | */
87 | public function write($sessID, $sessData)
88 | {
89 | if ($this->config['expire'] > 0) {
90 | return $this->handler->setex($this->config['session_name'] . $sessID, $this->config['expire'], $sessData);
91 | } else {
92 | return $this->handler->set($this->config['session_name'] . $sessID, $sessData);
93 | }
94 | }
95 |
96 | /**
97 | * 删除Session
98 | * @access public
99 | * @param string $sessID
100 | */
101 | public function destroy($sessID)
102 | {
103 | return $this->handler->delete($this->config['session_name'] . $sessID);
104 | }
105 |
106 | /**
107 | * Session 垃圾回收
108 | * @access public
109 | * @param string $sessMaxLifeTime
110 | */
111 | public function gc($sessMaxLifeTime)
112 | {
113 | return true;
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/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 | // 写入编译缓存
19 | public function write($cacheFile, $content)
20 | {
21 | // 检测模板目录
22 | $dir = dirname($cacheFile);
23 | if (!is_dir($dir)) {
24 | mkdir($dir, 0777, true);
25 | }
26 | // 生成模板缓存文件
27 | if (false === file_put_contents($cacheFile, $content)) {
28 | throw new Exception('cache write error :' . $cacheFile, 11602);
29 | }
30 | }
31 |
32 | // 读取编译编译
33 | public function read($cacheFile, $vars)
34 | {
35 | // 模板阵列变量分解成为独立变量
36 | extract($vars, EXTR_OVERWRITE);
37 | //载入模版缓存文件
38 | include $cacheFile;
39 | }
40 |
41 | // 检查编译缓存是否有效
42 | public function check($template, $cacheFile, $cacheTime)
43 | {
44 | if (!is_file($cacheFile) || (is_file($template) && filemtime($template) > filemtime($cacheFile))) {
45 | // 模板文件如果有更新则缓存需要更新
46 | return false;
47 | } elseif (0 != $cacheTime && time() > filemtime($cacheFile) + $cacheTime) {
48 | // 缓存是否在有效期
49 | return false;
50 | }
51 | return true;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/thinkphp/library/think/template/driver/Sae.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\template\driver;
13 |
14 | use think\Exception;
15 |
16 | class Sae
17 | {
18 | // mc 对象
19 | private $mc;
20 | // 编译缓存内容
21 | private $contents = [];
22 |
23 | /**
24 | * 架构函数
25 | * @access public
26 | */
27 | public function __construct()
28 | {
29 | if (!function_exists('memcache_init')) {
30 | throw new Exception('请在SAE平台上运行代码。');
31 | }
32 | $this->mc = @memcache_init();
33 | if (!$this->mc) {
34 | throw new Exception('您未开通Memcache服务,请在SAE管理平台初始化Memcache服务');
35 | }
36 | }
37 |
38 | // 写入编译缓存
39 | public function write($cacheFile, $content)
40 | {
41 | // 添加写入时间
42 | $content = time() . $content;
43 | if (!$this->mc->set($cacheFile, $content, MEMCACHE_COMPRESSED, 0)) {
44 | throw new Exception('sae mc write error :' . $cacheFile);
45 | } else {
46 | $this->contents[$cacheFile] = $content;
47 | return true;
48 | }
49 | }
50 |
51 | // 读取编译编译
52 | public function read($cacheFile, $vars)
53 | {
54 | if (!is_null($vars)) {
55 | extract($vars, EXTR_OVERWRITE);
56 | }
57 | eval('?>' . $this->get($cacheFile, 'content'));
58 | }
59 |
60 | // 检查编译缓存是否有效
61 | public function check($template, $cacheFile, $cacheTime)
62 | {
63 | $mtime = $this->get($cacheFile, 'mtime');
64 | if (!$this->get($cacheFile, 'content') || (is_file($template) && filemtime($template) > $mtime)) {
65 | // 模板文件如果有更新则缓存需要更新
66 | return false;
67 | }if (0 != $cacheTime && time() > $mtime + $cacheTime) {
68 | // 缓存是否在有效期
69 | return false;
70 | } else {
71 | return true;
72 | }
73 | }
74 |
75 | /**
76 | * 读取文件信息
77 | * @access private
78 | * @param string $filename 文件名
79 | * @param string $name 信息名 mtime或者content
80 | * @return boolean
81 | */
82 | private function get($filename, $name)
83 | {
84 | if (!isset($this->contents[$filename])) {
85 | $this->contents[$filename] = $this->mc->get($filename);
86 | }
87 | $content = $this->contents[$filename];
88 |
89 | if (false === $content) {
90 | return false;
91 | }
92 | $info = array(
93 | 'mtime' => substr($content, 0, 10),
94 | 'content' => substr($content, 10),
95 | );
96 | return $info[$name];
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/thinkphp/library/think/view/driver/Think.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think\view\driver;
13 |
14 | use think\Template;
15 |
16 | class Think
17 | {
18 | private $template = null;
19 | public function __construct($config = [])
20 | {
21 | $this->template = new Template($config);
22 | }
23 |
24 | public function fetch($template, $data = [], $cache = [])
25 | {
26 | if (is_file($template)) {
27 | $this->template->display($template, $data, $cache);
28 | } else {
29 | $this->template->fetch($template, $data);
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/thinkphp/library/traits/controller/Jump.php:
--------------------------------------------------------------------------------
1 | error();
11 | * $this->redirect();
12 | * }
13 | * }
14 | */
15 | namespace traits\controller;
16 |
17 | use think\Response;
18 |
19 | trait Jump
20 | {
21 | /**
22 | * 操作错误跳转的快捷方法
23 | * @access public
24 | * @param mixed $msg 提示信息
25 | * @param string $url 跳转的URL地址
26 | * @param mixed $data 返回的数据
27 | * @param integer $wait 跳转等待时间
28 | * @return mixed
29 | */
30 | public function error($msg = '', $url = null, $data = '', $wait = 3)
31 | {
32 | return Response::error($msg, $data, $url, $wait);
33 | }
34 |
35 | /**
36 | * 操作成功跳转的快捷方法
37 | * @access public
38 | * @param mixed $msg 提示信息
39 | * @param string $url 跳转的URL地址
40 | * @param mixed $data 返回的数据
41 | * @param integer $wait 跳转等待时间
42 | * @return mixed
43 | */
44 | public function success($msg = '', $url = null, $data = '', $wait = 3)
45 | {
46 | return Response::success($msg, $data, $url, $wait);
47 | }
48 |
49 | /**
50 | * 返回封装后的API数据到客户端
51 | * @access public
52 | * @param mixed $data 要返回的数据
53 | * @param integer $code 返回的code
54 | * @param mixed $msg 提示信息
55 | * @param string $type 返回数据格式
56 | * @return mixed
57 | */
58 | public function result($data, $code = 0, $msg = '', $type = '')
59 | {
60 | return Response::result($data, $code, $msg, $type);
61 | }
62 |
63 | /**
64 | * URL重定向
65 | * @access protected
66 | * @param string $url 跳转的URL表达式
67 | * @param array|int $params 其它URL参数或http code
68 | * @return void
69 | */
70 | public function redirect($url, $params = [])
71 | {
72 | Response::redirect($url, $params);
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/thinkphp/library/traits/controller/View.php:
--------------------------------------------------------------------------------
1 | assign();
11 | * $this->show();
12 | * }
13 | * }
14 | */
15 | namespace traits\controller;
16 |
17 | use think\Config;
18 |
19 | trait View
20 | {
21 | // 视图类实例
22 | protected $view = null;
23 |
24 | /**
25 | * 架构函数 初始化视图类 并采用内置模板引擎
26 | * @access public
27 | */
28 | public function initView()
29 | {
30 | // 模板引擎参数
31 | if (is_null($this->view)) {
32 | $this->view = \think\View::instance(Config::get()); // 只能这样写,不然view会冲突
33 | }
34 | }
35 |
36 | /**
37 | * 加载模板和页面输出 可以返回输出内容
38 | * @access public
39 | * @param string $template 模板文件名
40 | * @param array $vars 模板输出变量
41 | * @param string $cache_id 模板缓存标识
42 | * @return mixed
43 | */
44 | public function fetch($template = '', $vars = [], $cache_id = '')
45 | {
46 | $this->initView();
47 | return $this->view->fetch($template, $vars, $cache_id);
48 | }
49 |
50 | /**
51 | * 渲染内容输出
52 | * @access public
53 | * @param string $content 内容
54 | * @param array $vars 模板输出变量
55 | * @return mixed
56 | */
57 | public function show($content, $vars = [])
58 | {
59 | $this->initView();
60 | return $this->view->show($content, $vars);
61 | }
62 |
63 | /**
64 | * 模板变量赋值
65 | * @access protected
66 | * @param mixed $name 要显示的模板变量
67 | * @param mixed $value 变量的值
68 | * @return void
69 | */
70 | public function assign($name, $value = '')
71 | {
72 | $this->initView();
73 | $this->view->assign($name, $value);
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/thinkphp/library/traits/model/Transaction.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace traits\model;
13 |
14 | trait Transaction
15 | {
16 |
17 | /**
18 | * 启动事务
19 | * @access public
20 | * @return void
21 | */
22 | public function startTrans()
23 | {
24 | $this->commit();
25 | $this->db->startTrans();
26 | return;
27 | }
28 |
29 | /**
30 | * 提交事务
31 | * @access public
32 | * @return boolean
33 | */
34 | public function commit()
35 | {
36 | return $this->db->commit();
37 | }
38 |
39 | /**
40 | * 事务回滚
41 | * @access public
42 | * @return boolean
43 | */
44 | public function rollback()
45 | {
46 | return $this->db->rollback();
47 | }
48 |
49 | /**
50 | * 批处理执行SQL语句
51 | * 批处理的指令都认为是execute操作
52 | * @access public
53 | * @param array $sql SQL批处理指令
54 | * @return boolean
55 | */
56 | public function patchQuery($sql = [])
57 | {
58 | if (!is_array($sql)) {
59 | return false;
60 | }
61 | // 自动启动事务支持
62 | $this->startTrans();
63 | try {
64 | foreach ($sql as $_sql) {
65 | $result = $this->execute($_sql);
66 | if (false === $result) {
67 | // 发生错误自动回滚事务
68 | $this->rollback();
69 | return false;
70 | }
71 | }
72 | // 提交事务
73 | $this->commit();
74 | } catch (\think\exception $e) {
75 | $this->rollback();
76 | return false;
77 | }
78 | return true;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/thinkphp/library/traits/think/Instance.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace traits\think;
13 |
14 | trait Instance
15 | {
16 | protected static $instance = null;
17 |
18 | // 实例化(单例)
19 | public static function instance($options = [])
20 | {
21 | if (is_null(self::$instance)) {
22 | self::$instance = new self($options);
23 | }
24 | return self::$instance;
25 | }
26 |
27 | // 静态调用
28 | public static function __callStatic($method, $params)
29 | {
30 | if (is_null(self::$instance)) {
31 | self::$instance = new self();
32 | }
33 | $call = substr($method, 1);
34 | if (0 === strpos($method, '_') && is_callable([self::$instance, $call])) {
35 | return call_user_func_array([self::$instance, $call], $params);
36 | } else {
37 | throw new \think\Exception("not exists method:" . $method);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/thinkphp/mode/common.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | /**
13 | * ThinkPHP 普通模式定义
14 | */
15 | return [
16 | // 命名空间
17 | 'namespace' => [
18 | 'think' => LIB_PATH . 'think' . DS,
19 | 'behavior' => LIB_PATH . 'behavior' . DS,
20 | 'traits' => LIB_PATH . 'traits' . DS,
21 | APP_NAMESPACE => APP_PATH,
22 | ],
23 |
24 | // 配置文件
25 | 'config' => THINK_PATH . 'convention' . EXT,
26 |
27 | // 别名定义
28 | 'alias' => [
29 | 'think\App' => CORE_PATH . 'App' . EXT,
30 | 'think\Build' => CORE_PATH . 'Build' . EXT,
31 | 'think\Cache' => CORE_PATH . 'Cache' . EXT,
32 | 'think\Config' => CORE_PATH . 'Config' . EXT,
33 | 'think\Controller' => CORE_PATH . 'Controller' . EXT,
34 | 'think\Cookie' => CORE_PATH . 'Cookie' . EXT,
35 | 'think\Db' => CORE_PATH . 'Db' . EXT,
36 | 'think\Debug' => CORE_PATH . 'Debug' . EXT,
37 | 'think\Error' => CORE_PATH . 'Error' . EXT,
38 | 'think\Exception' => CORE_PATH . 'Exception' . EXT,
39 | 'think\Hook' => CORE_PATH . 'Hook' . EXT,
40 | 'think\Input' => CORE_PATH . 'Input' . EXT,
41 | 'think\Lang' => CORE_PATH . 'Lang' . EXT,
42 | 'think\Log' => CORE_PATH . 'Log' . EXT,
43 | 'think\Model' => CORE_PATH . 'Model' . EXT,
44 | 'think\Response' => CORE_PATH . 'Response' . EXT,
45 | 'think\Route' => CORE_PATH . 'Route' . EXT,
46 | 'think\Session' => CORE_PATH . 'Session' . EXT,
47 | 'think\Template' => CORE_PATH . 'Template' . EXT,
48 | 'think\Url' => CORE_PATH . 'Url' . EXT,
49 | 'think\View' => CORE_PATH . 'View' . EXT,
50 | 'think\db\Driver' => CORE_PATH . 'db' . DS . 'Driver' . EXT,
51 | 'think\view\driver\Think' => CORE_PATH . 'view' . DS . 'driver' . DS . 'Think' . EXT,
52 | 'think\template\driver\File' => CORE_PATH . 'template' . DS . 'driver' . DS . 'File' . EXT,
53 | 'think\log\driver\File' => CORE_PATH . 'log' . DS . 'driver' . DS . 'File' . EXT,
54 | 'think\cache\driver\File' => CORE_PATH . 'cache' . DS . 'driver' . DS . 'File' . EXT,
55 | ],
56 | ];
57 |
--------------------------------------------------------------------------------
/thinkphp/mode/console.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | /**
13 | * ThinkPHP CLI模式定义
14 | */
15 | return [
16 |
17 | // 命名空间
18 | 'namespace' => [
19 | 'think' => LIB_PATH . 'think' . DS,
20 | 'behavior' => LIB_PATH . 'behavior' . DS,
21 | 'traits' => LIB_PATH . 'traits' . DS,
22 | APP_NAMESPACE => APP_PATH,
23 | ],
24 |
25 | 'config' => [
26 | 'commands' => [],
27 | ],
28 |
29 | ];
30 |
--------------------------------------------------------------------------------
/thinkphp/phpunit.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 | ./tests/thinkphp/
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | ./
23 |
24 | tests
25 | vendor
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/thinkphp/start.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | namespace think;
13 |
14 | // ThinkPHP 引导文件
15 | // 加载基础文件
16 | require __DIR__ . '/base.php';
17 | require CORE_PATH . 'Loader.php';
18 |
19 | // 注册自动加载
20 | Loader::register();
21 |
22 | // 加载模式定义文件
23 | $mode = require MODE_PATH . APP_MODE . EXT;
24 |
25 | // 加载空间别名定义
26 | if (isset($mode['namespace'])) {
27 | Loader::addNamespace($mode['namespace']);
28 | }
29 |
30 | // 加载模式别名定义
31 | if (isset($mode['alias'])) {
32 | Loader::addMap(is_array($mode['alias']) ? $mode['alias'] : include $mode['alias']);
33 | }
34 |
35 | // 注册错误和异常处理机制
36 | Error::register();
37 |
38 | // 加载模式配置文件
39 | if (isset($mode['config'])) {
40 | is_array($mode['config']) ? Config::set($mode['config']) : Config::load($mode['config']);
41 | }
42 |
43 | // 加载模式行为定义
44 | if (APP_HOOK && isset($mode['tags'])) {
45 | Hook::import(is_array($mode['tags']) ? $mode['tags'] : include $mode['tags']);
46 | }
47 |
48 | // 自动生成
49 | if (APP_AUTO_BUILD && is_file(APP_PATH . 'build.php')) {
50 | Build::run(include APP_PATH . 'build.php');
51 | }
52 |
53 | // 是否自动运行
54 | if (APP_AUTO_RUN) {
55 | App::run();
56 | }
57 |
--------------------------------------------------------------------------------
/thinkphp/tests/README.md:
--------------------------------------------------------------------------------
1 | ## 测试目录结构
2 |
3 | 测试文件主要在 tests 文件下面,主要有以下几个文件夹
4 |
5 | - conf 测试环境配置文件。
6 | - script 测试环境配置脚本。
7 | - thinkphp 测试用例和相关文件,与项目文件夹机构一致。
8 | - mock.php 测试入口文件。
9 |
10 | ## 主要测试流程
11 |
12 | thinkphp5 的测试的主要流程是跟 thinkphp 的系统流程是相似的,大体的流程为:
13 |
14 | 1. 引用 mock.php 文件加载框架
15 |
16 | 2. 根据文件目录,添加测试文件
17 |
18 | 3. 执行单元测试,输出结果
19 |
20 | ## 测试举例
21 |
22 | 例如测试 thinkphp 里的 apc 缓存,将分为以下几个过程:
23 |
24 | 1. 创建 apcTest.php 文件
25 |
26 | 该文件应与 apc.php 目录路径 `thinkphp/library/think/cache/driver` 一致,命名空间与目录所在一致,并引用 `PHPUnit_Framework_TestCase`。
27 |
28 | ```php
29 | markTestSkipped('apc扩展不可用!');
56 | };
57 | ```
58 |
59 | - 编写测试用例
60 |
61 | *具体写法参照 [PHPUnit 官方文档](https://phpunit.de/manual/4.8/zh_cn/index.html)*
62 |
63 | ```php
64 | public function testGet()
65 | {
66 | App::run();
67 | $this->assertInstanceOf(
68 | '\think\cache\driver\Apc',
69 | Cache::connect(['type' => 'apc', 'expire' => 1])
70 | );
71 | $this->assertTrue(Cache::set('key', 'value'));
72 | $this->assertEquals('value', Cache::get('key'));
73 | $this->assertTrue(Cache::rm('key'));
74 | $this->assertFalse(Cache::get('key'));
75 | $this->assertTrue(Cache::clear('key'));
76 | Config::reset();
77 | }
78 | ```
79 |
80 | 3. 执行单元测试命令
81 |
82 | 在项目根目录执行
83 |
84 | ```bash
85 | $ phpunit
86 | ```
87 |
88 | 若想看到所有结果,请添加-v参数
89 |
90 | ```bash
91 | $ phpunit -v
92 | ```
93 |
94 | 4. 输出结果
95 |
96 | ## 相关文档
97 |
98 | [各个部分单元测试说明](http://www.kancloud.cn/brother_simon/tp5_test/96971 "各部分单元测试说明")
99 |
100 | ## 大家一起来
101 |
102 | 单元测试的内容会跟框架同步,测试内容方方面面,是一个相对复杂的模块,同时也是一个值得重视的部分。希望大家能够多多提出意见,多多参与。如果你有任何问题或想法,可以随时提 issue,我们期待着收到听大家的质疑和讨论。
103 |
104 | ## 任务进度
105 |
106 | 单元测试任务进度,请大家认领模块
107 |
108 | |模块|认领人|进度|
109 | |---|---|---|
110 | |Base|||
111 | |App|Haotong Lin||
112 | |Build|||
113 | |Config|Haotong Lin||
114 | |Cache|||
115 | |Controller|Haotong Lin||
116 | |Cookie|Haotong Lin||
117 | |Db|||
118 | |Debug|大漠|√|
119 | |Error|大漠||
120 | |Hook|||
121 | |Input|Haotong Lin||
122 | |Lang|||
123 | |Loader|||
124 | |Log|||
125 | |Model|||
126 | |Response|大漠|√|
127 | |Route|||
128 | |Session|大漠|√|
129 | |Template|Haotong Lin||
130 | |Url|||
131 | |View|mahuan||
132 |
--------------------------------------------------------------------------------
/thinkphp/tests/conf/apcu.ini:
--------------------------------------------------------------------------------
1 | extension=apcu.so
2 |
3 | apc.enable_cli=1
4 |
--------------------------------------------------------------------------------
/thinkphp/tests/conf/apcu_bc.ini:
--------------------------------------------------------------------------------
1 | extension=apcu.so
2 | extension=apc.so
3 |
4 | apc.enable_cli=1
5 |
--------------------------------------------------------------------------------
/thinkphp/tests/conf/memcached.ini:
--------------------------------------------------------------------------------
1 | extension=memcached.so
2 |
--------------------------------------------------------------------------------
/thinkphp/tests/conf/redis.ini:
--------------------------------------------------------------------------------
1 | extension=redis.so
2 |
--------------------------------------------------------------------------------
/thinkphp/tests/extensions/5.4/apcu.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lwl12/LWL-API/3b6fd88a58ec60fc8cc9587939e55bcb45431ce9/thinkphp/tests/extensions/5.4/apcu.so
--------------------------------------------------------------------------------
/thinkphp/tests/extensions/5.5/apcu.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lwl12/LWL-API/3b6fd88a58ec60fc8cc9587939e55bcb45431ce9/thinkphp/tests/extensions/5.5/apcu.so
--------------------------------------------------------------------------------
/thinkphp/tests/extensions/5.6/apcu.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lwl12/LWL-API/3b6fd88a58ec60fc8cc9587939e55bcb45431ce9/thinkphp/tests/extensions/5.6/apcu.so
--------------------------------------------------------------------------------
/thinkphp/tests/extensions/7.0/apc.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lwl12/LWL-API/3b6fd88a58ec60fc8cc9587939e55bcb45431ce9/thinkphp/tests/extensions/7.0/apc.so
--------------------------------------------------------------------------------
/thinkphp/tests/extensions/7.0/apcu.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lwl12/LWL-API/3b6fd88a58ec60fc8cc9587939e55bcb45431ce9/thinkphp/tests/extensions/7.0/apcu.so
--------------------------------------------------------------------------------
/thinkphp/tests/extensions/7.0/memcached.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lwl12/LWL-API/3b6fd88a58ec60fc8cc9587939e55bcb45431ce9/thinkphp/tests/extensions/7.0/memcached.so
--------------------------------------------------------------------------------
/thinkphp/tests/extensions/7.0/redis.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lwl12/LWL-API/3b6fd88a58ec60fc8cc9587939e55bcb45431ce9/thinkphp/tests/extensions/7.0/redis.so
--------------------------------------------------------------------------------
/thinkphp/tests/mock.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | // 测试入口文件
13 | $_SERVER['REQUEST_METHOD'] = 'GET';
14 |
15 | // 定义项目测试基础路径
16 | define('TEST_PATH', __DIR__ . '/');
17 |
18 | // 定义项目路径
19 | define('APP_PATH', __DIR__ . '/../../application/');
20 | // 开启调试模式
21 | define('APP_DEBUG', true);
22 |
23 | // 加载框架引导文件
24 | require __DIR__ . '/../start.php';
25 | \think\Loader::addNamespace('tests', TEST_PATH);
26 |
--------------------------------------------------------------------------------
/thinkphp/tests/script/install.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | if [ $(phpenv version-name) != "hhvm" ]; then
4 | cp thinkphp/tests/extensions/$(phpenv version-name)/*.so $(php-config --extension-dir)
5 |
6 | if [ $(phpenv version-name) = "7.0" ]; then
7 | phpenv config-add thinkphp/tests/conf/apcu_bc.ini
8 | else
9 | phpenv config-add thinkphp/tests/conf/apcu.ini
10 | fi
11 |
12 | phpenv config-add thinkphp/tests/conf/memcached.ini
13 | phpenv config-add thinkphp/tests/conf/redis.ini
14 | fi
15 |
16 | composer install --no-interaction --ignore-platform-reqs
17 |
--------------------------------------------------------------------------------
/thinkphp/tests/thinkphp/baseTest.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | /**
13 | * 保证运行环境正常
14 | */
15 | class baseTest extends \PHPUnit_Framework_TestCase
16 | {
17 | public function testConstants()
18 | {
19 | $this->assertNotEmpty(START_TIME);
20 | $this->assertNotEmpty(START_MEM);
21 | $this->assertNotEmpty(THINK_VERSION);
22 | $this->assertNotEmpty(DS);
23 | $this->assertNotEmpty(THINK_PATH);
24 | $this->assertNotEmpty(LIB_PATH);
25 | $this->assertNotEmpty(EXTEND_PATH);
26 | $this->assertNotEmpty(MODE_PATH);
27 | $this->assertNotEmpty(CORE_PATH);
28 | $this->assertNotEmpty(ORG_PATH);
29 | $this->assertNotEmpty(TRAIT_PATH);
30 | $this->assertNotEmpty(APP_PATH);
31 | $this->assertNotEmpty(APP_NAMESPACE);
32 | $this->assertNotEmpty(COMMON_MODULE);
33 | $this->assertNotEmpty(RUNTIME_PATH);
34 | $this->assertNotEmpty(DATA_PATH);
35 | $this->assertNotEmpty(LOG_PATH);
36 | $this->assertNotEmpty(CACHE_PATH);
37 | $this->assertNotEmpty(TEMP_PATH);
38 | $this->assertNotEmpty(VENDOR_PATH);
39 | $this->assertNotEmpty(EXT);
40 | $this->assertNotEmpty(MODEL_LAYER);
41 | $this->assertNotEmpty(VIEW_LAYER);
42 | $this->assertNotEmpty(CONTROLLER_LAYER);
43 | $this->assertTrue(is_bool(APP_DEBUG));
44 | $this->assertTrue(is_bool(APP_HOOK));
45 | $this->assertNotEmpty(ENV_PREFIX);
46 | $this->assertTrue(is_bool(IS_API));
47 | $this->assertTrue(is_bool(APP_AUTO_BUILD));
48 | $this->assertNotEmpty(APP_MODE);
49 | $this->assertTrue(!is_null(IS_CGI));
50 | $this->assertTrue(!is_null(IS_WIN));
51 | $this->assertTrue(!is_null(IS_CLI));
52 | $this->assertTrue(is_bool(IS_AJAX));
53 | $this->assertNotEmpty(NOW_TIME);
54 | $this->assertNotEmpty(REQUEST_METHOD);
55 | $this->assertTrue(is_bool(IS_GET));
56 | $this->assertTrue(is_bool(IS_POST));
57 | $this->assertTrue(is_bool(IS_PUT));
58 | $this->assertTrue(is_bool(IS_DELETE));
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/thinkphp/tests/thinkphp/library/think/appTest.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | /**
13 | * app类测试
14 | * @author Haotong Lin
15 | */
16 |
17 | namespace tests\thinkphp\library\think;
18 |
19 | class appTest extends \PHPUnit_Framework_TestCase
20 | {
21 | public function testRun()
22 | {
23 | //\think\App::run();
24 | //$this->expectOutputString('');
25 | // todo...
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/thinkphp/tests/thinkphp/library/think/cache/driver/apcTest.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | /**
13 | * Apc缓存驱动测试
14 | * @author mahuan
15 | */
16 |
17 | namespace tests\thinkphp\library\think\cache\driver;
18 |
19 | class apcTest extends cacheTestCase
20 | {
21 | private $_cacheInstance = null;
22 | /**
23 | * 基境缓存类型
24 | */
25 | protected function setUp()
26 | {
27 | if (!extension_loaded("apc")) {
28 | $this->markTestSkipped("APC没有安装,已跳过测试!");
29 | } elseif ('cli' === PHP_SAPI && !ini_get('apc.enable_cli')) {
30 | $this->markTestSkipped("APC模块没有开启,已跳过测试!");
31 | }
32 | \think\Cache::connect(array('type' => 'apc', 'expire' => 2));
33 | }
34 | /**
35 | * @return ApcCache
36 | */
37 | protected function getCacheInstance()
38 | {
39 | if (null === $this->_cacheInstance) {
40 | $this->_cacheInstance = new \think\cache\driver\Apc();
41 | }
42 | return $this->_cacheInstance;
43 | }
44 | /**
45 | * 缓存过期测试《提出来测试,因为目前看通不过缓存过期测试,所以还需研究》
46 | * @return mixed
47 | * @access public
48 | */
49 | public function testExpire()
50 | {
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/thinkphp/tests/thinkphp/library/think/cache/driver/dbTest.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | /**
13 | * 数据库缓存驱动测试
14 | * @author mahuan
15 | */
16 |
17 | namespace tests\thinkphp\library\think\cache\driver;
18 |
19 | class dbTest extends cacheTestCase
20 | {
21 | private $_cacheInstance = null;
22 |
23 | /**
24 | * 基境缓存类型
25 | */
26 | protected function setUp()
27 | {
28 | //数据库缓存测试因为缺少数据库单元测试所以暂时跳过
29 | $this->markTestSkipped("暂时跳过测试。");
30 | \think\Cache::connect(array('type' => 'db', 'expire' => 2));
31 | }
32 |
33 | /**
34 | * @return DbCache
35 | */
36 | protected function getCacheInstance()
37 | {
38 | if (null === $this->_cacheInstance) {
39 | $this->_cacheInstance = new \think\cache\driver\Db();
40 | }
41 | return $this->_cacheInstance;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/thinkphp/tests/thinkphp/library/think/cache/driver/memcachedTest.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | /**
13 | * Memcached缓存驱动测试
14 | * @author 7IN0SAN9
15 | */
16 |
17 | namespace tests\thinkphp\library\think\cache\driver;
18 |
19 | class memcachedTest extends cacheTestCase
20 | {
21 | private $_cacheInstance = null;
22 | /**
23 | * 基境缓存类型
24 | */
25 | protected function setUp()
26 | {
27 | if (!extension_loaded("memcached") && !extension_loaded('memcache')) {
28 | $this->markTestSkipped("Memcached或Memcache没有安装,已跳过测试!");
29 | }
30 | \think\Cache::connect(array('type' => 'memcached', 'expire' => 2));
31 | }
32 | /**
33 | * @return ApcCache
34 | */
35 | protected function getCacheInstance()
36 | {
37 | if (null === $this->_cacheInstance) {
38 | $this->_cacheInstance = new \think\cache\driver\Memcached();
39 | }
40 | return $this->_cacheInstance;
41 | }
42 | /**
43 | * 缓存过期测试《提出来测试,因为目前看通不过缓存过期测试,所以还需研究》
44 | * @return mixed
45 | * @access public
46 | */
47 | public function testExpire()
48 | {
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/thinkphp/tests/thinkphp/library/think/cache/driver/redisTest.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | /**
13 | * Redis缓存驱动测试
14 | * @author 7IN0SAN9
15 | */
16 |
17 | namespace tests\thinkphp\library\think\cache\driver;
18 |
19 | class redisTest extends cacheTestCase
20 | {
21 | private $_cacheInstance = null;
22 |
23 | protected function setUp()
24 | {
25 | if (!extension_loaded("redis")) {
26 | $this->markTestSkipped("Redis没有安装,已跳过测试!");
27 | }
28 | \think\Cache::connect(array('type' => 'redis', 'expire' => 2));
29 | }
30 |
31 | protected function getCacheInstance()
32 | {
33 | if (null === $this->_cacheInstance) {
34 | $this->_cacheInstance = new \think\cache\driver\Redis();
35 | }
36 | return $this->_cacheInstance;
37 | }
38 |
39 | public function testGet()
40 | {
41 | $cache = $this->prepare();
42 | $this->assertEquals('string_test', $cache->get('string_test'));
43 | $this->assertEquals(11, $cache->get('number_test'));
44 | }
45 |
46 | public function testStoreSpecialValues()
47 | {
48 | }
49 |
50 | public function testExpire()
51 | {
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/thinkphp/tests/thinkphp/library/think/config/driver/fixtures/config.ini:
--------------------------------------------------------------------------------
1 | inifile=1
--------------------------------------------------------------------------------
/thinkphp/tests/thinkphp/library/think/config/driver/fixtures/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 1
5 |
6 |
--------------------------------------------------------------------------------
/thinkphp/tests/thinkphp/library/think/config/driver/iniTest.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | /**
13 | * Ini配置测试
14 | * @author 7IN0SAN9
15 | */
16 |
17 | namespace tests\thinkphp\library\think\config\driver;
18 |
19 | use think\config;
20 |
21 | class iniTest extends \PHPUnit_Framework_TestCase
22 | {
23 | public function testParse()
24 | {
25 | Config::parse('inistring=1', 'ini');
26 | $this->assertEquals(1, Config::get('inistring'));
27 | Config::reset();
28 | Config::parse(__DIR__ . '/fixtures/config.ini');
29 | $this->assertTrue(Config::has('inifile'));
30 | $this->assertEquals(1, Config::get('inifile'));
31 | Config::reset();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/thinkphp/tests/thinkphp/library/think/config/driver/xmlTest.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | /**
13 | * Xml配置测试
14 | * @author 7IN0SAN9
15 | */
16 |
17 | namespace tests\thinkphp\library\think\config\driver;
18 |
19 | use think\config;
20 |
21 | class xmlTest extends \PHPUnit_Framework_TestCase
22 | {
23 | public function testParse()
24 | {
25 | Config::parse('1', 'xml');
26 | $this->assertEquals(1, Config::get('xmlstring'));
27 | Config::reset();
28 | Config::parse(__DIR__ . '/fixtures/config.xml');
29 | $this->assertTrue(Config::has('xmlfile.istrue'));
30 | $this->assertEquals(1, Config::get('xmlfile.istrue'));
31 | Config::reset();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/thinkphp/tests/thinkphp/library/think/controller/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/thinkphp/tests/thinkphp/library/think/controllerTest.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | /**
13 | * 控制器测试
14 | * @author Haotong Lin
15 | */
16 |
17 | namespace tests\thinkphp\library\think;
18 |
19 | require_once CORE_PATH . '../../helper.php';
20 |
21 | class Foo extends \think\Controller
22 | {
23 | public $test = 'test';
24 |
25 | public function _initialize()
26 | {
27 | $this->test = 'abcd';
28 | }
29 | }
30 |
31 | class Bar extends \think\Controller
32 | {
33 | public $test = 1;
34 |
35 | public $beforeActionList = ['action1', 'action2'];
36 |
37 | public function action1()
38 | {
39 | $this->test += 2;
40 | return 'action1';
41 | }
42 |
43 | public function action2()
44 | {
45 | $this->test += 4;
46 | return 'action2';
47 | }
48 | }
49 |
50 | class Baz extends \think\Controller
51 | {
52 | public $test = 1;
53 |
54 | public $beforeActionList = [
55 | 'action1' => ['only' => ['index']],
56 | 'action2' => ['except' => ['index']],
57 | 'action3' => ['only' => ['abcd']],
58 | 'action4' => ['except' => ['abcd']],
59 | ];
60 |
61 | public function action1()
62 | {
63 | $this->test += 2;
64 | return 'action1';
65 | }
66 |
67 | public function action2()
68 | {
69 | $this->test += 4;
70 | return 'action2';
71 | }
72 |
73 | public function action3()
74 | {
75 | $this->test += 8;
76 | return 'action2';
77 | }
78 |
79 | public function action4()
80 | {
81 | $this->test += 16;
82 | return 'action2';
83 | }
84 | }
85 |
86 | define('ACTION_NAME', 'index');
87 |
88 | class controllerTest extends \PHPUnit_Framework_TestCase
89 | {
90 | public function testInitialize()
91 | {
92 | $foo = new Foo;
93 | $this->assertEquals('abcd', $foo->test);
94 | }
95 |
96 | public function testBeforeAction()
97 | {
98 | $obj = new Bar;
99 | $this->assertEquals(7, $obj->test);
100 |
101 | $obj = new Baz;
102 | $this->assertEquals(19, $obj->test);
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/thinkphp/tests/thinkphp/library/think/db/driver/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/thinkphp/tests/thinkphp/library/think/display.html:
--------------------------------------------------------------------------------
1 | {$name??'default'}
--------------------------------------------------------------------------------
/thinkphp/tests/thinkphp/library/think/extend.html:
--------------------------------------------------------------------------------
1 | {extend name="extend2" /}
2 | {block name="mainbody"}
3 | mainbody
4 | {/block}
--------------------------------------------------------------------------------
/thinkphp/tests/thinkphp/library/think/extend2.html:
--------------------------------------------------------------------------------
1 | {layout name="layout" replace="[__REPLACE__]" /}
2 |
3 | {include file="include" name="info" value="$info.value" /}
4 | {block name="main"}
5 | {block name="side"}
6 | side
7 | {/block}
8 | {block name="mainbody"}
9 |
10 | {/block}
11 | {/block}
12 | {literal}
13 | {$name}
14 | {/literal}
15 |
16 |
--------------------------------------------------------------------------------
/thinkphp/tests/thinkphp/library/think/include.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/thinkphp/tests/thinkphp/library/think/layout.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/thinkphp/tests/thinkphp/library/think/log/driver/fileTest.php:
--------------------------------------------------------------------------------
1 |
10 | // +----------------------------------------------------------------------
11 |
12 | /**
13 | * Test File Log
14 | */
15 | namespace tests\thinkphp\library\think\log\driver;
16 |
17 | use think\Log;
18 |
19 | class fileTest extends \PHPUnit_Framework_TestCase
20 | {
21 | protected function setUp()
22 | {
23 | Log::init(['type' => 'file']);
24 | }
25 |
26 | public function testRecord()
27 | {
28 | $record_msg = 'record';
29 | Log::record($record_msg, 'notice');
30 | $logs = Log::getLog();
31 |
32 | $this->assertNotFalse(array_search(['type' => 'notice', 'msg' => $record_msg], $logs));
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/thinkphp/tests/thinkphp/library/think/model/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/thinkphp/tests/thinkphp/library/think/session/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/thinkphp/tests/thinkphp/library/think/template/driver/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/thinkphp/tests/thinkphp/library/think/view/driver/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/thinkphp/tests/thinkphp/library/traits/controller/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/thinkphp/tests/thinkphp/library/traits/model/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/thinkphp/tpl/default_index.tpl:
--------------------------------------------------------------------------------
1 | *{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px }';
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/thinkphp/tpl/dispatch_jump.tpl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 跳转提示
6 |
16 |
17 |
18 |
19 |
20 |
21 |
:)
22 |
23 |
24 |
25 |
:(
26 |
27 |
28 |
29 |
30 |
31 | 页面自动 跳转 等待时间:
32 |
33 |
34 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/thinkphp/vendor/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------