From 06709ae5cc655376d81197322567fa10b98ef394 Mon Sep 17 00:00:00 2001 From: zhaoxiang Date: Mon, 9 Apr 2018 09:38:10 +0800 Subject: [PATCH] =?UTF-8?q?modified=20ThinkPHP=E6=A0=B8=E5=BF=83=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/behavior/RequestFilter.php | 1 + thinkphp/CONTRIBUTING.md | 0 thinkphp/LICENSE.txt | 0 thinkphp/README.md | 2 +- thinkphp/base.php | 2 +- thinkphp/codecov.yml | 0 thinkphp/composer.json | 0 thinkphp/console.php | 0 thinkphp/convention.php | 7 +++ thinkphp/helper.php | 6 ++ thinkphp/lang/zh-cn.php | 0 thinkphp/library/think/App.php | 0 thinkphp/library/think/Build.php | 0 thinkphp/library/think/Cache.php | 0 thinkphp/library/think/Collection.php | 0 thinkphp/library/think/Config.php | 0 thinkphp/library/think/Console.php | 39 +++++++++---- thinkphp/library/think/Controller.php | 19 +++++- thinkphp/library/think/Cookie.php | 0 thinkphp/library/think/Db.php | 0 thinkphp/library/think/Debug.php | 0 thinkphp/library/think/Env.php | 0 thinkphp/library/think/Error.php | 0 thinkphp/library/think/Exception.php | 0 thinkphp/library/think/File.php | 0 thinkphp/library/think/Hook.php | 0 thinkphp/library/think/Lang.php | 0 thinkphp/library/think/Loader.php | 29 +++++++-- thinkphp/library/think/Log.php | 0 thinkphp/library/think/Model.php | 6 +- thinkphp/library/think/Paginator.php | 2 +- thinkphp/library/think/Process.php | 0 thinkphp/library/think/Request.php | 0 thinkphp/library/think/Response.php | 0 thinkphp/library/think/Route.php | 0 thinkphp/library/think/Session.php | 0 thinkphp/library/think/Template.php | 28 +++------ thinkphp/library/think/Url.php | 2 +- thinkphp/library/think/Validate.php | 3 +- thinkphp/library/think/View.php | 0 thinkphp/library/think/cache/Driver.php | 0 thinkphp/library/think/cache/driver/File.php | 5 +- thinkphp/library/think/cache/driver/Lite.php | 0 .../library/think/cache/driver/Memcache.php | 0 .../library/think/cache/driver/Memcached.php | 0 thinkphp/library/think/cache/driver/Redis.php | 0 .../library/think/cache/driver/Sqlite.php | 0 .../library/think/cache/driver/Wincache.php | 0 .../library/think/cache/driver/Xcache.php | 0 thinkphp/library/think/config/driver/Ini.php | 0 thinkphp/library/think/config/driver/Json.php | 0 thinkphp/library/think/config/driver/Xml.php | 0 thinkphp/library/think/console/Command.php | 0 thinkphp/library/think/console/Input.php | 0 thinkphp/library/think/console/LICENSE | 0 thinkphp/library/think/console/Output.php | 0 thinkphp/library/think/console/bin/README.md | 0 .../library/think/console/bin/hiddeninput.exe | Bin .../library/think/console/command/Build.php | 0 .../library/think/console/command/Clear.php | 0 .../library/think/console/command/Help.php | 0 .../library/think/console/command/Lists.php | 0 .../library/think/console/command/Make.php | 0 .../think/console/command/make/Controller.php | 0 .../think/console/command/make/Model.php | 0 .../command/make/stubs/controller.plain.stub | 0 .../command/make/stubs/controller.stub | 0 .../console/command/make/stubs/model.stub | 0 .../console/command/optimize/Autoload.php | 0 .../think/console/command/optimize/Config.php | 0 .../think/console/command/optimize/Route.php | 0 .../think/console/command/optimize/Schema.php | 0 .../library/think/console/input/Argument.php | 0 .../think/console/input/Definition.php | 0 .../library/think/console/input/Option.php | 0 thinkphp/library/think/console/output/Ask.php | 0 .../think/console/output/Descriptor.php | 0 .../think/console/output/Formatter.php | 0 .../library/think/console/output/Question.php | 0 .../console/output/descriptor/Console.php | 0 .../think/console/output/driver/Buffer.php | 0 .../think/console/output/driver/Console.php | 0 .../think/console/output/driver/Nothing.php | 0 .../think/console/output/formatter/Stack.php | 0 .../think/console/output/formatter/Style.php | 0 .../think/console/output/question/Choice.php | 0 .../console/output/question/Confirmation.php | 0 thinkphp/library/think/controller/Rest.php | 0 thinkphp/library/think/controller/Yar.php | 0 thinkphp/library/think/db/Builder.php | 10 +++- thinkphp/library/think/db/Connection.php | 1 + thinkphp/library/think/db/Query.php | 55 +++++++++++------- thinkphp/library/think/db/builder/Mysql.php | 0 thinkphp/library/think/db/builder/Pgsql.php | 0 thinkphp/library/think/db/builder/Sqlite.php | 0 thinkphp/library/think/db/builder/Sqlsrv.php | 0 thinkphp/library/think/db/connector/Mysql.php | 0 thinkphp/library/think/db/connector/Pgsql.php | 0 .../library/think/db/connector/Sqlite.php | 0 .../library/think/db/connector/Sqlsrv.php | 0 thinkphp/library/think/db/connector/pgsql.sql | 0 .../think/db/exception/BindParamException.php | 0 .../db/exception/DataNotFoundException.php | 0 .../db/exception/ModelNotFoundException.php | 0 thinkphp/library/think/debug/Console.php | 0 thinkphp/library/think/debug/Html.php | 2 +- .../exception/ClassNotFoundException.php | 0 .../library/think/exception/DbException.php | 0 .../think/exception/ErrorException.php | 0 thinkphp/library/think/exception/Handle.php | 0 .../library/think/exception/HttpException.php | 0 .../think/exception/HttpResponseException.php | 0 .../library/think/exception/PDOException.php | 0 .../exception/RouteNotFoundException.php | 0 .../exception/TemplateNotFoundException.php | 0 .../think/exception/ThrowableError.php | 0 .../think/exception/ValidateException.php | 0 thinkphp/library/think/log/driver/File.php | 19 +++++- thinkphp/library/think/log/driver/Socket.php | 0 thinkphp/library/think/log/driver/Test.php | 0 thinkphp/library/think/model/Collection.php | 14 ----- thinkphp/library/think/model/Merge.php | 0 thinkphp/library/think/model/Pivot.php | 0 thinkphp/library/think/model/Relation.php | 2 +- .../think/model/relation/BelongsTo.php | 22 ++++++- .../think/model/relation/BelongsToMany.php | 0 .../library/think/model/relation/HasMany.php | 0 .../think/model/relation/HasManyThrough.php | 0 .../library/think/model/relation/HasOne.php | 28 ++++++++- .../think/model/relation/MorphMany.php | 0 .../library/think/model/relation/MorphOne.php | 0 .../library/think/model/relation/MorphTo.php | 0 .../library/think/model/relation/OneToOne.php | 2 + .../think/paginator/driver/Bootstrap.php | 0 thinkphp/library/think/process/Builder.php | 0 thinkphp/library/think/process/Utils.php | 0 .../think/process/exception/Failed.php | 0 .../think/process/exception/Timeout.php | 0 .../library/think/process/pipes/Pipes.php | 0 thinkphp/library/think/process/pipes/Unix.php | 0 .../library/think/process/pipes/Windows.php | 0 thinkphp/library/think/response/Json.php | 0 thinkphp/library/think/response/Jsonp.php | 0 thinkphp/library/think/response/Redirect.php | 0 thinkphp/library/think/response/View.php | 0 thinkphp/library/think/response/Xml.php | 0 .../library/think/session/driver/Memcache.php | 0 .../think/session/driver/Memcached.php | 0 .../library/think/session/driver/Redis.php | 0 thinkphp/library/think/template/TagLib.php | 0 .../library/think/template/driver/File.php | 0 thinkphp/library/think/template/taglib/Cx.php | 0 thinkphp/library/think/view/driver/Php.php | 0 thinkphp/library/think/view/driver/Think.php | 0 thinkphp/library/traits/controller/Jump.php | 0 thinkphp/library/traits/model/SoftDelete.php | 0 thinkphp/library/traits/think/Instance.php | 0 thinkphp/logo.png | Bin thinkphp/phpunit.xml | 0 thinkphp/start.php | 0 thinkphp/tpl/default_index.tpl | 0 thinkphp/tpl/dispatch_jump.tpl | 0 thinkphp/tpl/page_trace.tpl | 0 thinkphp/tpl/think_exception.tpl | 0 164 files changed, 213 insertions(+), 93 deletions(-) mode change 100644 => 100755 thinkphp/CONTRIBUTING.md mode change 100644 => 100755 thinkphp/LICENSE.txt mode change 100644 => 100755 thinkphp/README.md mode change 100644 => 100755 thinkphp/base.php mode change 100644 => 100755 thinkphp/codecov.yml mode change 100644 => 100755 thinkphp/composer.json mode change 100644 => 100755 thinkphp/console.php mode change 100644 => 100755 thinkphp/convention.php mode change 100644 => 100755 thinkphp/helper.php mode change 100644 => 100755 thinkphp/lang/zh-cn.php mode change 100644 => 100755 thinkphp/library/think/App.php mode change 100644 => 100755 thinkphp/library/think/Build.php mode change 100644 => 100755 thinkphp/library/think/Cache.php mode change 100644 => 100755 thinkphp/library/think/Collection.php mode change 100644 => 100755 thinkphp/library/think/Config.php mode change 100644 => 100755 thinkphp/library/think/Console.php mode change 100644 => 100755 thinkphp/library/think/Controller.php mode change 100644 => 100755 thinkphp/library/think/Cookie.php mode change 100644 => 100755 thinkphp/library/think/Db.php mode change 100644 => 100755 thinkphp/library/think/Debug.php mode change 100644 => 100755 thinkphp/library/think/Env.php mode change 100644 => 100755 thinkphp/library/think/Error.php mode change 100644 => 100755 thinkphp/library/think/Exception.php mode change 100644 => 100755 thinkphp/library/think/File.php mode change 100644 => 100755 thinkphp/library/think/Hook.php mode change 100644 => 100755 thinkphp/library/think/Lang.php mode change 100644 => 100755 thinkphp/library/think/Loader.php mode change 100644 => 100755 thinkphp/library/think/Log.php mode change 100644 => 100755 thinkphp/library/think/Model.php mode change 100644 => 100755 thinkphp/library/think/Paginator.php mode change 100644 => 100755 thinkphp/library/think/Process.php mode change 100644 => 100755 thinkphp/library/think/Request.php mode change 100644 => 100755 thinkphp/library/think/Response.php mode change 100644 => 100755 thinkphp/library/think/Route.php mode change 100644 => 100755 thinkphp/library/think/Session.php mode change 100644 => 100755 thinkphp/library/think/Template.php mode change 100644 => 100755 thinkphp/library/think/Url.php mode change 100644 => 100755 thinkphp/library/think/Validate.php mode change 100644 => 100755 thinkphp/library/think/View.php mode change 100644 => 100755 thinkphp/library/think/cache/Driver.php mode change 100644 => 100755 thinkphp/library/think/cache/driver/File.php mode change 100644 => 100755 thinkphp/library/think/cache/driver/Lite.php mode change 100644 => 100755 thinkphp/library/think/cache/driver/Memcache.php mode change 100644 => 100755 thinkphp/library/think/cache/driver/Memcached.php mode change 100644 => 100755 thinkphp/library/think/cache/driver/Redis.php mode change 100644 => 100755 thinkphp/library/think/cache/driver/Sqlite.php mode change 100644 => 100755 thinkphp/library/think/cache/driver/Wincache.php mode change 100644 => 100755 thinkphp/library/think/cache/driver/Xcache.php mode change 100644 => 100755 thinkphp/library/think/config/driver/Ini.php mode change 100644 => 100755 thinkphp/library/think/config/driver/Json.php mode change 100644 => 100755 thinkphp/library/think/config/driver/Xml.php mode change 100644 => 100755 thinkphp/library/think/console/Command.php mode change 100644 => 100755 thinkphp/library/think/console/Input.php mode change 100644 => 100755 thinkphp/library/think/console/LICENSE mode change 100644 => 100755 thinkphp/library/think/console/Output.php mode change 100644 => 100755 thinkphp/library/think/console/bin/README.md mode change 100644 => 100755 thinkphp/library/think/console/bin/hiddeninput.exe mode change 100644 => 100755 thinkphp/library/think/console/command/Build.php mode change 100644 => 100755 thinkphp/library/think/console/command/Clear.php mode change 100644 => 100755 thinkphp/library/think/console/command/Help.php mode change 100644 => 100755 thinkphp/library/think/console/command/Lists.php mode change 100644 => 100755 thinkphp/library/think/console/command/Make.php mode change 100644 => 100755 thinkphp/library/think/console/command/make/Controller.php mode change 100644 => 100755 thinkphp/library/think/console/command/make/Model.php mode change 100644 => 100755 thinkphp/library/think/console/command/make/stubs/controller.plain.stub mode change 100644 => 100755 thinkphp/library/think/console/command/make/stubs/controller.stub mode change 100644 => 100755 thinkphp/library/think/console/command/make/stubs/model.stub mode change 100644 => 100755 thinkphp/library/think/console/command/optimize/Autoload.php mode change 100644 => 100755 thinkphp/library/think/console/command/optimize/Config.php mode change 100644 => 100755 thinkphp/library/think/console/command/optimize/Route.php mode change 100644 => 100755 thinkphp/library/think/console/command/optimize/Schema.php mode change 100644 => 100755 thinkphp/library/think/console/input/Argument.php mode change 100644 => 100755 thinkphp/library/think/console/input/Definition.php mode change 100644 => 100755 thinkphp/library/think/console/input/Option.php mode change 100644 => 100755 thinkphp/library/think/console/output/Ask.php mode change 100644 => 100755 thinkphp/library/think/console/output/Descriptor.php mode change 100644 => 100755 thinkphp/library/think/console/output/Formatter.php mode change 100644 => 100755 thinkphp/library/think/console/output/Question.php mode change 100644 => 100755 thinkphp/library/think/console/output/descriptor/Console.php mode change 100644 => 100755 thinkphp/library/think/console/output/driver/Buffer.php mode change 100644 => 100755 thinkphp/library/think/console/output/driver/Console.php mode change 100644 => 100755 thinkphp/library/think/console/output/driver/Nothing.php mode change 100644 => 100755 thinkphp/library/think/console/output/formatter/Stack.php mode change 100644 => 100755 thinkphp/library/think/console/output/formatter/Style.php mode change 100644 => 100755 thinkphp/library/think/console/output/question/Choice.php mode change 100644 => 100755 thinkphp/library/think/console/output/question/Confirmation.php mode change 100644 => 100755 thinkphp/library/think/controller/Rest.php mode change 100644 => 100755 thinkphp/library/think/controller/Yar.php mode change 100644 => 100755 thinkphp/library/think/db/Builder.php mode change 100644 => 100755 thinkphp/library/think/db/Connection.php mode change 100644 => 100755 thinkphp/library/think/db/Query.php mode change 100644 => 100755 thinkphp/library/think/db/builder/Mysql.php mode change 100644 => 100755 thinkphp/library/think/db/builder/Pgsql.php mode change 100644 => 100755 thinkphp/library/think/db/builder/Sqlite.php mode change 100644 => 100755 thinkphp/library/think/db/builder/Sqlsrv.php mode change 100644 => 100755 thinkphp/library/think/db/connector/Mysql.php mode change 100644 => 100755 thinkphp/library/think/db/connector/Pgsql.php mode change 100644 => 100755 thinkphp/library/think/db/connector/Sqlite.php mode change 100644 => 100755 thinkphp/library/think/db/connector/Sqlsrv.php mode change 100644 => 100755 thinkphp/library/think/db/connector/pgsql.sql mode change 100644 => 100755 thinkphp/library/think/db/exception/BindParamException.php mode change 100644 => 100755 thinkphp/library/think/db/exception/DataNotFoundException.php mode change 100644 => 100755 thinkphp/library/think/db/exception/ModelNotFoundException.php mode change 100644 => 100755 thinkphp/library/think/debug/Console.php mode change 100644 => 100755 thinkphp/library/think/debug/Html.php mode change 100644 => 100755 thinkphp/library/think/exception/ClassNotFoundException.php mode change 100644 => 100755 thinkphp/library/think/exception/DbException.php mode change 100644 => 100755 thinkphp/library/think/exception/ErrorException.php mode change 100644 => 100755 thinkphp/library/think/exception/Handle.php mode change 100644 => 100755 thinkphp/library/think/exception/HttpException.php mode change 100644 => 100755 thinkphp/library/think/exception/HttpResponseException.php mode change 100644 => 100755 thinkphp/library/think/exception/PDOException.php mode change 100644 => 100755 thinkphp/library/think/exception/RouteNotFoundException.php mode change 100644 => 100755 thinkphp/library/think/exception/TemplateNotFoundException.php mode change 100644 => 100755 thinkphp/library/think/exception/ThrowableError.php mode change 100644 => 100755 thinkphp/library/think/exception/ValidateException.php mode change 100644 => 100755 thinkphp/library/think/log/driver/File.php mode change 100644 => 100755 thinkphp/library/think/log/driver/Socket.php mode change 100644 => 100755 thinkphp/library/think/log/driver/Test.php mode change 100644 => 100755 thinkphp/library/think/model/Collection.php mode change 100644 => 100755 thinkphp/library/think/model/Merge.php mode change 100644 => 100755 thinkphp/library/think/model/Pivot.php mode change 100644 => 100755 thinkphp/library/think/model/Relation.php mode change 100644 => 100755 thinkphp/library/think/model/relation/BelongsTo.php mode change 100644 => 100755 thinkphp/library/think/model/relation/BelongsToMany.php mode change 100644 => 100755 thinkphp/library/think/model/relation/HasMany.php mode change 100644 => 100755 thinkphp/library/think/model/relation/HasManyThrough.php mode change 100644 => 100755 thinkphp/library/think/model/relation/HasOne.php mode change 100644 => 100755 thinkphp/library/think/model/relation/MorphMany.php mode change 100644 => 100755 thinkphp/library/think/model/relation/MorphOne.php mode change 100644 => 100755 thinkphp/library/think/model/relation/MorphTo.php mode change 100644 => 100755 thinkphp/library/think/model/relation/OneToOne.php mode change 100644 => 100755 thinkphp/library/think/paginator/driver/Bootstrap.php mode change 100644 => 100755 thinkphp/library/think/process/Builder.php mode change 100644 => 100755 thinkphp/library/think/process/Utils.php mode change 100644 => 100755 thinkphp/library/think/process/exception/Failed.php mode change 100644 => 100755 thinkphp/library/think/process/exception/Timeout.php mode change 100644 => 100755 thinkphp/library/think/process/pipes/Pipes.php mode change 100644 => 100755 thinkphp/library/think/process/pipes/Unix.php mode change 100644 => 100755 thinkphp/library/think/process/pipes/Windows.php mode change 100644 => 100755 thinkphp/library/think/response/Json.php mode change 100644 => 100755 thinkphp/library/think/response/Jsonp.php mode change 100644 => 100755 thinkphp/library/think/response/Redirect.php mode change 100644 => 100755 thinkphp/library/think/response/View.php mode change 100644 => 100755 thinkphp/library/think/response/Xml.php mode change 100644 => 100755 thinkphp/library/think/session/driver/Memcache.php mode change 100644 => 100755 thinkphp/library/think/session/driver/Memcached.php mode change 100644 => 100755 thinkphp/library/think/session/driver/Redis.php mode change 100644 => 100755 thinkphp/library/think/template/TagLib.php mode change 100644 => 100755 thinkphp/library/think/template/driver/File.php mode change 100644 => 100755 thinkphp/library/think/template/taglib/Cx.php mode change 100644 => 100755 thinkphp/library/think/view/driver/Php.php mode change 100644 => 100755 thinkphp/library/think/view/driver/Think.php mode change 100644 => 100755 thinkphp/library/traits/controller/Jump.php mode change 100644 => 100755 thinkphp/library/traits/model/SoftDelete.php mode change 100644 => 100755 thinkphp/library/traits/think/Instance.php mode change 100644 => 100755 thinkphp/logo.png mode change 100644 => 100755 thinkphp/phpunit.xml mode change 100644 => 100755 thinkphp/start.php mode change 100644 => 100755 thinkphp/tpl/default_index.tpl mode change 100644 => 100755 thinkphp/tpl/dispatch_jump.tpl mode change 100644 => 100755 thinkphp/tpl/page_trace.tpl mode change 100644 => 100755 thinkphp/tpl/think_exception.tpl diff --git a/application/api/behavior/RequestFilter.php b/application/api/behavior/RequestFilter.php index cb10925..529832f 100644 --- a/application/api/behavior/RequestFilter.php +++ b/application/api/behavior/RequestFilter.php @@ -20,6 +20,7 @@ class RequestFilter { /** * 默认行为函数 + * @throws \think\Exception * @throws \think\exception\DbException * @author zhaoxiang */ diff --git a/thinkphp/CONTRIBUTING.md b/thinkphp/CONTRIBUTING.md old mode 100644 new mode 100755 diff --git a/thinkphp/LICENSE.txt b/thinkphp/LICENSE.txt old mode 100644 new mode 100755 diff --git a/thinkphp/README.md b/thinkphp/README.md old mode 100644 new mode 100755 index 68e5e69..f01fd2b --- a/thinkphp/README.md +++ b/thinkphp/README.md @@ -92,7 +92,7 @@ www WEB部署目录(或者子目录) ## 命名规范 -ThinkPHP5的命名规范遵循PSR-2规范以及PSR-4自动加载规范。 +ThinkPHP5的命名规范遵循`PSR-2`规范以及`PSR-4`自动加载规范。 ## 参与开发 注册并登录 Github 帐号, fork 本项目并进行改动。 diff --git a/thinkphp/base.php b/thinkphp/base.php old mode 100644 new mode 100755 index f88935d..619eb93 --- a/thinkphp/base.php +++ b/thinkphp/base.php @@ -9,7 +9,7 @@ // | Author: liu21st // +---------------------------------------------------------------------- -define('THINK_VERSION', '5.0.15'); +define('THINK_VERSION', '5.0.16'); define('THINK_START_TIME', microtime(true)); define('THINK_START_MEM', memory_get_usage()); define('EXT', '.php'); diff --git a/thinkphp/codecov.yml b/thinkphp/codecov.yml old mode 100644 new mode 100755 diff --git a/thinkphp/composer.json b/thinkphp/composer.json old mode 100644 new mode 100755 diff --git a/thinkphp/console.php b/thinkphp/console.php old mode 100644 new mode 100755 diff --git a/thinkphp/convention.php b/thinkphp/convention.php old mode 100644 new mode 100755 index 4ca03c0..15e3496 --- a/thinkphp/convention.php +++ b/thinkphp/convention.php @@ -286,4 +286,11 @@ return [ 'list_rows' => 15, ], + //控制台配置 + 'console' => [ + 'name' => 'Think Console', + 'version' => '0.1', + 'user' => null, + ], + ]; diff --git a/thinkphp/helper.php b/thinkphp/helper.php old mode 100644 new mode 100755 index 12683cf..b568dab --- a/thinkphp/helper.php +++ b/thinkphp/helper.php @@ -443,6 +443,12 @@ if (!function_exists('view')) { */ function view($template = '', $vars = [], $replace = [], $code = 200) { + if ('' === $template) { + $trace = debug_backtrace(false, 2); + $suffix = Config::get('action_suffix'); + $action = $suffix ? substr($trace[1]['function'], 0, -strlen($suffix)) : $trace[1]['function']; + $template = Loader::parseName($action); + } return Response::create($template, 'view', $code)->replace($replace)->assign($vars); } } diff --git a/thinkphp/lang/zh-cn.php b/thinkphp/lang/zh-cn.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/App.php b/thinkphp/library/think/App.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/Build.php b/thinkphp/library/think/Build.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/Cache.php b/thinkphp/library/think/Cache.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/Collection.php b/thinkphp/library/think/Collection.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/Config.php b/thinkphp/library/think/Config.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/Console.php b/thinkphp/library/think/Console.php old mode 100644 new mode 100755 index 2ccde88..32b2572 --- a/thinkphp/library/think/Console.php +++ b/thinkphp/library/think/Console.php @@ -79,14 +79,19 @@ class Console /** * Console constructor. * @access public - * @param string $name 名称 - * @param string $version 版本 + * @param string $name 名称 + * @param string $version 版本 + * @param null|string $user 执行用户 */ - public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') + public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN', $user = null) { $this->name = $name; $this->version = $version; + if ($user) { + $this->setUser($user); + } + $this->defaultCommand = 'list'; $this->definition = $this->getDefaultInputDefinition(); @@ -95,6 +100,19 @@ class Console } } + /** + * 设置执行用户 + * @param $user + */ + public function setUser($user) + { + $user = posix_getpwnam($user); + if ($user) { + posix_setuid($user['uid']); + posix_setgid($user['gid']); + } + } + /** * 初始化 Console * @access public @@ -106,8 +124,9 @@ class Console static $console; if (!$console) { + $config = Config::get('console'); // 实例化 console - $console = new self('Think Console', '0.1'); + $console = new self($config['name'], $config['version'], $config['user']); // 读取指令集 if (is_file(CONF_PATH . 'command' . EXT)) { @@ -479,7 +498,7 @@ class Console }, $namespace); $allNamespaces = $this->getNamespaces(); - $namespaces = preg_grep('{^' . $expr . '}', $allNamespaces); + $namespaces = preg_grep('{^' . $expr . '}', $allNamespaces); if (empty($namespaces)) { $message = sprintf( @@ -527,7 +546,7 @@ class Console }, $name); $allCommands = array_keys($this->commands); - $commands = preg_grep('{^' . $expr . '}', $allCommands); + $commands = preg_grep('{^' . $expr . '}', $allCommands); if (empty($commands) || count(preg_grep('{^' . $expr . '$}', $commands)) < 1) { if (false !== ($pos = strrpos($name, ':'))) { @@ -550,7 +569,7 @@ class Console if (count($commands) > 1) { $commandList = $this->commands; - $commands = array_filter($commands, function ($nameOrAlias) use ($commandList, $commands) { + $commands = array_filter($commands, function ($nameOrAlias) use ($commandList, $commands) { $commandName = $commandList[$nameOrAlias]->getName(); return $commandName === $nameOrAlias || !in_array($commandName, $commands); @@ -601,7 +620,7 @@ class Console $abbrevs = []; foreach ($names as $name) { for ($len = strlen($name); $len > 0; --$len) { - $abbrev = substr($name, 0, $len); + $abbrev = substr($name, 0, $len); $abbrevs[$abbrev][] = $name; } } @@ -754,8 +773,8 @@ class Console */ private function findAlternatives($name, $collection) { - $threshold = 1e3; - $alternatives = []; + $threshold = 1e3; + $alternatives = []; $collectionParts = []; foreach ($collection as $item) { diff --git a/thinkphp/library/think/Controller.php b/thinkphp/library/think/Controller.php old mode 100644 new mode 100755 index e446e58..43044de --- a/thinkphp/library/think/Controller.php +++ b/thinkphp/library/think/Controller.php @@ -52,7 +52,7 @@ class Controller */ public function __construct(Request $request = null) { - $this->view = View::instance(Config::get('template'), Config::get('view_replace_str')); + $this->view = View::instance(Config::get('template'), Config::get('view_replace_str')); $this->request = is_null($request) ? Request::instance() : $request; // 控制器初始化 @@ -117,6 +117,13 @@ class Controller */ protected function fetch($template = '', $vars = [], $replace = [], $config = []) { + if ('' === $template) { + $trace = debug_backtrace(false, 2); + $suffix = Config::get('action_suffix'); + $action = $suffix ? substr($trace[1]['function'], 0, -strlen($suffix)) : $trace[1]['function']; + $template = Loader::parseName($action); + } + return $this->view->fetch($template, $vars, $replace, $config); } @@ -202,9 +209,15 @@ class Controller } // 批量验证 - if ($batch || $this->batchValidate) $v->batch(true); + if ($batch || $this->batchValidate) { + $v->batch(true); + } + // 设置错误信息 - if (is_array($message)) $v->message($message); + if (is_array($message)) { + $v->message($message); + } + // 使用回调验证 if ($callback && is_callable($callback)) { call_user_func_array($callback, [$v, &$data]); diff --git a/thinkphp/library/think/Cookie.php b/thinkphp/library/think/Cookie.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/Db.php b/thinkphp/library/think/Db.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/Debug.php b/thinkphp/library/think/Debug.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/Env.php b/thinkphp/library/think/Env.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/Error.php b/thinkphp/library/think/Error.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/Exception.php b/thinkphp/library/think/Exception.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/File.php b/thinkphp/library/think/File.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/Hook.php b/thinkphp/library/think/Hook.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/Lang.php b/thinkphp/library/think/Lang.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/Loader.php b/thinkphp/library/think/Loader.php old mode 100644 new mode 100755 index e4130bd..e75fe53 --- a/thinkphp/library/think/Loader.php +++ b/thinkphp/library/think/Loader.php @@ -284,6 +284,25 @@ class Loader // 注册系统自动加载 spl_autoload_register($autoload ?: 'think\\Loader::autoload', true, true); + // Composer 自动加载支持 + if (is_dir(VENDOR_PATH . 'composer')) { + if (PHP_VERSION_ID >= 50600 && is_file(VENDOR_PATH . 'composer' . DS . 'autoload_static.php')) { + require VENDOR_PATH . 'composer' . DS . 'autoload_static.php'; + + $declaredClass = get_declared_classes(); + $composerClass = array_pop($declaredClass); + + self::$prefixLengthsPsr4 = $composerClass::$prefixLengthsPsr4; + + self::$prefixDirsPsr4 = property_exists($composerClass, 'prefixDirsPsr4') ? $composerClass::$prefixDirsPsr4 : []; + + self::$prefixesPsr0 = property_exists($composerClass, 'prefixesPsr0') ? $composerClass::$prefixesPsr0 : []; + self::$map = property_exists($composerClass, 'classMap') ? $composerClass::$classMap : []; + } else { + self::registerComposerLoader(); + } + } + // 注册命名空间定义 self::addNamespace([ 'think' => LIB_PATH . 'think' . DS, @@ -296,10 +315,7 @@ class Loader self::addClassMap(__include_file(RUNTIME_PATH . 'classmap' . EXT)); } - // Composer 自动加载支持 - if (is_dir(VENDOR_PATH . 'composer')) { - self::registerComposerLoader(); - } + self::loadComposerAutoloadFiles(); // 自动加载 extend 目录 self::$fallbackDirsPsr4[] = rtrim(EXTEND_PATH, DS); @@ -331,9 +347,12 @@ class Loader if ($classMap) { self::addClassMap($classMap); } - } + } + // 加载composer autofile文件 + public static function loadComposerAutoloadFiles() + { if (is_file(VENDOR_PATH . 'composer/autoload_files.php')) { $includeFiles = require VENDOR_PATH . 'composer/autoload_files.php'; foreach ($includeFiles as $fileIdentifier => $file) { diff --git a/thinkphp/library/think/Log.php b/thinkphp/library/think/Log.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/Model.php b/thinkphp/library/think/Model.php old mode 100644 new mode 100755 index a42eafa..cbab715 --- a/thinkphp/library/think/Model.php +++ b/thinkphp/library/think/Model.php @@ -679,7 +679,11 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $value = empty($value) ? new \stdClass() : json_decode($value); break; case 'serialize': - $value = unserialize($value); + try { + $value = unserialize($value); + } catch (\Exception $e) { + $value = null; + } break; default: if (false !== strpos($type, '\\')) { diff --git a/thinkphp/library/think/Paginator.php b/thinkphp/library/think/Paginator.php old mode 100644 new mode 100755 index 0b42de0..0b2a3c6 --- a/thinkphp/library/think/Paginator.php +++ b/thinkphp/library/think/Paginator.php @@ -128,7 +128,7 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J } $url = $path; if (!empty($parameters)) { - $url .= '?' . urldecode(http_build_query($parameters, null, '&')); + $url .= '?' . http_build_query($parameters, null, '&'); } return $url . $this->buildFragment(); } diff --git a/thinkphp/library/think/Process.php b/thinkphp/library/think/Process.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/Request.php b/thinkphp/library/think/Request.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/Response.php b/thinkphp/library/think/Response.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/Route.php b/thinkphp/library/think/Route.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/Session.php b/thinkphp/library/think/Session.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/Template.php b/thinkphp/library/think/Template.php old mode 100644 new mode 100755 index 02cd504..9ba0ff3 --- a/thinkphp/library/think/Template.php +++ b/thinkphp/library/think/Template.php @@ -64,14 +64,16 @@ class Template */ public function __construct(array $config = []) { - $this->config['cache_path'] = TEMP_PATH; - $this->config = array_merge($this->config, $config); + $this->config['cache_path'] = TEMP_PATH; + $this->config = array_merge($this->config, $config); + $this->config['taglib_begin_origin'] = $this->config['taglib_begin']; $this->config['taglib_end_origin'] = $this->config['taglib_end']; - $this->config['taglib_begin'] = $this->stripPreg($this->config['taglib_begin']); - $this->config['taglib_end'] = $this->stripPreg($this->config['taglib_end']); - $this->config['tpl_begin'] = $this->stripPreg($this->config['tpl_begin']); - $this->config['tpl_end'] = $this->stripPreg($this->config['tpl_end']); + + $this->config['taglib_begin'] = preg_quote($this->config['taglib_begin'], '/'); + $this->config['taglib_end'] = preg_quote($this->config['taglib_end'], '/'); + $this->config['tpl_begin'] = preg_quote($this->config['tpl_begin'], '/'); + $this->config['tpl_end'] = preg_quote($this->config['tpl_end'], '/'); // 初始化模板编译存储器 $type = $this->config['compile_type'] ? $this->config['compile_type'] : 'File'; @@ -79,20 +81,6 @@ class Template $this->storage = new $class(); } - /** - * 字符串替换 避免正则混淆 - * @access private - * @param string $str - * @return string - */ - private function stripPreg($str) - { - return str_replace( - ['{', '}', '(', ')', '|', '[', ']', '-', '+', '*', '.', '^', '?'], - ['\{', '\}', '\(', '\)', '\|', '\[', '\]', '\-', '\+', '\*', '\.', '\^', '\?'], - $str); - } - /** * 模板变量赋值 * @access public diff --git a/thinkphp/library/think/Url.php b/thinkphp/library/think/Url.php old mode 100644 new mode 100755 index 2b5fd7f..53a545f --- a/thinkphp/library/think/Url.php +++ b/thinkphp/library/think/Url.php @@ -302,7 +302,7 @@ class Url foreach ($rule as $item) { list($url, $pattern, $domain, $suffix) = $item; if (empty($pattern)) { - return [$url, $domain, $suffix]; + return [rtrim($url, '$'), $domain, $suffix]; } $type = Config::get('url_common_param'); foreach ($pattern as $key => $val) { diff --git a/thinkphp/library/think/Validate.php b/thinkphp/library/think/Validate.php old mode 100644 new mode 100755 index 353561b..6226892 --- a/thinkphp/library/think/Validate.php +++ b/thinkphp/library/think/Validate.php @@ -42,7 +42,6 @@ class Validate 'float' => ':attribute must be float', 'boolean' => ':attribute must be bool', 'email' => ':attribute not a valid email address', - 'mobile' => ':attribute not a valid mobile', 'array' => ':attribute must be a array', 'accepted' => ':attribute must be yes,on or 1', 'date' => ':attribute not a valid datetime', @@ -1196,7 +1195,7 @@ class Validate // 不是正则表达式则两端补上/ $rule = '/^' . $rule . '$/'; } - return 1 === preg_match($rule, (string) $value); + return is_scalar($value) && 1 === preg_match($rule, (string) $value); } /** diff --git a/thinkphp/library/think/View.php b/thinkphp/library/think/View.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/cache/Driver.php b/thinkphp/library/think/cache/Driver.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/cache/driver/File.php b/thinkphp/library/think/cache/driver/File.php old mode 100644 new mode 100755 index 6b1abd1..fee6489 --- a/thinkphp/library/think/cache/driver/File.php +++ b/thinkphp/library/think/cache/driver/File.php @@ -215,7 +215,10 @@ class File extends Driver public function rm($name) { $filename = $this->getCacheKey($name); - return $this->unlink($filename); + try { + return $this->unlink($filename); + } catch (\Exception $e) { + } } /** diff --git a/thinkphp/library/think/cache/driver/Lite.php b/thinkphp/library/think/cache/driver/Lite.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/cache/driver/Memcache.php b/thinkphp/library/think/cache/driver/Memcache.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/cache/driver/Memcached.php b/thinkphp/library/think/cache/driver/Memcached.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/cache/driver/Redis.php b/thinkphp/library/think/cache/driver/Redis.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/cache/driver/Sqlite.php b/thinkphp/library/think/cache/driver/Sqlite.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/cache/driver/Wincache.php b/thinkphp/library/think/cache/driver/Wincache.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/cache/driver/Xcache.php b/thinkphp/library/think/cache/driver/Xcache.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/config/driver/Ini.php b/thinkphp/library/think/config/driver/Ini.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/config/driver/Json.php b/thinkphp/library/think/config/driver/Json.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/config/driver/Xml.php b/thinkphp/library/think/config/driver/Xml.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/Command.php b/thinkphp/library/think/console/Command.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/Input.php b/thinkphp/library/think/console/Input.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/LICENSE b/thinkphp/library/think/console/LICENSE old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/Output.php b/thinkphp/library/think/console/Output.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/bin/README.md b/thinkphp/library/think/console/bin/README.md old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/bin/hiddeninput.exe b/thinkphp/library/think/console/bin/hiddeninput.exe old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/command/Build.php b/thinkphp/library/think/console/command/Build.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/command/Clear.php b/thinkphp/library/think/console/command/Clear.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/command/Help.php b/thinkphp/library/think/console/command/Help.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/command/Lists.php b/thinkphp/library/think/console/command/Lists.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/command/Make.php b/thinkphp/library/think/console/command/Make.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/command/make/Controller.php b/thinkphp/library/think/console/command/make/Controller.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/command/make/Model.php b/thinkphp/library/think/console/command/make/Model.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/command/make/stubs/controller.plain.stub b/thinkphp/library/think/console/command/make/stubs/controller.plain.stub old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/command/make/stubs/controller.stub b/thinkphp/library/think/console/command/make/stubs/controller.stub old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/command/make/stubs/model.stub b/thinkphp/library/think/console/command/make/stubs/model.stub old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/command/optimize/Autoload.php b/thinkphp/library/think/console/command/optimize/Autoload.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/command/optimize/Config.php b/thinkphp/library/think/console/command/optimize/Config.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/command/optimize/Route.php b/thinkphp/library/think/console/command/optimize/Route.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/command/optimize/Schema.php b/thinkphp/library/think/console/command/optimize/Schema.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/input/Argument.php b/thinkphp/library/think/console/input/Argument.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/input/Definition.php b/thinkphp/library/think/console/input/Definition.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/input/Option.php b/thinkphp/library/think/console/input/Option.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/output/Ask.php b/thinkphp/library/think/console/output/Ask.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/output/Descriptor.php b/thinkphp/library/think/console/output/Descriptor.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/output/Formatter.php b/thinkphp/library/think/console/output/Formatter.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/output/Question.php b/thinkphp/library/think/console/output/Question.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/output/descriptor/Console.php b/thinkphp/library/think/console/output/descriptor/Console.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/output/driver/Buffer.php b/thinkphp/library/think/console/output/driver/Buffer.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/output/driver/Console.php b/thinkphp/library/think/console/output/driver/Console.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/output/driver/Nothing.php b/thinkphp/library/think/console/output/driver/Nothing.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/output/formatter/Stack.php b/thinkphp/library/think/console/output/formatter/Stack.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/output/formatter/Style.php b/thinkphp/library/think/console/output/formatter/Style.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/output/question/Choice.php b/thinkphp/library/think/console/output/question/Choice.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/console/output/question/Confirmation.php b/thinkphp/library/think/console/output/question/Confirmation.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/controller/Rest.php b/thinkphp/library/think/controller/Rest.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/controller/Yar.php b/thinkphp/library/think/controller/Yar.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/db/Builder.php b/thinkphp/library/think/db/Builder.php old mode 100644 new mode 100755 index bbc2037..cd948da --- a/thinkphp/library/think/db/Builder.php +++ b/thinkphp/library/think/db/Builder.php @@ -116,10 +116,14 @@ abstract class Builder $result[$item] = $val[1]; break; case 'inc': - $result[$item] = $this->parseKey($val[1]) . '+' . floatval($val[2]); + if ($key == $val[1]) { + $result[$item] = $this->parseKey($val[1]) . '+' . floatval($val[2]); + } break; case 'dec': - $result[$item] = $this->parseKey($val[1]) . '-' . floatval($val[2]); + if ($key == $val[1]) { + $result[$item] = $this->parseKey($val[1]) . '-' . floatval($val[2]); + } break; } } elseif (is_scalar($val)) { @@ -338,7 +342,7 @@ abstract class Builder throw new Exception('where express error:' . $exp); } } - $bindName = $bindName ?: 'where_' . str_replace(['.', '-'], '_', $field); + $bindName = $bindName ?: 'where_' . $rule . '_' . str_replace(['.', '-'], '_', $field); if (preg_match('/\W/', $bindName)) { // 处理带非单词字符的字段名 $bindName = md5($bindName); diff --git a/thinkphp/library/think/db/Connection.php b/thinkphp/library/think/db/Connection.php old mode 100644 new mode 100755 index e77abf8..e252b90 --- a/thinkphp/library/think/db/Connection.php +++ b/thinkphp/library/think/db/Connection.php @@ -823,6 +823,7 @@ abstract class Connection 'SSL connection has been closed unexpectedly', 'Error writing data to the connection', 'Resource deadlock avoided', + 'failed with errno', ]; $error = $e->getMessage(); diff --git a/thinkphp/library/think/db/Query.php b/thinkphp/library/think/db/Query.php old mode 100644 new mode 100755 index d425d78..50f0fd8 --- a/thinkphp/library/think/db/Query.php +++ b/thinkphp/library/think/db/Query.php @@ -131,7 +131,7 @@ class Query } /** - * 获取当前的模型对象名 + * 获取当前的模型对象实例 * @access public * @return Model|null */ @@ -403,7 +403,7 @@ class Query if (empty($this->options['table'])) { $this->options['table'] = $this->getTable(); } - $key = is_string($cache['key']) ? $cache['key'] : md5($field . serialize($this->options) . serialize($this->bind)); + $key = is_string($cache['key']) ? $cache['key'] : md5($this->connection->getConfig('database') . '.' . $field . serialize($this->options) . serialize($this->bind)); $result = Cache::get($key); } if (false === $result) { @@ -447,7 +447,7 @@ class Query if (empty($this->options['table'])) { $this->options['table'] = $this->getTable(); } - $guid = is_string($cache['key']) ? $cache['key'] : md5($field . serialize($this->options) . serialize($this->bind)); + $guid = is_string($cache['key']) ? $cache['key'] : md5($this->connection->getConfig('database') . '.' . $field . serialize($this->options) . serialize($this->bind)); $result = Cache::get($guid); } if (false === $result) { @@ -708,6 +708,7 @@ class Query // 传入的表名为数组 if (is_array($join)) { $table = $join; + $alias = array_shift($join); } else { $join = trim($join); if (false !== strpos($join, '(')) { @@ -793,7 +794,7 @@ class Query } if (isset($this->options['field'])) { - $field = array_merge($this->options['field'], $field); + $field = array_merge((array) $this->options['field'], $field); } $this->options['field'] = array_unique($field); return $this; @@ -873,9 +874,9 @@ class Query public function view($join, $field = true, $on = null, $type = 'INNER') { $this->options['view'] = true; - if (is_array($join) && key($join) !== 0) { + if (is_array($join) && key($join) === 0) { foreach ($join as $key => $val) { - $this->view($key, $val[0], isset($val[1]) ? $val[1] : null, isset($val[2]) ? $val[2] : 'INNER'); + $this->view($val[0], $val[1], isset($val[2]) ? $val[2] : null, isset($val[3]) ? $val[3] : 'INNER'); } } else { $fields = []; @@ -983,7 +984,7 @@ class Query */ public function whereNull($field, $logic = 'AND') { - $this->parseWhereExp($logic, $field, 'null', null); + $this->parseWhereExp($logic, $field, 'null', null, [], true); return $this; } @@ -996,7 +997,7 @@ class Query */ public function whereNotNull($field, $logic = 'AND') { - $this->parseWhereExp($logic, $field, 'notnull', null); + $this->parseWhereExp($logic, $field, 'notnull', null, [], true); return $this; } @@ -1036,7 +1037,7 @@ class Query */ public function whereIn($field, $condition, $logic = 'AND') { - $this->parseWhereExp($logic, $field, 'in', $condition); + $this->parseWhereExp($logic, $field, 'in', $condition, [], true); return $this; } @@ -1050,7 +1051,7 @@ class Query */ public function whereNotIn($field, $condition, $logic = 'AND') { - $this->parseWhereExp($logic, $field, 'not in', $condition); + $this->parseWhereExp($logic, $field, 'not in', $condition, [], true); return $this; } @@ -1064,7 +1065,7 @@ class Query */ public function whereLike($field, $condition, $logic = 'AND') { - $this->parseWhereExp($logic, $field, 'like', $condition); + $this->parseWhereExp($logic, $field, 'like', $condition, [], true); return $this; } @@ -1078,7 +1079,7 @@ class Query */ public function whereNotLike($field, $condition, $logic = 'AND') { - $this->parseWhereExp($logic, $field, 'not like', $condition); + $this->parseWhereExp($logic, $field, 'not like', $condition, [], true); return $this; } @@ -1092,7 +1093,7 @@ class Query */ public function whereBetween($field, $condition, $logic = 'AND') { - $this->parseWhereExp($logic, $field, 'between', $condition); + $this->parseWhereExp($logic, $field, 'between', $condition, [], true); return $this; } @@ -1106,7 +1107,7 @@ class Query */ public function whereNotBetween($field, $condition, $logic = 'AND') { - $this->parseWhereExp($logic, $field, 'not between', $condition); + $this->parseWhereExp($logic, $field, 'not between', $condition, [], true); return $this; } @@ -1120,7 +1121,7 @@ class Query */ public function whereExp($field, $condition, $logic = 'AND') { - $this->parseWhereExp($logic, $field, 'exp', $condition); + $this->parseWhereExp($logic, $field, 'exp', $condition, [], true); return $this; } @@ -1147,9 +1148,10 @@ class Query * @param mixed $op 查询表达式 * @param mixed $condition 查询条件 * @param array $param 查询参数 + * @param bool $strict 严格模式 * @return void */ - protected function parseWhereExp($logic, $field, $op, $condition, $param = []) + protected function parseWhereExp($logic, $field, $op, $condition, $param = [], $strict = false) { $logic = strtoupper($logic); if ($field instanceof \Closure) { @@ -1160,7 +1162,14 @@ class Query if (is_string($field) && !empty($this->options['via']) && !strpos($field, '.')) { $field = $this->options['via'] . '.' . $field; } - if (is_string($field) && preg_match('/[,=\>\<\'\"\(\s]/', $field)) { + + if ($strict) { + // 使用严格模式查询 + $where[$field] = [$op, $condition]; + + // 记录一个字段多次查询条件 + $this->options['multi'][$logic][$field][] = $where[$field]; + } elseif (is_string($field) && preg_match('/[,=\>\<\'\"\(\s]/', $field)) { $where[] = ['exp', $field]; if (is_array($op)) { // 参数绑定 @@ -2322,7 +2331,7 @@ class Query // 判断查询缓存 $cache = $options['cache']; unset($options['cache']); - $key = is_string($cache['key']) ? $cache['key'] : md5(serialize($options) . serialize($this->bind)); + $key = is_string($cache['key']) ? $cache['key'] : md5($this->connection->getConfig('database') . '.' . serialize($options) . serialize($this->bind)); $resultSet = Cache::get($key); } if (false === $resultSet) { @@ -2423,10 +2432,12 @@ class Query } elseif (is_array($value) && is_string($value[0]) && 'eq' == strtolower($value[0])) { $data = $value[1]; } + $prefix = $this->connection->getConfig('database') . '.'; + if (isset($data)) { - return 'think:' . (is_array($options['table']) ? key($options['table']) : $options['table']) . '|' . $data; + return 'think:' . $prefix . (is_array($options['table']) ? key($options['table']) : $options['table']) . '|' . $data; } else { - return md5(serialize($options) . serialize($bind)); + return md5($prefix . serialize($options) . serialize($bind)); } } @@ -2463,11 +2474,11 @@ class Query // 判断查询缓存 $cache = $options['cache']; if (true === $cache['key'] && !is_null($data) && !is_array($data)) { - $key = 'think:' . (is_array($options['table']) ? key($options['table']) : $options['table']) . '|' . $data; + $key = 'think:' . $this->connection->getConfig('database') . '.' . (is_array($options['table']) ? key($options['table']) : $options['table']) . '|' . $data; } elseif (is_string($cache['key'])) { $key = $cache['key']; } elseif (!isset($key)) { - $key = md5(serialize($options) . serialize($this->bind)); + $key = md5($this->connection->getConfig('database') . '.' . serialize($options) . serialize($this->bind)); } $result = Cache::get($key); } diff --git a/thinkphp/library/think/db/builder/Mysql.php b/thinkphp/library/think/db/builder/Mysql.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/db/builder/Pgsql.php b/thinkphp/library/think/db/builder/Pgsql.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/db/builder/Sqlite.php b/thinkphp/library/think/db/builder/Sqlite.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/db/builder/Sqlsrv.php b/thinkphp/library/think/db/builder/Sqlsrv.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/db/connector/Mysql.php b/thinkphp/library/think/db/connector/Mysql.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/db/connector/Pgsql.php b/thinkphp/library/think/db/connector/Pgsql.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/db/connector/Sqlite.php b/thinkphp/library/think/db/connector/Sqlite.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/db/connector/Sqlsrv.php b/thinkphp/library/think/db/connector/Sqlsrv.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/db/connector/pgsql.sql b/thinkphp/library/think/db/connector/pgsql.sql old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/db/exception/BindParamException.php b/thinkphp/library/think/db/exception/BindParamException.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/db/exception/DataNotFoundException.php b/thinkphp/library/think/db/exception/DataNotFoundException.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/db/exception/ModelNotFoundException.php b/thinkphp/library/think/db/exception/ModelNotFoundException.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/debug/Console.php b/thinkphp/library/think/debug/Console.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/debug/Html.php b/thinkphp/library/think/debug/Html.php old mode 100644 new mode 100755 index f8651aa..b6be7ad --- a/thinkphp/library/think/debug/Html.php +++ b/thinkphp/library/think/debug/Html.php @@ -53,7 +53,7 @@ class Html return false; } // 获取基本信息 - $runtime = number_format(microtime(true) - THINK_START_TIME, 10); + $runtime = number_format(microtime(true) - THINK_START_TIME, 10, '.', ''); $reqs = $runtime > 0 ? number_format(1 / $runtime, 2) : '∞'; $mem = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2); diff --git a/thinkphp/library/think/exception/ClassNotFoundException.php b/thinkphp/library/think/exception/ClassNotFoundException.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/exception/DbException.php b/thinkphp/library/think/exception/DbException.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/exception/ErrorException.php b/thinkphp/library/think/exception/ErrorException.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/exception/Handle.php b/thinkphp/library/think/exception/Handle.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/exception/HttpException.php b/thinkphp/library/think/exception/HttpException.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/exception/HttpResponseException.php b/thinkphp/library/think/exception/HttpResponseException.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/exception/PDOException.php b/thinkphp/library/think/exception/PDOException.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/exception/RouteNotFoundException.php b/thinkphp/library/think/exception/RouteNotFoundException.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/exception/TemplateNotFoundException.php b/thinkphp/library/think/exception/TemplateNotFoundException.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/exception/ThrowableError.php b/thinkphp/library/think/exception/ThrowableError.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/exception/ValidateException.php b/thinkphp/library/think/exception/ValidateException.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/log/driver/File.php b/thinkphp/library/think/log/driver/File.php old mode 100644 new mode 100755 index 4036cc4..fa84ac1 --- a/thinkphp/library/think/log/driver/File.php +++ b/thinkphp/library/think/log/driver/File.php @@ -25,6 +25,7 @@ class File 'file_size' => 2097152, 'path' => LOG_PATH, 'apart_level' => [], + 'max_files' => 0, ]; protected $writed = []; @@ -48,8 +49,20 @@ class File if ($this->config['single']) { $destination = $this->config['path'] . 'single.log'; } else { - $cli = IS_CLI ? '_cli' : ''; - $destination = $this->config['path'] . date('Ym') . DS . date('d') . $cli . '.log'; + $cli = IS_CLI ? '_cli' : ''; + + if ($this->config['max_files']) { + $filename = date('Ymd') . $cli . '.log'; + $files = glob($this->config['path'] . '*.log'); + + if (count($files) > $this->config['max_files']) { + unlink($files[0]); + } + } else { + $filename = date('Ym') . '/' . date('d') . $cli . '.log'; + } + + $destination = $this->config['path'] . $filename; } $path = dirname($destination); @@ -68,6 +81,8 @@ class File // 独立记录的日志级别 if ($this->config['single']) { $filename = $path . DS . $type . '.log'; + } elseif ($this->config['max_files']) { + $filename = $path . DS . date('Ymd') . '_' . $type . $cli . '.log'; } else { $filename = $path . DS . date('d') . '_' . $type . $cli . '.log'; } diff --git a/thinkphp/library/think/log/driver/Socket.php b/thinkphp/library/think/log/driver/Socket.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/log/driver/Test.php b/thinkphp/library/think/log/driver/Test.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/model/Collection.php b/thinkphp/library/think/model/Collection.php old mode 100644 new mode 100755 index 37d58ae..0406533 --- a/thinkphp/library/think/model/Collection.php +++ b/thinkphp/library/think/model/Collection.php @@ -16,20 +16,6 @@ use think\Model; class Collection extends BaseCollection { - /** - * 返回数组中指定的一列 - * @param string $column_key - * @param string|null $index_key - * @return array - */ - public function column($column_key, $index_key = null) - { - if (function_exists('array_column')) { - return array_column($this->toArray(), $column_key, $index_key); - } - return parent::column($column_key, $index_key); - } - /** * 延迟预载入关联查询 * @access public diff --git a/thinkphp/library/think/model/Merge.php b/thinkphp/library/think/model/Merge.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/model/Pivot.php b/thinkphp/library/think/model/Pivot.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/model/Relation.php b/thinkphp/library/think/model/Relation.php old mode 100644 new mode 100755 index b67bbf5..25fe88d --- a/thinkphp/library/think/model/Relation.php +++ b/thinkphp/library/think/model/Relation.php @@ -49,7 +49,7 @@ abstract class Relation } /** - * 获取当前的关联模型类 + * 获取当前的关联模型对象实例 * @access public * @return Model */ diff --git a/thinkphp/library/think/model/relation/BelongsTo.php b/thinkphp/library/think/model/relation/BelongsTo.php old mode 100644 new mode 100755 index dfd6114..c1cbab9 --- a/thinkphp/library/think/model/relation/BelongsTo.php +++ b/thinkphp/library/think/model/relation/BelongsTo.php @@ -52,6 +52,7 @@ class BelongsTo extends OneToOne call_user_func_array($closure, [ & $this->query]); } $relationModel = $this->query + ->removeWhereField($this->localKey) ->where($this->localKey, $this->parent->$foreignKey) ->relation($subRelation) ->find(); @@ -128,6 +129,7 @@ class BelongsTo extends OneToOne } if (!empty($range)) { + $this->query->removeWhereField($localKey); $data = $this->eagerlyWhere($this->query, [ $localKey => [ 'in', @@ -171,7 +173,8 @@ class BelongsTo extends OneToOne { $localKey = $this->localKey; $foreignKey = $this->foreignKey; - $data = $this->eagerlyWhere($this->query, [$localKey => $result->$foreignKey], $localKey, $relation, $subRelation, $closure); + $this->query->removeWhereField($localKey); + $data = $this->eagerlyWhere($this->query, [$localKey => $result->$foreignKey], $localKey, $relation, $subRelation, $closure); // 关联模型 if (!isset($data[$result->$foreignKey])) { $relationModel = null; @@ -220,4 +223,21 @@ class BelongsTo extends OneToOne return $this->parent->setRelation($this->relation, null); } + + /** + * 执行基础查询(仅执行一次) + * @access protected + * @return void + */ + protected function baseQuery() + { + if (empty($this->baseQuery)) { + if (isset($this->parent->{$this->foreignKey})) { + // 关联查询带入关联条件 + $this->query->where($this->localKey, '=', $this->parent->{$this->foreignKey}); + } + + $this->baseQuery = true; + } + } } diff --git a/thinkphp/library/think/model/relation/BelongsToMany.php b/thinkphp/library/think/model/relation/BelongsToMany.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/model/relation/HasMany.php b/thinkphp/library/think/model/relation/HasMany.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/model/relation/HasManyThrough.php b/thinkphp/library/think/model/relation/HasManyThrough.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/model/relation/HasOne.php b/thinkphp/library/think/model/relation/HasOne.php old mode 100644 new mode 100755 index f64f133..db74e4a --- a/thinkphp/library/think/model/relation/HasOne.php +++ b/thinkphp/library/think/model/relation/HasOne.php @@ -50,7 +50,11 @@ class HasOne extends OneToOne call_user_func_array($closure, [ & $this->query]); } // 判断关联类型执行查询 - $relationModel = $this->query->where($this->foreignKey, $this->parent->$localKey)->relation($subRelation)->find(); + $relationModel = $this->query + ->removeWhereField($this->foreignKey) + ->where($this->foreignKey, $this->parent->$localKey) + ->relation($subRelation) + ->find(); if ($relationModel) { $relationModel->setParent(clone $this->parent); @@ -130,7 +134,8 @@ class HasOne extends OneToOne } if (!empty($range)) { - $data = $this->eagerlyWhere($this, [ + $this->query->removeWhereField($foreignKey); + $data = $this->eagerlyWhere($this->query, [ $foreignKey => [ 'in', $range, @@ -172,7 +177,8 @@ class HasOne extends OneToOne { $localKey = $this->localKey; $foreignKey = $this->foreignKey; - $data = $this->eagerlyWhere($this, [$foreignKey => $result->$localKey], $foreignKey, $relation, $subRelation, $closure); + $this->query->removeWhereField($foreignKey); + $data = $this->eagerlyWhere($this->query, [$foreignKey => $result->$localKey], $foreignKey, $relation, $subRelation, $closure); // 关联模型 if (!isset($data[$result->$localKey])) { @@ -190,4 +196,20 @@ class HasOne extends OneToOne } } + /** + * 执行基础查询(仅执行一次) + * @access protected + * @return void + */ + protected function baseQuery() + { + if (empty($this->baseQuery)) { + if (isset($this->parent->{$this->localKey})) { + // 关联查询带入关联条件 + $this->query->where($this->foreignKey, '=', $this->parent->{$this->localKey}); + } + + $this->baseQuery = true; + } + } } diff --git a/thinkphp/library/think/model/relation/MorphMany.php b/thinkphp/library/think/model/relation/MorphMany.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/model/relation/MorphOne.php b/thinkphp/library/think/model/relation/MorphOne.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/model/relation/MorphTo.php b/thinkphp/library/think/model/relation/MorphTo.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/model/relation/OneToOne.php b/thinkphp/library/think/model/relation/OneToOne.php old mode 100644 new mode 100755 index 02d7d56..dd8595c --- a/thinkphp/library/think/model/relation/OneToOne.php +++ b/thinkphp/library/think/model/relation/OneToOne.php @@ -304,6 +304,8 @@ abstract class OneToOne extends Relation */ protected function eagerlyWhere($model, $where, $key, $relation, $subRelation = '', $closure = false) { + $this->baseQuery = true; + // 预载入关联查询 支持嵌套预载入 if ($closure) { call_user_func_array($closure, [ & $model]); diff --git a/thinkphp/library/think/paginator/driver/Bootstrap.php b/thinkphp/library/think/paginator/driver/Bootstrap.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/process/Builder.php b/thinkphp/library/think/process/Builder.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/process/Utils.php b/thinkphp/library/think/process/Utils.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/process/exception/Failed.php b/thinkphp/library/think/process/exception/Failed.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/process/exception/Timeout.php b/thinkphp/library/think/process/exception/Timeout.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/process/pipes/Pipes.php b/thinkphp/library/think/process/pipes/Pipes.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/process/pipes/Unix.php b/thinkphp/library/think/process/pipes/Unix.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/process/pipes/Windows.php b/thinkphp/library/think/process/pipes/Windows.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/response/Json.php b/thinkphp/library/think/response/Json.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/response/Jsonp.php b/thinkphp/library/think/response/Jsonp.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/response/Redirect.php b/thinkphp/library/think/response/Redirect.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/response/View.php b/thinkphp/library/think/response/View.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/response/Xml.php b/thinkphp/library/think/response/Xml.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/session/driver/Memcache.php b/thinkphp/library/think/session/driver/Memcache.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/session/driver/Memcached.php b/thinkphp/library/think/session/driver/Memcached.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/session/driver/Redis.php b/thinkphp/library/think/session/driver/Redis.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/template/TagLib.php b/thinkphp/library/think/template/TagLib.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/template/driver/File.php b/thinkphp/library/think/template/driver/File.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/template/taglib/Cx.php b/thinkphp/library/think/template/taglib/Cx.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/view/driver/Php.php b/thinkphp/library/think/view/driver/Php.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/think/view/driver/Think.php b/thinkphp/library/think/view/driver/Think.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/traits/controller/Jump.php b/thinkphp/library/traits/controller/Jump.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/traits/model/SoftDelete.php b/thinkphp/library/traits/model/SoftDelete.php old mode 100644 new mode 100755 diff --git a/thinkphp/library/traits/think/Instance.php b/thinkphp/library/traits/think/Instance.php old mode 100644 new mode 100755 diff --git a/thinkphp/logo.png b/thinkphp/logo.png old mode 100644 new mode 100755 diff --git a/thinkphp/phpunit.xml b/thinkphp/phpunit.xml old mode 100644 new mode 100755 diff --git a/thinkphp/start.php b/thinkphp/start.php old mode 100644 new mode 100755 diff --git a/thinkphp/tpl/default_index.tpl b/thinkphp/tpl/default_index.tpl old mode 100644 new mode 100755 diff --git a/thinkphp/tpl/dispatch_jump.tpl b/thinkphp/tpl/dispatch_jump.tpl old mode 100644 new mode 100755 diff --git a/thinkphp/tpl/page_trace.tpl b/thinkphp/tpl/page_trace.tpl old mode 100644 new mode 100755 diff --git a/thinkphp/tpl/think_exception.tpl b/thinkphp/tpl/think_exception.tpl old mode 100644 new mode 100755