├── .gitignore ├── README.md ├── extend └── .gitignore ├── index.php ├── public ├── assets │ ├── css │ │ ├── admin.css │ │ ├── amazeui.datatables.min.css │ │ ├── amazeui.min.css │ │ ├── app.css │ │ ├── app.less │ │ ├── fullcalendar.min.css │ │ └── fullcalendar.print.css │ ├── fonts │ │ ├── FontAwesome.otf │ │ ├── fontawesome-webfont.eot │ │ ├── fontawesome-webfont.ttf │ │ ├── fontawesome-webfont.woff │ │ └── fontawesome-webfont.woff2 │ ├── i │ │ ├── app-icon72x72@2x.png │ │ ├── examples │ │ │ ├── admin-chrome.png │ │ │ ├── admin-firefox.png │ │ │ ├── admin-ie.png │ │ │ ├── admin-opera.png │ │ │ ├── admin-safari.png │ │ │ ├── adminPage.png │ │ │ ├── blogPage.png │ │ │ ├── landing.png │ │ │ ├── landingPage.png │ │ │ ├── loginPage.png │ │ │ └── sidebarPage.png │ │ ├── favicon.png │ │ └── startup-640x1096.png │ ├── img │ │ ├── a5.png │ │ ├── k.jpg │ │ ├── logo.png │ │ ├── logoa.png │ │ ├── logob.png │ │ ├── user01.png │ │ ├── user02.png │ │ ├── user03.png │ │ ├── user04.png │ │ ├── user05.png │ │ ├── user06.png │ │ └── user07.png │ └── js │ │ ├── amazeui.datatables.min.js │ │ ├── app.js │ │ ├── dataTables.responsive.min.js │ │ ├── fullcalendar.min.js │ │ ├── jquery.min.js │ │ ├── moment.js │ │ └── theme.js ├── img │ └── landscape.jpg ├── js │ ├── amazeui_2.7.2_js_amazeui.min.js │ ├── jquery-1.11.0.min.js │ ├── jquery.min.js │ ├── layer.js │ ├── layer2.js │ ├── main.js │ └── modernizr-custom.js ├── logo.ico └── readme │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── 4.jpg │ ├── 5.jpg │ ├── 6.png │ ├── 7.png │ ├── 8.jpg │ └── 8.png ├── thinkphp ├── .gitignore ├── .htaccess ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE.txt ├── README.md ├── base.php ├── codecov.yml ├── composer.json ├── console.php ├── convention.php ├── helper.php ├── lang │ └── zh-cn.php ├── library │ ├── think │ │ ├── App.php │ │ ├── Build.php │ │ ├── Cache.php │ │ ├── Collection.php │ │ ├── Config.php │ │ ├── Console.php │ │ ├── Controller.php │ │ ├── Cookie.php │ │ ├── Db.php │ │ ├── Debug.php │ │ ├── Env.php │ │ ├── Error.php │ │ ├── Exception.php │ │ ├── File.php │ │ ├── Hook.php │ │ ├── Lang.php │ │ ├── Loader.php │ │ ├── Log.php │ │ ├── Model.php │ │ ├── Paginator.php │ │ ├── Process.php │ │ ├── Request.php │ │ ├── Response.php │ │ ├── Route.php │ │ ├── Session.php │ │ ├── Template.php │ │ ├── Url.php │ │ ├── Validate.php │ │ ├── View.php │ │ ├── cache │ │ │ ├── Driver.php │ │ │ └── driver │ │ │ │ ├── File.php │ │ │ │ ├── Lite.php │ │ │ │ ├── Memcache.php │ │ │ │ ├── Memcached.php │ │ │ │ ├── Redis.php │ │ │ │ ├── Sqlite.php │ │ │ │ ├── Wincache.php │ │ │ │ └── Xcache.php │ │ ├── config │ │ │ └── driver │ │ │ │ ├── Ini.php │ │ │ │ ├── Json.php │ │ │ │ └── Xml.php │ │ ├── console │ │ │ ├── Command.php │ │ │ ├── Input.php │ │ │ ├── LICENSE │ │ │ ├── Output.php │ │ │ ├── bin │ │ │ │ ├── README.md │ │ │ │ └── hiddeninput.exe │ │ │ ├── command │ │ │ │ ├── Build.php │ │ │ │ ├── Clear.php │ │ │ │ ├── Help.php │ │ │ │ ├── Lists.php │ │ │ │ ├── Make.php │ │ │ │ ├── make │ │ │ │ │ ├── Controller.php │ │ │ │ │ ├── Model.php │ │ │ │ │ └── stubs │ │ │ │ │ │ ├── controller.plain.stub │ │ │ │ │ │ ├── controller.stub │ │ │ │ │ │ └── model.stub │ │ │ │ └── optimize │ │ │ │ │ ├── Autoload.php │ │ │ │ │ ├── Config.php │ │ │ │ │ ├── Route.php │ │ │ │ │ └── Schema.php │ │ │ ├── input │ │ │ │ ├── Argument.php │ │ │ │ ├── Definition.php │ │ │ │ └── Option.php │ │ │ └── output │ │ │ │ ├── Ask.php │ │ │ │ ├── Descriptor.php │ │ │ │ ├── Formatter.php │ │ │ │ ├── Question.php │ │ │ │ ├── descriptor │ │ │ │ └── Console.php │ │ │ │ ├── driver │ │ │ │ ├── Buffer.php │ │ │ │ ├── Console.php │ │ │ │ └── Nothing.php │ │ │ │ ├── formatter │ │ │ │ ├── Stack.php │ │ │ │ └── Style.php │ │ │ │ └── question │ │ │ │ ├── Choice.php │ │ │ │ └── Confirmation.php │ │ ├── controller │ │ │ ├── Rest.php │ │ │ └── Yar.php │ │ ├── db │ │ │ ├── Builder.php │ │ │ ├── Connection.php │ │ │ ├── Query.php │ │ │ ├── builder │ │ │ │ ├── Mysql.php │ │ │ │ ├── Pgsql.php │ │ │ │ ├── Sqlite.php │ │ │ │ └── Sqlsrv.php │ │ │ ├── connector │ │ │ │ ├── Mysql.php │ │ │ │ ├── Pgsql.php │ │ │ │ ├── Sqlite.php │ │ │ │ ├── Sqlsrv.php │ │ │ │ └── pgsql.sql │ │ │ └── exception │ │ │ │ ├── BindParamException.php │ │ │ │ ├── DataNotFoundException.php │ │ │ │ └── ModelNotFoundException.php │ │ ├── debug │ │ │ ├── Console.php │ │ │ └── Html.php │ │ ├── exception │ │ │ ├── ClassNotFoundException.php │ │ │ ├── DbException.php │ │ │ ├── ErrorException.php │ │ │ ├── Handle.php │ │ │ ├── HttpException.php │ │ │ ├── HttpResponseException.php │ │ │ ├── PDOException.php │ │ │ ├── RouteNotFoundException.php │ │ │ ├── TemplateNotFoundException.php │ │ │ ├── ThrowableError.php │ │ │ └── ValidateException.php │ │ ├── log │ │ │ └── driver │ │ │ │ ├── File.php │ │ │ │ ├── Socket.php │ │ │ │ └── Test.php │ │ ├── model │ │ │ ├── Collection.php │ │ │ ├── Merge.php │ │ │ ├── Pivot.php │ │ │ ├── Relation.php │ │ │ └── relation │ │ │ │ ├── BelongsTo.php │ │ │ │ ├── BelongsToMany.php │ │ │ │ ├── HasMany.php │ │ │ │ ├── HasManyThrough.php │ │ │ │ ├── HasOne.php │ │ │ │ ├── MorphMany.php │ │ │ │ ├── MorphOne.php │ │ │ │ ├── MorphTo.php │ │ │ │ └── OneToOne.php │ │ ├── paginator │ │ │ └── driver │ │ │ │ └── Bootstrap.php │ │ ├── process │ │ │ ├── Builder.php │ │ │ ├── Utils.php │ │ │ ├── exception │ │ │ │ ├── Failed.php │ │ │ │ └── Timeout.php │ │ │ └── pipes │ │ │ │ ├── Pipes.php │ │ │ │ ├── Unix.php │ │ │ │ └── Windows.php │ │ ├── response │ │ │ ├── Json.php │ │ │ ├── Jsonp.php │ │ │ ├── Redirect.php │ │ │ ├── View.php │ │ │ └── Xml.php │ │ ├── session │ │ │ └── driver │ │ │ │ ├── Memcache.php │ │ │ │ ├── Memcached.php │ │ │ │ └── Redis.php │ │ ├── template │ │ │ ├── TagLib.php │ │ │ ├── driver │ │ │ │ └── File.php │ │ │ └── taglib │ │ │ │ └── Cx.php │ │ └── view │ │ │ └── driver │ │ │ ├── Php.php │ │ │ └── Think.php │ └── traits │ │ ├── controller │ │ └── Jump.php │ │ ├── model │ │ └── SoftDelete.php │ │ └── think │ │ └── Instance.php ├── logo.png ├── phpunit.xml ├── start.php └── tpl │ ├── default_index.tpl │ ├── dispatch_jump.tpl │ ├── page_trace.tpl │ └── think_exception.tpl └── vendor └── .gitignore /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | runtime 3 | public/uploads 4 | common.php 5 | Common.php 6 | public/photo 7 | application -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 人脸识别门禁系统 2 | 3 | ## 可以在线实时的检测人脸,是实时的不需要上传图片,对于已经录入人脸库的,可以显示通过,支持后台注册人脸,以及管理人脸库的信息,后期还会加入每日检测历史记录。 4 | 5 | 开发日志: 6 | 7 | 2018-6-14添加了日志模块,可以查看人脸登录信息,成功或失败都会显示出来 8 | 9 | 2018-6-9 对手机端进行了页面支持,可以在微信中直接打开视频流 10 | 11 | 2018-6-5添加了登录功能,管理员需要登录 12 | 13 | 完善了门禁界面,采用自动化人脸采集,界面更加洁净,当有人脸出现时,能够识别并在弹窗中显示采集到的照片和验证信息,弹窗固定时间后自动消失,进行下一次比对,技术就是多个计时器和定时器联动使用。 14 | 15 | 16 | 17 | ## 最新版本图,自动采集 18 | 19 | ![](/public/readme/7.png) 20 | 21 | ![](/public/readme/8.png) 22 | 23 | ![](/public/readme/6.png) 24 | 25 | 26 | 27 | ### 下面是效果图 28 | 29 | ![](/public/readme/1.jpg) 30 | ![](/public/readme/2.jpg) 31 | ![](/public/readme/3.jpg) 32 | ![](/public/readme/4.jpg) 33 | ![](/public/readme/5.jpg) -------------------------------------------------------------------------------- /extend/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | // [ 应用入口文件 ] 13 | define('VENDOR_PATH', __DIR__ .'/vendor/'); 14 | // 定义应用目录 15 | define('APP_PATH', __DIR__ . '/application/'); 16 | // 定义配置文件目录和应用目录同级 17 | define('CONF_PATH', __DIR__.'/application/config/'); 18 | // 加载框架引导文件 19 | require __DIR__ . '/thinkphp/start.php'; 20 | -------------------------------------------------------------------------------- /public/assets/fonts/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/fonts/FontAwesome.otf -------------------------------------------------------------------------------- /public/assets/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /public/assets/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /public/assets/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /public/assets/fonts/fontawesome-webfont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/fonts/fontawesome-webfont.woff2 -------------------------------------------------------------------------------- /public/assets/i/app-icon72x72@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/i/app-icon72x72@2x.png -------------------------------------------------------------------------------- /public/assets/i/examples/admin-chrome.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/i/examples/admin-chrome.png -------------------------------------------------------------------------------- /public/assets/i/examples/admin-firefox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/i/examples/admin-firefox.png -------------------------------------------------------------------------------- /public/assets/i/examples/admin-ie.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/i/examples/admin-ie.png -------------------------------------------------------------------------------- /public/assets/i/examples/admin-opera.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/i/examples/admin-opera.png -------------------------------------------------------------------------------- /public/assets/i/examples/admin-safari.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/i/examples/admin-safari.png -------------------------------------------------------------------------------- /public/assets/i/examples/adminPage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/i/examples/adminPage.png -------------------------------------------------------------------------------- /public/assets/i/examples/blogPage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/i/examples/blogPage.png -------------------------------------------------------------------------------- /public/assets/i/examples/landing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/i/examples/landing.png -------------------------------------------------------------------------------- /public/assets/i/examples/landingPage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/i/examples/landingPage.png -------------------------------------------------------------------------------- /public/assets/i/examples/loginPage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/i/examples/loginPage.png -------------------------------------------------------------------------------- /public/assets/i/examples/sidebarPage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/i/examples/sidebarPage.png -------------------------------------------------------------------------------- /public/assets/i/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/i/favicon.png -------------------------------------------------------------------------------- /public/assets/i/startup-640x1096.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/i/startup-640x1096.png -------------------------------------------------------------------------------- /public/assets/img/a5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/img/a5.png -------------------------------------------------------------------------------- /public/assets/img/k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/img/k.jpg -------------------------------------------------------------------------------- /public/assets/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/img/logo.png -------------------------------------------------------------------------------- /public/assets/img/logoa.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/img/logoa.png -------------------------------------------------------------------------------- /public/assets/img/logob.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/img/logob.png -------------------------------------------------------------------------------- /public/assets/img/user01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/img/user01.png -------------------------------------------------------------------------------- /public/assets/img/user02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/img/user02.png -------------------------------------------------------------------------------- /public/assets/img/user03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/img/user03.png -------------------------------------------------------------------------------- /public/assets/img/user04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/img/user04.png -------------------------------------------------------------------------------- /public/assets/img/user05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/img/user05.png -------------------------------------------------------------------------------- /public/assets/img/user06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/img/user06.png -------------------------------------------------------------------------------- /public/assets/img/user07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/assets/img/user07.png -------------------------------------------------------------------------------- /public/assets/js/theme.js: -------------------------------------------------------------------------------- 1 | var saveSelectColor = { 2 | 'Name': 'SelcetColor', 3 | 'Color': 'theme-white' 4 | } 5 | 6 | 7 | 8 | // 判断用户是否已有自己选择的模板风格 9 | if (storageLoad('SelcetColor')) { 10 | $('body').attr('class', storageLoad('SelcetColor').Color) 11 | } else { 12 | storageSave(saveSelectColor); 13 | $('body').attr('class', 'theme-white') 14 | } 15 | 16 | 17 | // 本地缓存 18 | function storageSave(objectData) { 19 | localStorage.setItem(objectData.Name, JSON.stringify(objectData)); 20 | } 21 | 22 | function storageLoad(objectName) { 23 | if (localStorage.getItem(objectName)) { 24 | return JSON.parse(localStorage.getItem(objectName)) 25 | } else { 26 | return false 27 | } 28 | } -------------------------------------------------------------------------------- /public/img/landscape.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/public/img/landscape.jpg -------------------------------------------------------------------------------- /public/js/modernizr-custom.js: -------------------------------------------------------------------------------- 1 | /*! modernizr 3.3.1 (Custom Build) | MIT * 2 | * https://modernizr.com/download/?-csstransitions-setclasses !*/ 3 | !function(e,n,t){function r(e,n){return typeof e===n}function s(){var e,n,t,s,o,i,a;for(var l in C)if(C.hasOwnProperty(l)){if(e=[],n=C[l],n.name&&(e.push(n.name.toLowerCase()),n.options&&n.options.aliases&&n.options.aliases.length))for(t=0;tp;p++)if(h=e[p],v=z.style[h],a(h,"-")&&(h=l(h)),z.style[h]!==t){if(o||r(s,"undefined"))return f(),"pfx"==n?h:!0;try{z.style[h]=s}catch(g){}if(z.style[h]!=v)return f(),"pfx"==n?h:!0}return f(),!1}function v(e,n,t,s,o){var i=e.charAt(0).toUpperCase()+e.slice(1),a=(e+" "+b.join(i+" ")+i).split(" ");return r(n,"string")||r(n,"undefined")?h(a,n,s,o):(a=(e+" "+E.join(i+" ")+i).split(" "),u(a,n,t))}function y(e,n,r){return v(e,t,t,n,r)}var g=[],C=[],w={_version:"3.3.1",_config:{classPrefix:"",enableClasses:!0,enableJSClass:!0,usePrefixes:!0},_q:[],on:function(e,n){var t=this;setTimeout(function(){n(t[e])},0)},addTest:function(e,n,t){C.push({name:e,fn:n,options:t})},addAsyncTest:function(e){C.push({name:null,fn:e})}},Modernizr=function(){};Modernizr.prototype=w,Modernizr=new Modernizr;var _=n.documentElement,S="svg"===_.nodeName.toLowerCase(),x="Moz O ms Webkit",b=w._config.usePrefixes?x.split(" "):[];w._cssomPrefixes=b;var E=w._config.usePrefixes?x.toLowerCase().split(" "):[];w._domPrefixes=E;var P={elem:i("modernizr")};Modernizr._q.push(function(){delete P.elem});var z={style:P.elem.style};Modernizr._q.unshift(function(){delete z.style}),w.testAllProps=v,w.testAllProps=y,Modernizr.addTest("csstransitions",y("transition","all",!0)),s(),o(g),delete w.addTest,delete w.addAsyncTest;for(var N=0;N ThinkPHP5的运行环境要求PHP5.4以上。 34 | 35 | 详细开发文档参考 [ThinkPHP5完全开发手册](http://www.kancloud.cn/manual/thinkphp5) 以及[ThinkPHP5入门系列教程](http://www.kancloud.cn/special/thinkphp5_quickstart) 36 | 37 | ## 目录结构 38 | 39 | 初始的目录结构如下: 40 | 41 | ~~~ 42 | www WEB部署目录(或者子目录) 43 | ├─application 应用目录 44 | │ ├─common 公共模块目录(可以更改) 45 | │ ├─module_name 模块目录 46 | │ │ ├─config.php 模块配置文件 47 | │ │ ├─common.php 模块函数文件 48 | │ │ ├─controller 控制器目录 49 | │ │ ├─model 模型目录 50 | │ │ ├─view 视图目录 51 | │ │ └─ ... 更多类库目录 52 | │ │ 53 | │ ├─command.php 命令行工具配置文件 54 | │ ├─common.php 公共函数文件 55 | │ ├─config.php 公共配置文件 56 | │ ├─route.php 路由配置文件 57 | │ ├─tags.php 应用行为扩展定义文件 58 | │ └─database.php 数据库配置文件 59 | │ 60 | ├─public WEB目录(对外访问目录) 61 | │ ├─index.php 入口文件 62 | │ ├─router.php 快速测试文件 63 | │ └─.htaccess 用于apache的重写 64 | │ 65 | ├─thinkphp 框架系统目录 66 | │ ├─lang 语言文件目录 67 | │ ├─library 框架类库目录 68 | │ │ ├─think Think类库包目录 69 | │ │ └─traits 系统Trait目录 70 | │ │ 71 | │ ├─tpl 系统模板目录 72 | │ ├─base.php 基础定义文件 73 | │ ├─console.php 控制台入口文件 74 | │ ├─convention.php 框架惯例配置文件 75 | │ ├─helper.php 助手函数文件 76 | │ ├─phpunit.xml phpunit配置文件 77 | │ └─start.php 框架入口文件 78 | │ 79 | ├─extend 扩展类库目录 80 | ├─runtime 应用的运行时目录(可写,可定制) 81 | ├─vendor 第三方类库目录(Composer依赖库) 82 | ├─build.php 自动生成定义文件(参考) 83 | ├─composer.json composer 定义文件 84 | ├─LICENSE.txt 授权说明文件 85 | ├─README.md README 文件 86 | ├─think 命令行入口文件 87 | ~~~ 88 | 89 | > router.php用于php自带webserver支持,可用于快速测试 90 | > 切换到public目录后,启动命令:php -S localhost:8888 router.php 91 | > 上面的目录结构和名称是可以改变的,这取决于你的入口文件和配置参数。 92 | 93 | ## 命名规范 94 | 95 | ThinkPHP5的命名规范遵循PSR-2规范以及PSR-4自动加载规范。 96 | 97 | ## 参与开发 98 | 注册并登录 Github 帐号, fork 本项目并进行改动。 99 | 100 | 更多细节参阅 [CONTRIBUTING.md](CONTRIBUTING.md) 101 | 102 | ## 版权信息 103 | 104 | ThinkPHP遵循Apache2开源协议发布,并提供免费使用。 105 | 106 | 本项目包含的第三方源码和二进制文件之版权信息另行标注。 107 | 108 | 版权所有Copyright © 2006-2016 by ThinkPHP (http://thinkphp.cn) 109 | 110 | All rights reserved。 111 | 112 | ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。 113 | 114 | 更多细节参阅 [LICENSE.txt](LICENSE.txt) 115 | -------------------------------------------------------------------------------- /thinkphp/base.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | define('THINK_VERSION', '5.0.11'); 13 | define('THINK_START_TIME', microtime(true)); 14 | define('THINK_START_MEM', memory_get_usage()); 15 | define('EXT', '.php'); 16 | define('DS', DIRECTORY_SEPARATOR); 17 | defined('THINK_PATH') or define('THINK_PATH', __DIR__ . DS); 18 | define('LIB_PATH', THINK_PATH . 'library' . DS); 19 | define('CORE_PATH', LIB_PATH . 'think' . DS); 20 | define('TRAIT_PATH', LIB_PATH . 'traits' . DS); 21 | defined('APP_PATH') or define('APP_PATH', dirname($_SERVER['SCRIPT_FILENAME']) . DS); 22 | defined('ROOT_PATH') or define('ROOT_PATH', dirname(realpath(APP_PATH)) . DS); 23 | defined('EXTEND_PATH') or define('EXTEND_PATH', ROOT_PATH . 'extend' . DS); 24 | defined('VENDOR_PATH') or define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS); 25 | defined('RUNTIME_PATH') or define('RUNTIME_PATH', ROOT_PATH . 'runtime' . DS); 26 | defined('LOG_PATH') or define('LOG_PATH', RUNTIME_PATH . 'log' . DS); 27 | defined('CACHE_PATH') or define('CACHE_PATH', RUNTIME_PATH . 'cache' . DS); 28 | defined('TEMP_PATH') or define('TEMP_PATH', RUNTIME_PATH . 'temp' . DS); 29 | defined('CONF_PATH') or define('CONF_PATH', APP_PATH); // 配置文件目录 30 | defined('CONF_EXT') or define('CONF_EXT', EXT); // 配置文件后缀 31 | defined('ENV_PREFIX') or define('ENV_PREFIX', 'PHP_'); // 环境变量的配置前缀 32 | 33 | // 环境常量 34 | define('IS_CLI', PHP_SAPI == 'cli' ? true : false); 35 | define('IS_WIN', strpos(PHP_OS, 'WIN') !== false); 36 | 37 | // 载入Loader类 38 | require CORE_PATH . 'Loader.php'; 39 | 40 | // 加载环境变量配置文件 41 | if (is_file(ROOT_PATH . '.env')) { 42 | $env = parse_ini_file(ROOT_PATH . '.env', true); 43 | foreach ($env as $key => $val) { 44 | $name = ENV_PREFIX . strtoupper($key); 45 | if (is_array($val)) { 46 | foreach ($val as $k => $v) { 47 | $item = $name . '_' . strtoupper($k); 48 | putenv("$item=$v"); 49 | } 50 | } else { 51 | putenv("$name=$val"); 52 | } 53 | } 54 | } 55 | 56 | // 注册自动加载 57 | \think\Loader::register(); 58 | 59 | // 注册错误和异常处理机制 60 | \think\Error::register(); 61 | 62 | // 加载惯例配置文件 63 | \think\Config::set(include THINK_PATH . 'convention' . EXT); 64 | -------------------------------------------------------------------------------- /thinkphp/codecov.yml: -------------------------------------------------------------------------------- 1 | comment: 2 | layout: header, changes, diff 3 | coverage: 4 | ignore: 5 | - base.php 6 | - helper.php 7 | - convention.php 8 | - lang/zh-cn.php 9 | - start.php 10 | - console.php 11 | status: 12 | patch: false 13 | -------------------------------------------------------------------------------- /thinkphp/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "topthink/framework", 3 | "description": "the new thinkphp framework", 4 | "type": "think-framework", 5 | "keywords": [ 6 | "framework", 7 | "thinkphp", 8 | "ORM" 9 | ], 10 | "homepage": "http://thinkphp.cn/", 11 | "license": "Apache-2.0", 12 | "authors": [ 13 | { 14 | "name": "liu21st", 15 | "email": "liu21st@gmail.com" 16 | } 17 | ], 18 | "require": { 19 | "php": ">=5.4.0", 20 | "topthink/think-installer": "~1.0" 21 | }, 22 | "require-dev": { 23 | "phpunit/phpunit": "4.8.*", 24 | "johnkary/phpunit-speedtrap": "^1.0", 25 | "mikey179/vfsStream": "~1.6", 26 | "phploc/phploc": "2.*", 27 | "sebastian/phpcpd": "2.*", 28 | "phpdocumentor/reflection-docblock": "^2.0" 29 | }, 30 | "autoload": { 31 | "psr-4": { 32 | "think\\": "library/think" 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /thinkphp/console.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think; 13 | 14 | // ThinkPHP 引导文件 15 | // 加载基础文件 16 | require __DIR__ . '/base.php'; 17 | 18 | // 执行应用 19 | App::initCommon(); 20 | Console::init(); 21 | -------------------------------------------------------------------------------- /thinkphp/lang/zh-cn.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | // 核心中文语言包 13 | return [ 14 | // 系统错误提示 15 | 'Undefined variable' => '未定义变量', 16 | 'Undefined index' => '未定义数组索引', 17 | 'Undefined offset' => '未定义数组下标', 18 | 'Parse error' => '语法解析错误', 19 | 'Type error' => '类型错误', 20 | 'Fatal error' => '致命错误', 21 | 'syntax error' => '语法错误', 22 | 23 | // 框架核心错误提示 24 | 'dispatch type not support' => '不支持的调度类型', 25 | 'method param miss' => '方法参数错误', 26 | 'method not exists' => '方法不存在', 27 | 'module not exists' => '模块不存在', 28 | 'controller not exists' => '控制器不存在', 29 | 'class not exists' => '类不存在', 30 | 'property not exists' => '类的属性不存在', 31 | 'template not exists' => '模板文件不存在', 32 | 'illegal controller name' => '非法的控制器名称', 33 | 'illegal action name' => '非法的操作名称', 34 | 'url suffix deny' => '禁止的URL后缀访问', 35 | 'Route Not Found' => '当前访问路由未定义', 36 | 'Undefined db type' => '未定义数据库类型', 37 | 'variable type error' => '变量类型错误', 38 | 'PSR-4 error' => 'PSR-4 规范错误', 39 | 'not support total' => '简洁模式下不能获取数据总数', 40 | 'not support last' => '简洁模式下不能获取最后一页', 41 | 'error session handler' => '错误的SESSION处理器类', 42 | 'not allow php tag' => '模板不允许使用PHP语法', 43 | 'not support' => '不支持', 44 | 'redisd master' => 'Redisd 主服务器错误', 45 | 'redisd slave' => 'Redisd 从服务器错误', 46 | 'must run at sae' => '必须在SAE运行', 47 | 'memcache init error' => '未开通Memcache服务,请在SAE管理平台初始化Memcache服务', 48 | 'KVDB init error' => '没有初始化KVDB,请在SAE管理平台初始化KVDB服务', 49 | 'fields not exists' => '数据表字段不存在', 50 | 'where express error' => '查询表达式错误', 51 | 'no data to update' => '没有任何数据需要更新', 52 | 'miss data to insert' => '缺少需要写入的数据', 53 | 'miss complex primary data' => '缺少复合主键数据', 54 | 'miss update condition' => '缺少更新条件', 55 | 'model data Not Found' => '模型数据不存在', 56 | 'table data not Found' => '表数据不存在', 57 | 'delete without condition' => '没有条件不会执行删除操作', 58 | 'miss relation data' => '缺少关联表数据', 59 | 'tag attr must' => '模板标签属性必须', 60 | 'tag error' => '模板标签错误', 61 | 'cache write error' => '缓存写入失败', 62 | 'sae mc write error' => 'SAE mc 写入错误', 63 | 'route name not exists' => '路由标识不存在(或参数不够)', 64 | 'invalid request' => '非法请求', 65 | 'bind attr has exists' => '模型的属性已经存在', 66 | 'relation data not exists' => '关联数据不存在', 67 | 'relation not support' => '关联不支持', 68 | 'chunk not support order' => 'Chunk不支持调用order方法', 69 | ]; 70 | -------------------------------------------------------------------------------- /thinkphp/library/think/Env.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think; 13 | 14 | class Env 15 | { 16 | /** 17 | * 获取环境变量值 18 | * @param string $name 环境变量名(支持二级 .号分割) 19 | * @param string $default 默认值 20 | * @return mixed 21 | */ 22 | public static function get($name, $default = null) 23 | { 24 | $result = getenv(ENV_PREFIX . strtoupper(str_replace('.', '_', $name))); 25 | if (false !== $result) { 26 | if ('false' === $result) { 27 | $result = false; 28 | } elseif ('true' === $result) { 29 | $result = true; 30 | } 31 | return $result; 32 | } else { 33 | return $default; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /thinkphp/library/think/Error.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think; 13 | 14 | use think\console\Output as ConsoleOutput; 15 | use think\exception\ErrorException; 16 | use think\exception\Handle; 17 | use think\exception\ThrowableError; 18 | 19 | class Error 20 | { 21 | /** 22 | * 注册异常处理 23 | * @return void 24 | */ 25 | public static function register() 26 | { 27 | error_reporting(E_ALL); 28 | set_error_handler([__CLASS__, 'appError']); 29 | set_exception_handler([__CLASS__, 'appException']); 30 | register_shutdown_function([__CLASS__, 'appShutdown']); 31 | } 32 | 33 | /** 34 | * Exception Handler 35 | * @param \Exception|\Throwable $e 36 | */ 37 | public static function appException($e) 38 | { 39 | if (!$e instanceof \Exception) { 40 | $e = new ThrowableError($e); 41 | } 42 | 43 | self::getExceptionHandler()->report($e); 44 | if (IS_CLI) { 45 | self::getExceptionHandler()->renderForConsole(new ConsoleOutput, $e); 46 | } else { 47 | self::getExceptionHandler()->render($e)->send(); 48 | } 49 | } 50 | 51 | /** 52 | * Error Handler 53 | * @param integer $errno 错误编号 54 | * @param integer $errstr 详细错误信息 55 | * @param string $errfile 出错的文件 56 | * @param integer $errline 出错行号 57 | * @param array $errcontext 58 | * @throws ErrorException 59 | */ 60 | public static function appError($errno, $errstr, $errfile = '', $errline = 0, $errcontext = []) 61 | { 62 | $exception = new ErrorException($errno, $errstr, $errfile, $errline, $errcontext); 63 | if (error_reporting() & $errno) { 64 | // 将错误信息托管至 think\exception\ErrorException 65 | throw $exception; 66 | } else { 67 | self::getExceptionHandler()->report($exception); 68 | } 69 | } 70 | 71 | /** 72 | * Shutdown Handler 73 | */ 74 | public static function appShutdown() 75 | { 76 | if (!is_null($error = error_get_last()) && self::isFatal($error['type'])) { 77 | // 将错误信息托管至think\ErrorException 78 | $exception = new ErrorException($error['type'], $error['message'], $error['file'], $error['line']); 79 | 80 | self::appException($exception); 81 | } 82 | 83 | // 写入日志 84 | Log::save(); 85 | } 86 | 87 | /** 88 | * 确定错误类型是否致命 89 | * 90 | * @param int $type 91 | * @return bool 92 | */ 93 | protected static function isFatal($type) 94 | { 95 | return in_array($type, [E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE]); 96 | } 97 | 98 | /** 99 | * Get an instance of the exception handler. 100 | * 101 | * @return Handle 102 | */ 103 | public static function getExceptionHandler() 104 | { 105 | static $handle; 106 | if (!$handle) { 107 | // 异常处理handle 108 | $class = Config::get('exception_handle'); 109 | if ($class && class_exists($class) && is_subclass_of($class, "\\think\\exception\\Handle")) { 110 | $handle = new $class; 111 | } else { 112 | $handle = new Handle; 113 | if ($class instanceof \Closure) { 114 | $handle->setRender($class); 115 | } 116 | } 117 | } 118 | return $handle; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /thinkphp/library/think/Exception.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think; 13 | 14 | class Exception extends \Exception 15 | { 16 | 17 | /** 18 | * 保存异常页面显示的额外Debug数据 19 | * @var array 20 | */ 21 | protected $data = []; 22 | 23 | /** 24 | * 设置异常额外的Debug数据 25 | * 数据将会显示为下面的格式 26 | * 27 | * Exception Data 28 | * -------------------------------------------------- 29 | * Label 1 30 | * key1 value1 31 | * key2 value2 32 | * Label 2 33 | * key1 value1 34 | * key2 value2 35 | * 36 | * @param string $label 数据分类,用于异常页面显示 37 | * @param array $data 需要显示的数据,必须为关联数组 38 | */ 39 | final protected function setData($label, array $data) 40 | { 41 | $this->data[$label] = $data; 42 | } 43 | 44 | /** 45 | * 获取异常额外Debug数据 46 | * 主要用于输出到异常页面便于调试 47 | * @return array 由setData设置的Debug数据 48 | */ 49 | final public function getData() 50 | { 51 | return $this->data; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /thinkphp/library/think/cache/driver/Wincache.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\cache\driver; 13 | 14 | use think\cache\Driver; 15 | 16 | /** 17 | * Wincache缓存驱动 18 | * @author liu21st 19 | */ 20 | class Wincache extends Driver 21 | { 22 | protected $options = [ 23 | 'prefix' => '', 24 | 'expire' => 0, 25 | ]; 26 | 27 | /** 28 | * 构造函数 29 | * @param array $options 缓存参数 30 | * @throws \BadFunctionCallException 31 | * @access public 32 | */ 33 | public function __construct($options = []) 34 | { 35 | if (!function_exists('wincache_ucache_info')) { 36 | throw new \BadFunctionCallException('not support: WinCache'); 37 | } 38 | if (!empty($options)) { 39 | $this->options = array_merge($this->options, $options); 40 | } 41 | } 42 | 43 | /** 44 | * 判断缓存 45 | * @access public 46 | * @param string $name 缓存变量名 47 | * @return bool 48 | */ 49 | public function has($name) 50 | { 51 | $key = $this->getCacheKey($name); 52 | return wincache_ucache_exists($key); 53 | } 54 | 55 | /** 56 | * 读取缓存 57 | * @access public 58 | * @param string $name 缓存变量名 59 | * @param mixed $default 默认值 60 | * @return mixed 61 | */ 62 | public function get($name, $default = false) 63 | { 64 | $key = $this->getCacheKey($name); 65 | return wincache_ucache_exists($key) ? wincache_ucache_get($key) : $default; 66 | } 67 | 68 | /** 69 | * 写入缓存 70 | * @access public 71 | * @param string $name 缓存变量名 72 | * @param mixed $value 存储数据 73 | * @param integer|\DateTime $expire 有效时间(秒) 74 | * @return boolean 75 | */ 76 | public function set($name, $value, $expire = null) 77 | { 78 | if (is_null($expire)) { 79 | $expire = $this->options['expire']; 80 | } 81 | if ($expire instanceof \DateTime) { 82 | $expire = $expire->getTimestamp() - time(); 83 | } 84 | $key = $this->getCacheKey($name); 85 | if ($this->tag && !$this->has($name)) { 86 | $first = true; 87 | } 88 | if (wincache_ucache_set($key, $value, $expire)) { 89 | isset($first) && $this->setTagItem($key); 90 | return true; 91 | } 92 | return false; 93 | } 94 | 95 | /** 96 | * 自增缓存(针对数值缓存) 97 | * @access public 98 | * @param string $name 缓存变量名 99 | * @param int $step 步长 100 | * @return false|int 101 | */ 102 | public function inc($name, $step = 1) 103 | { 104 | $key = $this->getCacheKey($name); 105 | return wincache_ucache_inc($key, $step); 106 | } 107 | 108 | /** 109 | * 自减缓存(针对数值缓存) 110 | * @access public 111 | * @param string $name 缓存变量名 112 | * @param int $step 步长 113 | * @return false|int 114 | */ 115 | public function dec($name, $step = 1) 116 | { 117 | $key = $this->getCacheKey($name); 118 | return wincache_ucache_dec($key, $step); 119 | } 120 | 121 | /** 122 | * 删除缓存 123 | * @access public 124 | * @param string $name 缓存变量名 125 | * @return boolean 126 | */ 127 | public function rm($name) 128 | { 129 | return wincache_ucache_delete($this->getCacheKey($name)); 130 | } 131 | 132 | /** 133 | * 清除缓存 134 | * @access public 135 | * @param string $tag 标签名 136 | * @return boolean 137 | */ 138 | public function clear($tag = null) 139 | { 140 | if ($tag) { 141 | $keys = $this->getTagItem($tag); 142 | foreach ($keys as $key) { 143 | wincache_ucache_delete($key); 144 | } 145 | $this->rm('tag_' . md5($tag)); 146 | return true; 147 | } else { 148 | return wincache_ucache_clear(); 149 | } 150 | } 151 | 152 | } 153 | -------------------------------------------------------------------------------- /thinkphp/library/think/cache/driver/Xcache.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\cache\driver; 13 | 14 | use think\cache\Driver; 15 | 16 | /** 17 | * Xcache缓存驱动 18 | * @author liu21st 19 | */ 20 | class Xcache extends Driver 21 | { 22 | protected $options = [ 23 | 'prefix' => '', 24 | 'expire' => 0, 25 | ]; 26 | 27 | /** 28 | * 构造函数 29 | * @param array $options 缓存参数 30 | * @access public 31 | * @throws \BadFunctionCallException 32 | */ 33 | public function __construct($options = []) 34 | { 35 | if (!function_exists('xcache_info')) { 36 | throw new \BadFunctionCallException('not support: Xcache'); 37 | } 38 | if (!empty($options)) { 39 | $this->options = array_merge($this->options, $options); 40 | } 41 | } 42 | 43 | /** 44 | * 判断缓存 45 | * @access public 46 | * @param string $name 缓存变量名 47 | * @return bool 48 | */ 49 | public function has($name) 50 | { 51 | $key = $this->getCacheKey($name); 52 | return xcache_isset($key); 53 | } 54 | 55 | /** 56 | * 读取缓存 57 | * @access public 58 | * @param string $name 缓存变量名 59 | * @param mixed $default 默认值 60 | * @return mixed 61 | */ 62 | public function get($name, $default = false) 63 | { 64 | $key = $this->getCacheKey($name); 65 | return xcache_isset($key) ? xcache_get($key) : $default; 66 | } 67 | 68 | /** 69 | * 写入缓存 70 | * @access public 71 | * @param string $name 缓存变量名 72 | * @param mixed $value 存储数据 73 | * @param integer|\DateTime $expire 有效时间(秒) 74 | * @return boolean 75 | */ 76 | public function set($name, $value, $expire = null) 77 | { 78 | if (is_null($expire)) { 79 | $expire = $this->options['expire']; 80 | } 81 | if ($expire instanceof \DateTime) { 82 | $expire = $expire->getTimestamp() - time(); 83 | } 84 | if ($this->tag && !$this->has($name)) { 85 | $first = true; 86 | } 87 | $key = $this->getCacheKey($name); 88 | if (xcache_set($key, $value, $expire)) { 89 | isset($first) && $this->setTagItem($key); 90 | return true; 91 | } 92 | return false; 93 | } 94 | 95 | /** 96 | * 自增缓存(针对数值缓存) 97 | * @access public 98 | * @param string $name 缓存变量名 99 | * @param int $step 步长 100 | * @return false|int 101 | */ 102 | public function inc($name, $step = 1) 103 | { 104 | $key = $this->getCacheKey($name); 105 | return xcache_inc($key, $step); 106 | } 107 | 108 | /** 109 | * 自减缓存(针对数值缓存) 110 | * @access public 111 | * @param string $name 缓存变量名 112 | * @param int $step 步长 113 | * @return false|int 114 | */ 115 | public function dec($name, $step = 1) 116 | { 117 | $key = $this->getCacheKey($name); 118 | return xcache_dec($key, $step); 119 | } 120 | 121 | /** 122 | * 删除缓存 123 | * @access public 124 | * @param string $name 缓存变量名 125 | * @return boolean 126 | */ 127 | public function rm($name) 128 | { 129 | return xcache_unset($this->getCacheKey($name)); 130 | } 131 | 132 | /** 133 | * 清除缓存 134 | * @access public 135 | * @param string $tag 标签名 136 | * @return boolean 137 | */ 138 | public function clear($tag = null) 139 | { 140 | if ($tag) { 141 | // 指定标签清除 142 | $keys = $this->getTagItem($tag); 143 | foreach ($keys as $key) { 144 | xcache_unset($key); 145 | } 146 | $this->rm('tag_' . md5($tag)); 147 | return true; 148 | } 149 | if (function_exists('xcache_unset_by_prefix')) { 150 | return xcache_unset_by_prefix($this->options['prefix']); 151 | } else { 152 | return false; 153 | } 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /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/Json.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\config\driver; 13 | 14 | class Json 15 | { 16 | public function parse($config) 17 | { 18 | if (is_file($config)) { 19 | $config = file_get_contents($config); 20 | } 21 | $result = json_decode($config, true); 22 | return $result; 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/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2004-2016 Fabien Potencier 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /thinkphp/library/think/console/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/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/thinkphp/library/think/console/bin/hiddeninput.exe -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/Build.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\command; 13 | 14 | use think\console\Command; 15 | use think\console\Input; 16 | use think\console\input\Option; 17 | use think\console\Output; 18 | 19 | class Build extends Command 20 | { 21 | 22 | /** 23 | * {@inheritdoc} 24 | */ 25 | protected function configure() 26 | { 27 | $this->setName('build') 28 | ->setDefinition([ 29 | new Option('config', null, Option::VALUE_OPTIONAL, "build.php path"), 30 | new Option('module', null, Option::VALUE_OPTIONAL, "module name"), 31 | ]) 32 | ->setDescription('Build Application Dirs'); 33 | } 34 | 35 | protected function execute(Input $input, Output $output) 36 | { 37 | if ($input->hasOption('module')) { 38 | \think\Build::module($input->getOption('module')); 39 | $output->writeln("Successed"); 40 | return; 41 | } 42 | 43 | if ($input->hasOption('config')) { 44 | $build = include $input->getOption('config'); 45 | } else { 46 | $build = include APP_PATH . 'build.php'; 47 | } 48 | if (empty($build)) { 49 | $output->writeln("Build Config Is Empty"); 50 | return; 51 | } 52 | \think\Build::run($build); 53 | $output->writeln("Successed"); 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/Clear.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | namespace think\console\command; 12 | 13 | use think\console\Command; 14 | use think\console\Input; 15 | use think\console\input\Option; 16 | use think\console\Output; 17 | 18 | class Clear extends Command 19 | { 20 | protected function configure() 21 | { 22 | // 指令配置 23 | $this 24 | ->setName('clear') 25 | ->addOption('path', 'd', Option::VALUE_OPTIONAL, 'path to clear', null) 26 | ->setDescription('Clear runtime file'); 27 | } 28 | 29 | protected function execute(Input $input, Output $output) 30 | { 31 | $path = $input->getOption('path') ?: RUNTIME_PATH; 32 | 33 | if (is_dir($path)) { 34 | $this->clearPath($path); 35 | } 36 | 37 | $output->writeln("Clear Successed"); 38 | } 39 | 40 | protected function clearPath($path) 41 | { 42 | $path = realpath($path) . DS; 43 | $files = scandir($path); 44 | if ($files) { 45 | foreach ($files as $file) { 46 | if ('.' != $file && '..' != $file && is_dir($path . $file)) { 47 | $this->clearPath($path . $file); 48 | } elseif ('.gitignore' != $file && is_file($path . $file)) { 49 | unlink($path . $file); 50 | } 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/Help.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\command; 13 | 14 | use think\console\Command; 15 | use think\console\Input; 16 | use think\console\input\Argument as InputArgument; 17 | use think\console\input\Option as InputOption; 18 | use think\console\Output; 19 | 20 | class Help extends Command 21 | { 22 | 23 | private $command; 24 | 25 | /** 26 | * {@inheritdoc} 27 | */ 28 | protected function configure() 29 | { 30 | $this->ignoreValidationErrors(); 31 | 32 | $this->setName('help')->setDefinition([ 33 | new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'), 34 | new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command help'), 35 | ])->setDescription('Displays help for a command')->setHelp(<<%command.name% command displays help for a given command: 37 | 38 | php %command.full_name% list 39 | 40 | To display the list of available commands, please use the list command. 41 | EOF 42 | ); 43 | } 44 | 45 | /** 46 | * Sets the command. 47 | * @param Command $command The command to set 48 | */ 49 | public function setCommand(Command $command) 50 | { 51 | $this->command = $command; 52 | } 53 | 54 | /** 55 | * {@inheritdoc} 56 | */ 57 | protected function execute(Input $input, Output $output) 58 | { 59 | if (null === $this->command) { 60 | $this->command = $this->getConsole()->find($input->getArgument('command_name')); 61 | } 62 | 63 | $output->describe($this->command, [ 64 | 'raw_text' => $input->getOption('raw'), 65 | ]); 66 | 67 | $this->command = null; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/Lists.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\command; 13 | 14 | use think\console\Command; 15 | use think\console\Input; 16 | use think\console\Output; 17 | use think\console\input\Argument as InputArgument; 18 | use think\console\input\Option as InputOption; 19 | use think\console\input\Definition as InputDefinition; 20 | 21 | class Lists extends Command 22 | { 23 | 24 | /** 25 | * {@inheritdoc} 26 | */ 27 | protected function configure() 28 | { 29 | $this->setName('list')->setDefinition($this->createDefinition())->setDescription('Lists commands')->setHelp(<<%command.name% command lists all commands: 31 | 32 | php %command.full_name% 33 | 34 | You can also display the commands for a specific namespace: 35 | 36 | php %command.full_name% test 37 | 38 | It's also possible to get raw list of commands (useful for embedding command runner): 39 | 40 | php %command.full_name% --raw 41 | EOF 42 | ); 43 | } 44 | 45 | /** 46 | * {@inheritdoc} 47 | */ 48 | public function getNativeDefinition() 49 | { 50 | return $this->createDefinition(); 51 | } 52 | 53 | /** 54 | * {@inheritdoc} 55 | */ 56 | protected function execute(Input $input, Output $output) 57 | { 58 | $output->describe($this->getConsole(), [ 59 | 'raw_text' => $input->getOption('raw'), 60 | 'namespace' => $input->getArgument('namespace'), 61 | ]); 62 | } 63 | 64 | /** 65 | * {@inheritdoc} 66 | */ 67 | private function createDefinition() 68 | { 69 | return new InputDefinition([ 70 | new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'), 71 | new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list') 72 | ]); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/Make.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\command; 13 | 14 | use think\App; 15 | use think\Config; 16 | use think\console\Command; 17 | use think\console\Input; 18 | use think\console\input\Argument; 19 | use think\console\Output; 20 | 21 | abstract class Make extends Command 22 | { 23 | 24 | protected $type; 25 | 26 | abstract protected function getStub(); 27 | 28 | protected function configure() 29 | { 30 | $this->addArgument('name', Argument::REQUIRED, "The name of the class"); 31 | } 32 | 33 | protected function execute(Input $input, Output $output) 34 | { 35 | 36 | $name = trim($input->getArgument('name')); 37 | 38 | $classname = $this->getClassName($name); 39 | 40 | $pathname = $this->getPathName($classname); 41 | 42 | if (is_file($pathname)) { 43 | $output->writeln('' . $this->type . ' already exists!'); 44 | return false; 45 | } 46 | 47 | if (!is_dir(dirname($pathname))) { 48 | mkdir(strtolower(dirname($pathname)), 0755, true); 49 | } 50 | 51 | file_put_contents($pathname, $this->buildClass($classname)); 52 | 53 | $output->writeln('' . $this->type . ' created successfully.'); 54 | 55 | } 56 | 57 | protected function buildClass($name) 58 | { 59 | $stub = file_get_contents($this->getStub()); 60 | 61 | $namespace = trim(implode('\\', array_slice(explode('\\', $name), 0, -1)), '\\'); 62 | 63 | $class = str_replace($namespace . '\\', '', $name); 64 | 65 | return str_replace(['{%className%}', '{%namespace%}', '{%app_namespace%}'], [ 66 | $class, 67 | $namespace, 68 | App::$namespace, 69 | ], $stub); 70 | 71 | } 72 | 73 | protected function getPathName($name) 74 | { 75 | $name = str_replace(App::$namespace . '\\', '', $name); 76 | 77 | return APP_PATH . str_replace('\\', '/', $name) . '.php'; 78 | } 79 | 80 | protected function getClassName($name) 81 | { 82 | $appNamespace = App::$namespace; 83 | 84 | if (strpos($name, $appNamespace . '\\') === 0) { 85 | return $name; 86 | } 87 | 88 | if (Config::get('app_multi_module')) { 89 | if (strpos($name, '/')) { 90 | list($module, $name) = explode('/', $name, 2); 91 | } else { 92 | $module = 'common'; 93 | } 94 | } else { 95 | $module = null; 96 | } 97 | 98 | if (strpos($name, '/') !== false) { 99 | $name = str_replace('/', '\\', $name); 100 | } 101 | 102 | return $this->getNamespace($appNamespace, $module) . '\\' . $name; 103 | } 104 | 105 | protected function getNamespace($appNamespace, $module) 106 | { 107 | return $module ? ($appNamespace . '\\' . $module) : $appNamespace; 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/make/Controller.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\command\make; 13 | 14 | use think\Config; 15 | use think\console\command\Make; 16 | use think\console\input\Option; 17 | 18 | class Controller extends Make 19 | { 20 | 21 | protected $type = "Controller"; 22 | 23 | protected function configure() 24 | { 25 | parent::configure(); 26 | $this->setName('make:controller') 27 | ->addOption('plain', null, Option::VALUE_NONE, 'Generate an empty controller class.') 28 | ->setDescription('Create a new resource controller class'); 29 | } 30 | 31 | protected function getStub() 32 | { 33 | if ($this->input->getOption('plain')) { 34 | return __DIR__ . '/stubs/controller.plain.stub'; 35 | } 36 | 37 | return __DIR__ . '/stubs/controller.stub'; 38 | } 39 | 40 | protected function getClassName($name) 41 | { 42 | return parent::getClassName($name) . (Config::get('controller_suffix') ? ucfirst(Config::get('url_controller_layer')) : ''); 43 | } 44 | 45 | protected function getNamespace($appNamespace, $module) 46 | { 47 | return parent::getNamespace($appNamespace, $module) . '\controller'; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/make/Model.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\command\make; 13 | 14 | use think\console\command\Make; 15 | 16 | class Model extends Make 17 | { 18 | protected $type = "Model"; 19 | 20 | protected function configure() 21 | { 22 | parent::configure(); 23 | $this->setName('make:model') 24 | ->setDescription('Create a new model class'); 25 | } 26 | 27 | protected function getStub() 28 | { 29 | return __DIR__ . '/stubs/model.stub'; 30 | } 31 | 32 | protected function getNamespace($appNamespace, $module) 33 | { 34 | return parent::getNamespace($appNamespace, $module) . '\model'; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/make/stubs/controller.plain.stub: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | namespace think\console\command\optimize; 12 | 13 | use think\Config as ThinkConfig; 14 | use think\console\Command; 15 | use think\console\Input; 16 | use think\console\input\Argument; 17 | use think\console\Output; 18 | 19 | class Config extends Command 20 | { 21 | /** @var Output */ 22 | protected $output; 23 | 24 | protected function configure() 25 | { 26 | $this->setName('optimize:config') 27 | ->addArgument('module', Argument::OPTIONAL, 'Build module config cache .') 28 | ->setDescription('Build config and common file cache.'); 29 | } 30 | 31 | protected function execute(Input $input, Output $output) 32 | { 33 | if ($input->hasArgument('module')) { 34 | $module = $input->getArgument('module') . DS; 35 | } else { 36 | $module = ''; 37 | } 38 | 39 | $content = 'buildCacheContent($module); 40 | 41 | if (!is_dir(RUNTIME_PATH . $module)) { 42 | @mkdir(RUNTIME_PATH . $module, 0755, true); 43 | } 44 | 45 | file_put_contents(RUNTIME_PATH . $module . 'init' . EXT, $content); 46 | 47 | $output->writeln('Succeed!'); 48 | } 49 | 50 | protected function buildCacheContent($module) 51 | { 52 | $content = ''; 53 | $path = realpath(APP_PATH . $module) . DS; 54 | 55 | if ($module) { 56 | // 加载模块配置 57 | $config = ThinkConfig::load(CONF_PATH . $module . 'config' . CONF_EXT); 58 | 59 | // 读取数据库配置文件 60 | $filename = CONF_PATH . $module . 'database' . CONF_EXT; 61 | ThinkConfig::load($filename, 'database'); 62 | 63 | // 加载应用状态配置 64 | if ($config['app_status']) { 65 | $config = ThinkConfig::load(CONF_PATH . $module . $config['app_status'] . CONF_EXT); 66 | } 67 | // 读取扩展配置文件 68 | if (is_dir(CONF_PATH . $module . 'extra')) { 69 | $dir = CONF_PATH . $module . 'extra'; 70 | $files = scandir($dir); 71 | foreach ($files as $file) { 72 | if (strpos($file, CONF_EXT)) { 73 | $filename = $dir . DS . $file; 74 | ThinkConfig::load($filename, pathinfo($file, PATHINFO_FILENAME)); 75 | } 76 | } 77 | } 78 | } 79 | 80 | // 加载行为扩展文件 81 | if (is_file(CONF_PATH . $module . 'tags' . EXT)) { 82 | $content .= '\think\Hook::import(' . (var_export(include CONF_PATH . $module . 'tags' . EXT, true)) . ');' . PHP_EOL; 83 | } 84 | 85 | // 加载公共文件 86 | if (is_file($path . 'common' . EXT)) { 87 | $content .= substr(php_strip_whitespace($path . 'common' . EXT), 5) . PHP_EOL; 88 | } 89 | 90 | $content .= '\think\Config::set(' . var_export(ThinkConfig::get(), true) . ');'; 91 | return $content; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/optimize/Route.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | namespace think\console\command\optimize; 12 | 13 | use think\console\Command; 14 | use think\console\Input; 15 | use think\console\Output; 16 | 17 | class Route extends Command 18 | { 19 | /** @var Output */ 20 | protected $output; 21 | 22 | protected function configure() 23 | { 24 | $this->setName('optimize:route') 25 | ->setDescription('Build route cache.'); 26 | } 27 | 28 | protected function execute(Input $input, Output $output) 29 | { 30 | file_put_contents(RUNTIME_PATH . 'route.php', $this->buildRouteCache()); 31 | $output->writeln('Succeed!'); 32 | } 33 | 34 | protected function buildRouteCache() 35 | { 36 | $files = \think\Config::get('route_config_file'); 37 | foreach ($files as $file) { 38 | if (is_file(CONF_PATH . $file . CONF_EXT)) { 39 | $config = include CONF_PATH . $file . CONF_EXT; 40 | if (is_array($config)) { 41 | \think\Route::import($config); 42 | } 43 | } 44 | } 45 | $rules = \think\Route::rules(true); 46 | array_walk_recursive($rules, [$this, 'buildClosure']); 47 | $content = 'getStartLine(); 58 | $endLine = $reflection->getEndLine(); 59 | $file = $reflection->getFileName(); 60 | $item = file($file); 61 | $content = ''; 62 | for ($i = $startLine - 1; $i <= $endLine - 1; $i++) { 63 | $content .= $item[$i]; 64 | } 65 | $start = strpos($content, 'function'); 66 | $end = strrpos($content, '}'); 67 | $value = '[__start__' . substr($content, $start, $end - $start + 1) . '__end__]'; 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/input/Argument.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\input; 13 | 14 | class Argument 15 | { 16 | 17 | const REQUIRED = 1; 18 | const OPTIONAL = 2; 19 | const IS_ARRAY = 4; 20 | 21 | private $name; 22 | private $mode; 23 | private $default; 24 | private $description; 25 | 26 | /** 27 | * 构造方法 28 | * @param string $name 参数名 29 | * @param int $mode 参数类型: self::REQUIRED 或者 self::OPTIONAL 30 | * @param string $description 描述 31 | * @param mixed $default 默认值 (仅 self::OPTIONAL 类型有效) 32 | * @throws \InvalidArgumentException 33 | */ 34 | public function __construct($name, $mode = null, $description = '', $default = null) 35 | { 36 | if (null === $mode) { 37 | $mode = self::OPTIONAL; 38 | } elseif (!is_int($mode) || $mode > 7 || $mode < 1) { 39 | throw new \InvalidArgumentException(sprintf('Argument mode "%s" is not valid.', $mode)); 40 | } 41 | 42 | $this->name = $name; 43 | $this->mode = $mode; 44 | $this->description = $description; 45 | 46 | $this->setDefault($default); 47 | } 48 | 49 | /** 50 | * 获取参数名 51 | * @return string 52 | */ 53 | public function getName() 54 | { 55 | return $this->name; 56 | } 57 | 58 | /** 59 | * 是否必须 60 | * @return bool 61 | */ 62 | public function isRequired() 63 | { 64 | return self::REQUIRED === (self::REQUIRED & $this->mode); 65 | } 66 | 67 | /** 68 | * 该参数是否接受数组 69 | * @return bool 70 | */ 71 | public function isArray() 72 | { 73 | return self::IS_ARRAY === (self::IS_ARRAY & $this->mode); 74 | } 75 | 76 | /** 77 | * 设置默认值 78 | * @param mixed $default 默认值 79 | * @throws \LogicException 80 | */ 81 | public function setDefault($default = null) 82 | { 83 | if (self::REQUIRED === $this->mode && null !== $default) { 84 | throw new \LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.'); 85 | } 86 | 87 | if ($this->isArray()) { 88 | if (null === $default) { 89 | $default = []; 90 | } elseif (!is_array($default)) { 91 | throw new \LogicException('A default value for an array argument must be an array.'); 92 | } 93 | } 94 | 95 | $this->default = $default; 96 | } 97 | 98 | /** 99 | * 获取默认值 100 | * @return mixed 101 | */ 102 | public function getDefault() 103 | { 104 | return $this->default; 105 | } 106 | 107 | /** 108 | * 获取描述 109 | * @return string 110 | */ 111 | public function getDescription() 112 | { 113 | return $this->description; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/output/descriptor/Console.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\output\descriptor; 13 | 14 | use think\Console as ThinkConsole; 15 | use think\console\Command; 16 | 17 | class Console 18 | { 19 | 20 | const GLOBAL_NAMESPACE = '_global'; 21 | 22 | /** 23 | * @var ThinkConsole 24 | */ 25 | private $console; 26 | 27 | /** 28 | * @var null|string 29 | */ 30 | private $namespace; 31 | 32 | /** 33 | * @var array 34 | */ 35 | private $namespaces; 36 | 37 | /** 38 | * @var Command[] 39 | */ 40 | private $commands; 41 | 42 | /** 43 | * @var Command[] 44 | */ 45 | private $aliases; 46 | 47 | /** 48 | * 构造方法 49 | * @param ThinkConsole $console 50 | * @param string|null $namespace 51 | */ 52 | public function __construct(ThinkConsole $console, $namespace = null) 53 | { 54 | $this->console = $console; 55 | $this->namespace = $namespace; 56 | } 57 | 58 | /** 59 | * @return array 60 | */ 61 | public function getNamespaces() 62 | { 63 | if (null === $this->namespaces) { 64 | $this->inspectConsole(); 65 | } 66 | 67 | return $this->namespaces; 68 | } 69 | 70 | /** 71 | * @return Command[] 72 | */ 73 | public function getCommands() 74 | { 75 | if (null === $this->commands) { 76 | $this->inspectConsole(); 77 | } 78 | 79 | return $this->commands; 80 | } 81 | 82 | /** 83 | * @param string $name 84 | * @return Command 85 | * @throws \InvalidArgumentException 86 | */ 87 | public function getCommand($name) 88 | { 89 | if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) { 90 | throw new \InvalidArgumentException(sprintf('Command %s does not exist.', $name)); 91 | } 92 | 93 | return isset($this->commands[$name]) ? $this->commands[$name] : $this->aliases[$name]; 94 | } 95 | 96 | private function inspectConsole() 97 | { 98 | $this->commands = []; 99 | $this->namespaces = []; 100 | 101 | $all = $this->console->all($this->namespace ? $this->console->findNamespace($this->namespace) : null); 102 | foreach ($this->sortCommands($all) as $namespace => $commands) { 103 | $names = []; 104 | 105 | /** @var Command $command */ 106 | foreach ($commands as $name => $command) { 107 | if (!$command->getName()) { 108 | continue; 109 | } 110 | 111 | if ($command->getName() === $name) { 112 | $this->commands[$name] = $command; 113 | } else { 114 | $this->aliases[$name] = $command; 115 | } 116 | 117 | $names[] = $name; 118 | } 119 | 120 | $this->namespaces[$namespace] = ['id' => $namespace, 'commands' => $names]; 121 | } 122 | } 123 | 124 | /** 125 | * @param array $commands 126 | * @return array 127 | */ 128 | private function sortCommands(array $commands) 129 | { 130 | $namespacedCommands = []; 131 | foreach ($commands as $name => $command) { 132 | $key = $this->console->extractNamespace($name, 1); 133 | if (!$key) { 134 | $key = self::GLOBAL_NAMESPACE; 135 | } 136 | 137 | $namespacedCommands[$key][$name] = $command; 138 | } 139 | ksort($namespacedCommands); 140 | 141 | foreach ($namespacedCommands as &$commandsSet) { 142 | ksort($commandsSet); 143 | } 144 | // unset reference to keep scope clear 145 | unset($commandsSet); 146 | 147 | return $namespacedCommands; 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/output/driver/Buffer.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\output\driver; 13 | 14 | use think\console\Output; 15 | 16 | class Buffer 17 | { 18 | /** 19 | * @var string 20 | */ 21 | private $buffer = ''; 22 | 23 | public function __construct(Output $output) 24 | { 25 | // do nothing 26 | } 27 | 28 | public function fetch() 29 | { 30 | $content = $this->buffer; 31 | $this->buffer = ''; 32 | return $content; 33 | } 34 | 35 | public function write($messages, $newline = false, $options = Output::OUTPUT_NORMAL) 36 | { 37 | $messages = (array) $messages; 38 | 39 | foreach ($messages as $message) { 40 | $this->buffer .= $message; 41 | } 42 | if ($newline) { 43 | $this->buffer .= "\n"; 44 | } 45 | } 46 | 47 | public function renderException(\Exception $e) 48 | { 49 | // do nothing 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/output/driver/Nothing.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\output\driver; 13 | 14 | use think\console\Output; 15 | 16 | class Nothing 17 | { 18 | 19 | public function __construct(Output $output) 20 | { 21 | // do nothing 22 | } 23 | 24 | public function write($messages, $newline = false, $options = Output::OUTPUT_NORMAL) 25 | { 26 | // do nothing 27 | } 28 | 29 | public function renderException(\Exception $e) 30 | { 31 | // do nothing 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/output/formatter/Stack.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\output\formatter; 13 | 14 | class Stack 15 | { 16 | 17 | /** 18 | * @var Style[] 19 | */ 20 | private $styles; 21 | 22 | /** 23 | * @var Style 24 | */ 25 | private $emptyStyle; 26 | 27 | /** 28 | * 构造方法 29 | * @param Style|null $emptyStyle 30 | */ 31 | public function __construct(Style $emptyStyle = null) 32 | { 33 | $this->emptyStyle = $emptyStyle ?: new Style(); 34 | $this->reset(); 35 | } 36 | 37 | /** 38 | * 重置堆栈 39 | */ 40 | public function reset() 41 | { 42 | $this->styles = []; 43 | } 44 | 45 | /** 46 | * 推一个样式进入堆栈 47 | * @param Style $style 48 | */ 49 | public function push(Style $style) 50 | { 51 | $this->styles[] = $style; 52 | } 53 | 54 | /** 55 | * 从堆栈中弹出一个样式 56 | * @param Style|null $style 57 | * @return Style 58 | * @throws \InvalidArgumentException 59 | */ 60 | public function pop(Style $style = null) 61 | { 62 | if (empty($this->styles)) { 63 | return $this->emptyStyle; 64 | } 65 | 66 | if (null === $style) { 67 | return array_pop($this->styles); 68 | } 69 | 70 | /** 71 | * @var int $index 72 | * @var Style $stackedStyle 73 | */ 74 | foreach (array_reverse($this->styles, true) as $index => $stackedStyle) { 75 | if ($style->apply('') === $stackedStyle->apply('')) { 76 | $this->styles = array_slice($this->styles, 0, $index); 77 | 78 | return $stackedStyle; 79 | } 80 | } 81 | 82 | throw new \InvalidArgumentException('Incorrectly nested style tag found.'); 83 | } 84 | 85 | /** 86 | * 计算堆栈的当前样式。 87 | * @return Style 88 | */ 89 | public function getCurrent() 90 | { 91 | if (empty($this->styles)) { 92 | return $this->emptyStyle; 93 | } 94 | 95 | return $this->styles[count($this->styles) - 1]; 96 | } 97 | 98 | /** 99 | * @param Style $emptyStyle 100 | * @return Stack 101 | */ 102 | public function setEmptyStyle(Style $emptyStyle) 103 | { 104 | $this->emptyStyle = $emptyStyle; 105 | 106 | return $this; 107 | } 108 | 109 | /** 110 | * @return Style 111 | */ 112 | public function getEmptyStyle() 113 | { 114 | return $this->emptyStyle; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/output/question/Confirmation.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\output\question; 13 | 14 | use think\console\output\Question; 15 | 16 | class Confirmation extends Question 17 | { 18 | 19 | private $trueAnswerRegex; 20 | 21 | /** 22 | * 构造方法 23 | * @param string $question 问题 24 | * @param bool $default 默认答案 25 | * @param string $trueAnswerRegex 验证正则 26 | */ 27 | public function __construct($question, $default = true, $trueAnswerRegex = '/^y/i') 28 | { 29 | parent::__construct($question, (bool) $default); 30 | 31 | $this->trueAnswerRegex = $trueAnswerRegex; 32 | $this->setNormalizer($this->getDefaultNormalizer()); 33 | } 34 | 35 | /** 36 | * 获取默认的答案回调 37 | * @return callable 38 | */ 39 | private function getDefaultNormalizer() 40 | { 41 | $default = $this->getDefault(); 42 | $regex = $this->trueAnswerRegex; 43 | 44 | return function ($answer) use ($default, $regex) { 45 | if (is_bool($answer)) { 46 | return $answer; 47 | } 48 | 49 | $answerIsTrue = (bool) preg_match($regex, $answer); 50 | if (false === $default) { 51 | return $answer && $answerIsTrue; 52 | } 53 | 54 | return !$answer || $answerIsTrue; 55 | }; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /thinkphp/library/think/controller/Rest.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\controller; 13 | 14 | use think\App; 15 | use think\Request; 16 | use think\Response; 17 | 18 | abstract class Rest 19 | { 20 | 21 | protected $method; // 当前请求类型 22 | protected $type; // 当前资源类型 23 | // 输出类型 24 | protected $restMethodList = 'get|post|put|delete'; 25 | protected $restDefaultMethod = 'get'; 26 | protected $restTypeList = 'html|xml|json|rss'; 27 | protected $restDefaultType = 'html'; 28 | protected $restOutputType = [ // REST允许输出的资源类型列表 29 | 'xml' => 'application/xml', 30 | 'json' => 'application/json', 31 | 'html' => 'text/html', 32 | ]; 33 | 34 | /** 35 | * 构造函数 取得模板对象实例 36 | * @access public 37 | */ 38 | public function __construct() 39 | { 40 | // 资源类型检测 41 | $request = Request::instance(); 42 | $ext = $request->ext(); 43 | if ('' == $ext) { 44 | // 自动检测资源类型 45 | $this->type = $request->type(); 46 | } elseif (!preg_match('/\(' . $this->restTypeList . '\)$/i', $ext)) { 47 | // 资源类型非法 则用默认资源类型访问 48 | $this->type = $this->restDefaultType; 49 | } else { 50 | $this->type = $ext; 51 | } 52 | // 请求方式检测 53 | $method = strtolower($request->method()); 54 | if (false === stripos($this->restMethodList, $method)) { 55 | // 请求方式非法 则用默认请求方法 56 | $method = $this->restDefaultMethod; 57 | } 58 | $this->method = $method; 59 | } 60 | 61 | /** 62 | * REST 调用 63 | * @access public 64 | * @param string $method 方法名 65 | * @return mixed 66 | * @throws \Exception 67 | */ 68 | public function _empty($method) 69 | { 70 | if (method_exists($this, $method . '_' . $this->method . '_' . $this->type)) { 71 | // RESTFul方法支持 72 | $fun = $method . '_' . $this->method . '_' . $this->type; 73 | } elseif ($this->method == $this->restDefaultMethod && method_exists($this, $method . '_' . $this->type)) { 74 | $fun = $method . '_' . $this->type; 75 | } elseif ($this->type == $this->restDefaultType && method_exists($this, $method . '_' . $this->method)) { 76 | $fun = $method . '_' . $this->method; 77 | } 78 | if (isset($fun)) { 79 | return App::invokeMethod([$this, $fun]); 80 | } else { 81 | // 抛出异常 82 | throw new \Exception('error action :' . $method); 83 | } 84 | } 85 | 86 | /** 87 | * 输出返回数据 88 | * @access protected 89 | * @param mixed $data 要返回的数据 90 | * @param String $type 返回类型 JSON XML 91 | * @param integer $code HTTP状态码 92 | * @return Response 93 | */ 94 | protected function response($data, $type = 'json', $code = 200) 95 | { 96 | return Response::create($data, $type)->code($code); 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /thinkphp/library/think/controller/Yar.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\controller; 13 | 14 | /** 15 | * ThinkPHP Yar控制器类 16 | */ 17 | abstract class Yar 18 | { 19 | 20 | /** 21 | * 构造函数 22 | * @access public 23 | */ 24 | public function __construct() 25 | { 26 | //控制器初始化 27 | if (method_exists($this, '_initialize')) { 28 | $this->_initialize(); 29 | } 30 | 31 | //判断扩展是否存在 32 | if (!extension_loaded('yar')) { 33 | throw new \Exception('not support yar'); 34 | } 35 | 36 | //实例化Yar_Server 37 | $server = new \Yar_Server($this); 38 | // 启动server 39 | $server->handle(); 40 | } 41 | 42 | /** 43 | * 魔术方法 有不存在的操作的时候执行 44 | * @access public 45 | * @param string $method 方法名 46 | * @param array $args 参数 47 | * @return mixed 48 | */ 49 | public function __call($method, $args) 50 | {} 51 | } 52 | -------------------------------------------------------------------------------- /thinkphp/library/think/db/builder/Mysql.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\db\builder; 13 | 14 | use think\db\Builder; 15 | 16 | /** 17 | * mysql数据库驱动 18 | */ 19 | class Mysql extends Builder 20 | { 21 | protected $updateSql = 'UPDATE %TABLE% %JOIN% SET %SET% %WHERE% %ORDER%%LIMIT% %LOCK%%COMMENT%'; 22 | 23 | /** 24 | * 字段和表名处理 25 | * @access protected 26 | * @param string $key 27 | * @param array $options 28 | * @return string 29 | */ 30 | protected function parseKey($key, $options = []) 31 | { 32 | $key = trim($key); 33 | if (strpos($key, '$.') && false === strpos($key, '(')) { 34 | // JSON字段支持 35 | list($field, $name) = explode('$.', $key); 36 | $key = 'json_extract(' . $field . ', \'$.' . $name . '\')'; 37 | } elseif (strpos($key, '.') && !preg_match('/[,\'\"\(\)`\s]/', $key)) { 38 | list($table, $key) = explode('.', $key, 2); 39 | if ('__TABLE__' == $table) { 40 | $table = $this->query->getTable(); 41 | } 42 | if (isset($options['alias'][$table])) { 43 | $table = $options['alias'][$table]; 44 | } 45 | } 46 | if (!preg_match('/[,\'\"\*\(\)`.\s]/', $key)) { 47 | $key = '`' . $key . '`'; 48 | } 49 | if (isset($table)) { 50 | if (strpos($table, '.')) { 51 | $table = str_replace('.', '`.`', $table); 52 | } 53 | $key = '`' . $table . '`.' . $key; 54 | } 55 | return $key; 56 | } 57 | 58 | /** 59 | * 随机排序 60 | * @access protected 61 | * @return string 62 | */ 63 | protected function parseRand() 64 | { 65 | return 'rand()'; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /thinkphp/library/think/db/builder/Pgsql.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\db\builder; 13 | 14 | use think\db\Builder; 15 | 16 | /** 17 | * Pgsql数据库驱动 18 | */ 19 | class Pgsql extends Builder 20 | { 21 | protected $insertSql = 'INSERT INTO %TABLE% (%FIELD%) VALUES (%DATA%) %COMMENT%'; 22 | protected $insertAllSql = 'INSERT INTO %TABLE% (%FIELD%) %DATA% %COMMENT%'; 23 | 24 | /** 25 | * limit分析 26 | * @access protected 27 | * @param mixed $limit 28 | * @return string 29 | */ 30 | public function parseLimit($limit) 31 | { 32 | $limitStr = ''; 33 | if (!empty($limit)) { 34 | $limit = explode(',', $limit); 35 | if (count($limit) > 1) { 36 | $limitStr .= ' LIMIT ' . $limit[1] . ' OFFSET ' . $limit[0] . ' '; 37 | } else { 38 | $limitStr .= ' LIMIT ' . $limit[0] . ' '; 39 | } 40 | } 41 | return $limitStr; 42 | } 43 | 44 | /** 45 | * 字段和表名处理 46 | * @access protected 47 | * @param string $key 48 | * @param array $options 49 | * @return string 50 | */ 51 | protected function parseKey($key, $options = []) 52 | { 53 | $key = trim($key); 54 | if (strpos($key, '$.') && false === strpos($key, '(')) { 55 | // JSON字段支持 56 | list($field, $name) = explode('$.', $key); 57 | $key = $field . '->>\'' . $name . '\''; 58 | } elseif (strpos($key, '.')) { 59 | list($table, $key) = explode('.', $key, 2); 60 | if ('__TABLE__' == $table) { 61 | $table = $this->query->getTable(); 62 | } 63 | if (isset($options['alias'][$table])) { 64 | $table = $options['alias'][$table]; 65 | } 66 | } 67 | if (isset($table)) { 68 | $key = $table . '.' . $key; 69 | } 70 | return $key; 71 | } 72 | 73 | /** 74 | * 随机排序 75 | * @access protected 76 | * @return string 77 | */ 78 | protected function parseRand() 79 | { 80 | return 'RANDOM()'; 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /thinkphp/library/think/db/builder/Sqlite.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\db\builder; 13 | 14 | use think\db\Builder; 15 | 16 | /** 17 | * Sqlite数据库驱动 18 | */ 19 | class Sqlite extends Builder 20 | { 21 | 22 | /** 23 | * limit 24 | * @access public 25 | * @param string $limit 26 | * @return string 27 | */ 28 | public function parseLimit($limit) 29 | { 30 | $limitStr = ''; 31 | if (!empty($limit)) { 32 | $limit = explode(',', $limit); 33 | if (count($limit) > 1) { 34 | $limitStr .= ' LIMIT ' . $limit[1] . ' OFFSET ' . $limit[0] . ' '; 35 | } else { 36 | $limitStr .= ' LIMIT ' . $limit[0] . ' '; 37 | } 38 | } 39 | return $limitStr; 40 | } 41 | 42 | /** 43 | * 随机排序 44 | * @access protected 45 | * @return string 46 | */ 47 | protected function parseRand() 48 | { 49 | return 'RANDOM()'; 50 | } 51 | 52 | /** 53 | * 字段和表名处理 54 | * @access protected 55 | * @param string $key 56 | * @param array $options 57 | * @return string 58 | */ 59 | protected function parseKey($key, $options = []) 60 | { 61 | $key = trim($key); 62 | if (strpos($key, '.')) { 63 | list($table, $key) = explode('.', $key, 2); 64 | if ('__TABLE__' == $table) { 65 | $table = $this->query->getTable(); 66 | } 67 | if (isset($options['alias'][$table])) { 68 | $table = $options['alias'][$table]; 69 | } 70 | } 71 | if (isset($table)) { 72 | $key = $table . '.' . $key; 73 | } 74 | return $key; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /thinkphp/library/think/db/builder/Sqlsrv.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\db\builder; 13 | 14 | use think\db\Builder; 15 | 16 | /** 17 | * Sqlsrv数据库驱动 18 | */ 19 | class Sqlsrv extends Builder 20 | { 21 | protected $selectSql = 'SELECT T1.* FROM (SELECT thinkphp.*, ROW_NUMBER() OVER (%ORDER%) AS ROW_NUMBER FROM (SELECT %DISTINCT% %FIELD% FROM %TABLE%%JOIN%%WHERE%%GROUP%%HAVING%) AS thinkphp) AS T1 %LIMIT%%COMMENT%'; 22 | protected $selectInsertSql = 'SELECT %DISTINCT% %FIELD% FROM %TABLE%%JOIN%%WHERE%%GROUP%%HAVING%'; 23 | protected $updateSql = 'UPDATE %TABLE% SET %SET% FROM %TABLE% %JOIN% %WHERE% %LIMIT% %LOCK%%COMMENT%'; 24 | protected $deleteSql = 'DELETE FROM %TABLE% %USING% FROM %TABLE% %JOIN% %WHERE% %LIMIT% %LOCK%%COMMENT%'; 25 | protected $insertSql = 'INSERT INTO %TABLE% (%FIELD%) VALUES (%DATA%) %COMMENT%'; 26 | protected $insertAllSql = 'INSERT INTO %TABLE% (%FIELD%) %DATA% %COMMENT%'; 27 | 28 | /** 29 | * order分析 30 | * @access protected 31 | * @param mixed $order 32 | * @param array $options 33 | * @return string 34 | */ 35 | protected function parseOrder($order, $options = []) 36 | { 37 | if (is_array($order)) { 38 | $array = []; 39 | foreach ($order as $key => $val) { 40 | if (is_numeric($key)) { 41 | if (false === strpos($val, '(')) { 42 | $array[] = $this->parseKey($val, $options); 43 | } elseif ('[rand]' == $val) { 44 | $array[] = $this->parseRand(); 45 | } else { 46 | $array[] = $val; 47 | } 48 | } else { 49 | $sort = in_array(strtolower(trim($val)), ['asc', 'desc']) ? ' ' . $val : ''; 50 | $array[] = $this->parseKey($key, $options) . ' ' . $sort; 51 | } 52 | } 53 | $order = implode(',', $array); 54 | } 55 | return !empty($order) ? ' ORDER BY ' . $order : ' ORDER BY rand()'; 56 | } 57 | 58 | /** 59 | * 随机排序 60 | * @access protected 61 | * @return string 62 | */ 63 | protected function parseRand() 64 | { 65 | return 'rand()'; 66 | } 67 | 68 | /** 69 | * 字段和表名处理 70 | * @access protected 71 | * @param string $key 72 | * @param array $options 73 | * @return string 74 | */ 75 | protected function parseKey($key, $options = []) 76 | { 77 | $key = trim($key); 78 | if (strpos($key, '.') && !preg_match('/[,\'\"\(\)\[\s]/', $key)) { 79 | list($table, $key) = explode('.', $key, 2); 80 | if ('__TABLE__' == $table) { 81 | $table = $this->query->getTable(); 82 | } 83 | if (isset($options['alias'][$table])) { 84 | $table = $options['alias'][$table]; 85 | } 86 | } 87 | if (!is_numeric($key) && !preg_match('/[,\'\"\*\(\)\[.\s]/', $key)) { 88 | $key = '[' . $key . ']'; 89 | } 90 | if (isset($table)) { 91 | $key = '[' . $table . '].' . $key; 92 | } 93 | return $key; 94 | } 95 | 96 | /** 97 | * limit 98 | * @access protected 99 | * @param mixed $limit 100 | * @return string 101 | */ 102 | protected function parseLimit($limit) 103 | { 104 | if (empty($limit)) { 105 | return ''; 106 | } 107 | 108 | $limit = explode(',', $limit); 109 | if (count($limit) > 1) { 110 | $limitStr = '(T1.ROW_NUMBER BETWEEN ' . $limit[0] . ' + 1 AND ' . $limit[0] . ' + ' . $limit[1] . ')'; 111 | } else { 112 | $limitStr = '(T1.ROW_NUMBER BETWEEN 1 AND ' . $limit[0] . ")"; 113 | } 114 | return 'WHERE ' . $limitStr; 115 | } 116 | 117 | public function selectInsert($fields, $table, $options) 118 | { 119 | $this->selectSql = $this->selectInsertSql; 120 | return parent::selectInsert($fields, $table, $options); 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /thinkphp/library/think/db/connector/Mysql.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\db\connector; 13 | 14 | use PDO; 15 | use think\db\Connection; 16 | use think\Log; 17 | 18 | /** 19 | * mysql数据库驱动 20 | */ 21 | class Mysql extends Connection 22 | { 23 | 24 | protected $builder = '\\think\\db\\builder\\Mysql'; 25 | 26 | /** 27 | * 解析pdo连接的dsn信息 28 | * @access protected 29 | * @param array $config 连接信息 30 | * @return string 31 | */ 32 | protected function parseDsn($config) 33 | { 34 | if (!empty($config['socket'])) { 35 | $dsn = 'mysql:unix_socket=' . $config['socket']; 36 | } elseif (!empty($config['hostport'])) { 37 | $dsn = 'mysql:host=' . $config['hostname'] . ';port=' . $config['hostport']; 38 | } else { 39 | $dsn = 'mysql:host=' . $config['hostname']; 40 | } 41 | $dsn .= ';dbname=' . $config['database']; 42 | 43 | if (!empty($config['charset'])) { 44 | $dsn .= ';charset=' . $config['charset']; 45 | } 46 | return $dsn; 47 | } 48 | 49 | /** 50 | * 取得数据表的字段信息 51 | * @access public 52 | * @param string $tableName 53 | * @return array 54 | */ 55 | public function getFields($tableName) 56 | { 57 | list($tableName) = explode(' ', $tableName); 58 | if (false === strpos($tableName, '`')) { 59 | if (strpos($tableName, '.')) { 60 | $tableName = str_replace('.', '`.`', $tableName); 61 | } 62 | $tableName = '`' . $tableName . '`'; 63 | } 64 | $sql = 'SHOW COLUMNS FROM ' . $tableName; 65 | $pdo = $this->query($sql, [], false, true); 66 | $result = $pdo->fetchAll(PDO::FETCH_ASSOC); 67 | $info = []; 68 | if ($result) { 69 | foreach ($result as $key => $val) { 70 | $val = array_change_key_case($val); 71 | $info[$val['field']] = [ 72 | 'name' => $val['field'], 73 | 'type' => $val['type'], 74 | 'notnull' => (bool) ('' === $val['null']), // not null is empty, null is yes 75 | 'default' => $val['default'], 76 | 'primary' => (strtolower($val['key']) == 'pri'), 77 | 'autoinc' => (strtolower($val['extra']) == 'auto_increment'), 78 | ]; 79 | } 80 | } 81 | return $this->fieldCase($info); 82 | } 83 | 84 | /** 85 | * 取得数据库的表信息 86 | * @access public 87 | * @param string $dbName 88 | * @return array 89 | */ 90 | public function getTables($dbName = '') 91 | { 92 | $sql = !empty($dbName) ? 'SHOW TABLES FROM ' . $dbName : 'SHOW TABLES '; 93 | $pdo = $this->query($sql, [], false, true); 94 | $result = $pdo->fetchAll(PDO::FETCH_ASSOC); 95 | $info = []; 96 | foreach ($result as $key => $val) { 97 | $info[$key] = current($val); 98 | } 99 | return $info; 100 | } 101 | 102 | /** 103 | * SQL性能分析 104 | * @access protected 105 | * @param string $sql 106 | * @return array 107 | */ 108 | protected function getExplain($sql) 109 | { 110 | $pdo = $this->linkID->query("EXPLAIN " . $sql); 111 | $result = $pdo->fetch(PDO::FETCH_ASSOC); 112 | $result = array_change_key_case($result); 113 | if (isset($result['extra'])) { 114 | if (strpos($result['extra'], 'filesort') || strpos($result['extra'], 'temporary')) { 115 | Log::record('SQL:' . $this->queryStr . '[' . $result['extra'] . ']', 'warn'); 116 | } 117 | } 118 | return $result; 119 | } 120 | 121 | protected function supportSavepoint() 122 | { 123 | return true; 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /thinkphp/library/think/db/connector/Pgsql.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\db\connector; 13 | 14 | use PDO; 15 | use think\db\Connection; 16 | 17 | /** 18 | * Pgsql数据库驱动 19 | */ 20 | class Pgsql extends Connection 21 | { 22 | protected $builder = '\\think\\db\\builder\\Pgsql'; 23 | 24 | /** 25 | * 解析pdo连接的dsn信息 26 | * @access protected 27 | * @param array $config 连接信息 28 | * @return string 29 | */ 30 | protected function parseDsn($config) 31 | { 32 | $dsn = 'pgsql:dbname=' . $config['database'] . ';host=' . $config['hostname']; 33 | if (!empty($config['hostport'])) { 34 | $dsn .= ';port=' . $config['hostport']; 35 | } 36 | return $dsn; 37 | } 38 | 39 | /** 40 | * 取得数据表的字段信息 41 | * @access public 42 | * @param string $tableName 43 | * @return array 44 | */ 45 | public function getFields($tableName) 46 | { 47 | 48 | list($tableName) = explode(' ', $tableName); 49 | $sql = 'select fields_name as "field",fields_type as "type",fields_not_null as "null",fields_key_name as "key",fields_default as "default",fields_default as "extra" from table_msg(\'' . $tableName . '\');'; 50 | 51 | $pdo = $this->query($sql, [], false, true); 52 | $result = $pdo->fetchAll(PDO::FETCH_ASSOC); 53 | $info = []; 54 | if ($result) { 55 | foreach ($result as $key => $val) { 56 | $val = array_change_key_case($val); 57 | $info[$val['field']] = [ 58 | 'name' => $val['field'], 59 | 'type' => $val['type'], 60 | 'notnull' => (bool) ('' !== $val['null']), 61 | 'default' => $val['default'], 62 | 'primary' => !empty($val['key']), 63 | 'autoinc' => (0 === strpos($val['extra'], 'nextval(')), 64 | ]; 65 | } 66 | } 67 | return $this->fieldCase($info); 68 | } 69 | 70 | /** 71 | * 取得数据库的表信息 72 | * @access public 73 | * @param string $dbName 74 | * @return array 75 | */ 76 | public function getTables($dbName = '') 77 | { 78 | $sql = "select tablename as Tables_in_test from pg_tables where schemaname ='public'"; 79 | $pdo = $this->query($sql, [], false, true); 80 | $result = $pdo->fetchAll(PDO::FETCH_ASSOC); 81 | $info = []; 82 | foreach ($result as $key => $val) { 83 | $info[$key] = current($val); 84 | } 85 | return $info; 86 | } 87 | 88 | /** 89 | * SQL性能分析 90 | * @access protected 91 | * @param string $sql 92 | * @return array 93 | */ 94 | protected function getExplain($sql) 95 | { 96 | return []; 97 | } 98 | 99 | protected function supportSavepoint() 100 | { 101 | return true; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /thinkphp/library/think/db/connector/Sqlite.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\db\connector; 13 | 14 | use PDO; 15 | use think\db\Connection; 16 | 17 | /** 18 | * Sqlite数据库驱动 19 | */ 20 | class Sqlite extends Connection 21 | { 22 | 23 | protected $builder = '\\think\\db\\builder\\Sqlite'; 24 | 25 | /** 26 | * 解析pdo连接的dsn信息 27 | * @access protected 28 | * @param array $config 连接信息 29 | * @return string 30 | */ 31 | protected function parseDsn($config) 32 | { 33 | $dsn = 'sqlite:' . $config['database']; 34 | return $dsn; 35 | } 36 | 37 | /** 38 | * 取得数据表的字段信息 39 | * @access public 40 | * @param string $tableName 41 | * @return array 42 | */ 43 | public function getFields($tableName) 44 | { 45 | list($tableName) = explode(' ', $tableName); 46 | $sql = 'PRAGMA table_info( ' . $tableName . ' )'; 47 | 48 | $pdo = $this->query($sql, [], false, true); 49 | $result = $pdo->fetchAll(PDO::FETCH_ASSOC); 50 | $info = []; 51 | if ($result) { 52 | foreach ($result as $key => $val) { 53 | $val = array_change_key_case($val); 54 | $info[$val['name']] = [ 55 | 'name' => $val['name'], 56 | 'type' => $val['type'], 57 | 'notnull' => 1 === $val['notnull'], 58 | 'default' => $val['dflt_value'], 59 | 'primary' => '1' == $val['pk'], 60 | 'autoinc' => '1' == $val['pk'], 61 | ]; 62 | } 63 | } 64 | return $this->fieldCase($info); 65 | } 66 | 67 | /** 68 | * 取得数据库的表信息 69 | * @access public 70 | * @param string $dbName 71 | * @return array 72 | */ 73 | public function getTables($dbName = '') 74 | { 75 | 76 | $sql = "SELECT name FROM sqlite_master WHERE type='table' " 77 | . "UNION ALL SELECT name FROM sqlite_temp_master " 78 | . "WHERE type='table' ORDER BY name"; 79 | 80 | $pdo = $this->query($sql, [], false, true); 81 | $result = $pdo->fetchAll(PDO::FETCH_ASSOC); 82 | $info = []; 83 | foreach ($result as $key => $val) { 84 | $info[$key] = current($val); 85 | } 86 | return $info; 87 | } 88 | 89 | /** 90 | * SQL性能分析 91 | * @access protected 92 | * @param string $sql 93 | * @return array 94 | */ 95 | protected function getExplain($sql) 96 | { 97 | return []; 98 | } 99 | 100 | protected function supportSavepoint() 101 | { 102 | return true; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /thinkphp/library/think/db/connector/Sqlsrv.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\db\connector; 13 | 14 | use PDO; 15 | use think\db\Connection; 16 | 17 | /** 18 | * Sqlsrv数据库驱动 19 | */ 20 | class Sqlsrv extends Connection 21 | { 22 | // PDO连接参数 23 | protected $params = [ 24 | PDO::ATTR_CASE => PDO::CASE_NATURAL, 25 | PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, 26 | PDO::ATTR_STRINGIFY_FETCHES => false, 27 | ]; 28 | protected $builder = '\\think\\db\\builder\\Sqlsrv'; 29 | /** 30 | * 解析pdo连接的dsn信息 31 | * @access protected 32 | * @param array $config 连接信息 33 | * @return string 34 | */ 35 | protected function parseDsn($config) 36 | { 37 | $dsn = 'sqlsrv:Database=' . $config['database'] . ';Server=' . $config['hostname']; 38 | if (!empty($config['hostport'])) { 39 | $dsn .= ',' . $config['hostport']; 40 | } 41 | return $dsn; 42 | } 43 | 44 | /** 45 | * 取得数据表的字段信息 46 | * @access public 47 | * @param string $tableName 48 | * @return array 49 | */ 50 | public function getFields($tableName) 51 | { 52 | list($tableName) = explode(' ', $tableName); 53 | $sql = "SELECT column_name, data_type, column_default, is_nullable 54 | FROM information_schema.tables AS t 55 | JOIN information_schema.columns AS c 56 | ON t.table_catalog = c.table_catalog 57 | AND t.table_schema = c.table_schema 58 | AND t.table_name = c.table_name 59 | WHERE t.table_name = '$tableName'"; 60 | 61 | $pdo = $this->query($sql, [], false, true); 62 | $result = $pdo->fetchAll(PDO::FETCH_ASSOC); 63 | $info = []; 64 | if ($result) { 65 | foreach ($result as $key => $val) { 66 | $val = array_change_key_case($val); 67 | $info[$val['column_name']] = [ 68 | 'name' => $val['column_name'], 69 | 'type' => $val['data_type'], 70 | 'notnull' => (bool) ('' === $val['is_nullable']), // not null is empty, null is yes 71 | 'default' => $val['column_default'], 72 | 'primary' => false, 73 | 'autoinc' => false, 74 | ]; 75 | } 76 | } 77 | $sql = "SELECT column_name FROM information_schema.key_column_usage WHERE table_name='$tableName'"; 78 | // 调试开始 79 | $this->debug(true); 80 | $pdo = $this->linkID->query($sql); 81 | // 调试结束 82 | $this->debug(false, $sql); 83 | $result = $pdo->fetch(PDO::FETCH_ASSOC); 84 | if ($result) { 85 | $info[$result['column_name']]['primary'] = true; 86 | } 87 | return $this->fieldCase($info); 88 | } 89 | 90 | /** 91 | * 取得数据表的字段信息 92 | * @access public 93 | * @param string $dbName 94 | * @return array 95 | */ 96 | public function getTables($dbName = '') 97 | { 98 | $sql = "SELECT TABLE_NAME 99 | FROM INFORMATION_SCHEMA.TABLES 100 | WHERE TABLE_TYPE = 'BASE TABLE' 101 | "; 102 | 103 | $pdo = $this->query($sql, [], false, true); 104 | $result = $pdo->fetchAll(PDO::FETCH_ASSOC); 105 | $info = []; 106 | foreach ($result as $key => $val) { 107 | $info[$key] = current($val); 108 | } 109 | return $info; 110 | } 111 | 112 | /** 113 | * SQL性能分析 114 | * @access protected 115 | * @param string $sql 116 | * @return array 117 | */ 118 | protected function getExplain($sql) 119 | { 120 | return []; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /thinkphp/library/think/db/connector/pgsql.sql: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE FUNCTION pgsql_type(a_type varchar) RETURNS varchar AS 2 | $BODY$ 3 | DECLARE 4 | v_type varchar; 5 | BEGIN 6 | IF a_type='int8' THEN 7 | v_type:='bigint'; 8 | ELSIF a_type='int4' THEN 9 | v_type:='integer'; 10 | ELSIF a_type='int2' THEN 11 | v_type:='smallint'; 12 | ELSIF a_type='bpchar' THEN 13 | v_type:='char'; 14 | ELSE 15 | v_type:=a_type; 16 | END IF; 17 | RETURN v_type; 18 | END; 19 | $BODY$ 20 | LANGUAGE PLPGSQL; 21 | 22 | CREATE TYPE "public"."tablestruct" AS ( 23 | "fields_key_name" varchar(100), 24 | "fields_name" VARCHAR(200), 25 | "fields_type" VARCHAR(20), 26 | "fields_length" BIGINT, 27 | "fields_not_null" VARCHAR(10), 28 | "fields_default" VARCHAR(500), 29 | "fields_comment" VARCHAR(1000) 30 | ); 31 | 32 | CREATE OR REPLACE FUNCTION "public"."table_msg" (a_schema_name varchar, a_table_name varchar) RETURNS SETOF "public"."tablestruct" AS 33 | $body$ 34 | DECLARE 35 | v_ret tablestruct; 36 | v_oid oid; 37 | v_sql varchar; 38 | v_rec RECORD; 39 | v_key varchar; 40 | BEGIN 41 | SELECT 42 | pg_class.oid INTO v_oid 43 | FROM 44 | pg_class 45 | INNER JOIN pg_namespace ON (pg_class.relnamespace = pg_namespace.oid AND lower(pg_namespace.nspname) = a_schema_name) 46 | WHERE 47 | pg_class.relname=a_table_name; 48 | IF NOT FOUND THEN 49 | RETURN; 50 | END IF; 51 | 52 | v_sql=' 53 | SELECT 54 | pg_attribute.attname AS fields_name, 55 | pg_attribute.attnum AS fields_index, 56 | pgsql_type(pg_type.typname::varchar) AS fields_type, 57 | pg_attribute.atttypmod-4 as fields_length, 58 | CASE WHEN pg_attribute.attnotnull THEN ''not null'' 59 | ELSE '''' 60 | END AS fields_not_null, 61 | pg_attrdef.adsrc AS fields_default, 62 | pg_description.description AS fields_comment 63 | FROM 64 | pg_attribute 65 | INNER JOIN pg_class ON pg_attribute.attrelid = pg_class.oid 66 | INNER JOIN pg_type ON pg_attribute.atttypid = pg_type.oid 67 | LEFT OUTER JOIN pg_attrdef ON pg_attrdef.adrelid = pg_class.oid AND pg_attrdef.adnum = pg_attribute.attnum 68 | LEFT OUTER JOIN pg_description ON pg_description.objoid = pg_class.oid AND pg_description.objsubid = pg_attribute.attnum 69 | WHERE 70 | pg_attribute.attnum > 0 71 | AND attisdropped <> ''t'' 72 | AND pg_class.oid = ' || v_oid || ' 73 | ORDER BY pg_attribute.attnum' ; 74 | 75 | FOR v_rec IN EXECUTE v_sql LOOP 76 | v_ret.fields_name=v_rec.fields_name; 77 | v_ret.fields_type=v_rec.fields_type; 78 | IF v_rec.fields_length > 0 THEN 79 | v_ret.fields_length:=v_rec.fields_length; 80 | ELSE 81 | v_ret.fields_length:=NULL; 82 | END IF; 83 | v_ret.fields_not_null=v_rec.fields_not_null; 84 | v_ret.fields_default=v_rec.fields_default; 85 | v_ret.fields_comment=v_rec.fields_comment; 86 | SELECT constraint_name INTO v_key FROM information_schema.key_column_usage WHERE table_schema=a_schema_name AND table_name=a_table_name AND column_name=v_rec.fields_name; 87 | IF FOUND THEN 88 | v_ret.fields_key_name=v_key; 89 | ELSE 90 | v_ret.fields_key_name=''; 91 | END IF; 92 | RETURN NEXT v_ret; 93 | END LOOP; 94 | RETURN ; 95 | END; 96 | $body$ 97 | LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER; 98 | 99 | COMMENT ON FUNCTION "public"."table_msg"(a_schema_name varchar, a_table_name varchar) 100 | IS '获得表信息'; 101 | 102 | ---重载一个函数 103 | CREATE OR REPLACE FUNCTION "public"."table_msg" (a_table_name varchar) RETURNS SETOF "public"."tablestruct" AS 104 | $body$ 105 | DECLARE 106 | v_ret tablestruct; 107 | BEGIN 108 | FOR v_ret IN SELECT * FROM table_msg('public',a_table_name) LOOP 109 | RETURN NEXT v_ret; 110 | END LOOP; 111 | RETURN; 112 | END; 113 | $body$ 114 | LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER; 115 | 116 | COMMENT ON FUNCTION "public"."table_msg"(a_table_name varchar) 117 | IS '获得表信息'; -------------------------------------------------------------------------------- /thinkphp/library/think/db/exception/BindParamException.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\db\exception; 13 | 14 | use think\exception\DbException; 15 | 16 | /** 17 | * PDO参数绑定异常 18 | */ 19 | class BindParamException extends DbException 20 | { 21 | 22 | /** 23 | * BindParamException constructor. 24 | * @param string $message 25 | * @param array $config 26 | * @param string $sql 27 | * @param array $bind 28 | * @param int $code 29 | */ 30 | public function __construct($message, $config, $sql, $bind, $code = 10502) 31 | { 32 | $this->setData('Bind Param', $bind); 33 | parent::__construct($message, $config, $sql, $code); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /thinkphp/library/think/db/exception/DataNotFoundException.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\db\exception; 13 | 14 | use think\exception\DbException; 15 | 16 | class DataNotFoundException extends DbException 17 | { 18 | protected $table; 19 | 20 | /** 21 | * DbException constructor. 22 | * @param string $message 23 | * @param string $table 24 | * @param array $config 25 | */ 26 | public function __construct($message, $table = '', array $config = []) 27 | { 28 | $this->message = $message; 29 | $this->table = $table; 30 | 31 | $this->setData('Database Config', $config); 32 | } 33 | 34 | /** 35 | * 获取数据表名 36 | * @access public 37 | * @return string 38 | */ 39 | public function getTable() 40 | { 41 | return $this->table; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /thinkphp/library/think/db/exception/ModelNotFoundException.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\db\exception; 13 | 14 | use think\exception\DbException; 15 | 16 | class ModelNotFoundException extends DbException 17 | { 18 | protected $model; 19 | 20 | /** 21 | * 构造方法 22 | * @param string $message 23 | * @param string $model 24 | */ 25 | public function __construct($message, $model = '', array $config = []) 26 | { 27 | $this->message = $message; 28 | $this->model = $model; 29 | 30 | $this->setData('Database Config', $config); 31 | } 32 | 33 | /** 34 | * 获取模型类名 35 | * @access public 36 | * @return string 37 | */ 38 | public function getModel() 39 | { 40 | return $this->model; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /thinkphp/library/think/debug/Html.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\debug; 13 | 14 | use think\Cache; 15 | use think\Config; 16 | use think\Db; 17 | use think\Debug; 18 | use think\Request; 19 | use think\Response; 20 | 21 | /** 22 | * 页面Trace调试 23 | */ 24 | class Html 25 | { 26 | protected $config = [ 27 | 'trace_file' => '', 28 | 'trace_tabs' => ['base' => '基本', 'file' => '文件', 'info' => '流程', 'notice|error' => '错误', 'sql' => 'SQL', 'debug|log' => '调试'], 29 | ]; 30 | 31 | // 实例化并传入参数 32 | public function __construct(array $config = []) 33 | { 34 | $this->config['trace_file'] = THINK_PATH . 'tpl/page_trace.tpl'; 35 | $this->config = array_merge($this->config, $config); 36 | } 37 | 38 | /** 39 | * 调试输出接口 40 | * @access public 41 | * @param Response $response Response对象 42 | * @param array $log 日志信息 43 | * @return bool 44 | */ 45 | public function output(Response $response, array $log = []) 46 | { 47 | $request = Request::instance(); 48 | $contentType = $response->getHeader('Content-Type'); 49 | $accept = $request->header('accept'); 50 | if (strpos($accept, 'application/json') === 0 || $request->isAjax()) { 51 | return false; 52 | } elseif (!empty($contentType) && strpos($contentType, 'html') === false) { 53 | return false; 54 | } 55 | // 获取基本信息 56 | $runtime = number_format(microtime(true) - THINK_START_TIME, 10); 57 | $reqs = $runtime > 0 ? number_format(1 / $runtime, 2) : '∞'; 58 | $mem = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2); 59 | 60 | // 页面Trace信息 61 | if (isset($_SERVER['HTTP_HOST'])) { 62 | $uri = $_SERVER['SERVER_PROTOCOL'] . ' ' . $_SERVER['REQUEST_METHOD'] . ' : ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 63 | } else { 64 | $uri = 'cmd:' . implode(' ', $_SERVER['argv']); 65 | } 66 | $base = [ 67 | '请求信息' => date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']) . ' ' . $uri, 68 | '运行时间' => number_format($runtime, 6) . 's [ 吞吐率:' . $reqs . 'req/s ] 内存消耗:' . $mem . 'kb 文件加载:' . count(get_included_files()), 69 | '查询信息' => Db::$queryTimes . ' queries ' . Db::$executeTimes . ' writes ', 70 | '缓存信息' => Cache::$readTimes . ' reads,' . Cache::$writeTimes . ' writes', 71 | '配置加载' => count(Config::get()), 72 | ]; 73 | 74 | if (session_id()) { 75 | $base['会话信息'] = 'SESSION_ID=' . session_id(); 76 | } 77 | 78 | $info = Debug::getFile(true); 79 | 80 | // 页面Trace信息 81 | $trace = []; 82 | foreach ($this->config['trace_tabs'] as $name => $title) { 83 | $name = strtolower($name); 84 | switch ($name) { 85 | case 'base': // 基本信息 86 | $trace[$title] = $base; 87 | break; 88 | case 'file': // 文件信息 89 | $trace[$title] = $info; 90 | break; 91 | default: // 调试信息 92 | if (strpos($name, '|')) { 93 | // 多组信息 94 | $names = explode('|', $name); 95 | $result = []; 96 | foreach ($names as $name) { 97 | $result = array_merge($result, isset($log[$name]) ? $log[$name] : []); 98 | } 99 | $trace[$title] = $result; 100 | } else { 101 | $trace[$title] = isset($log[$name]) ? $log[$name] : ''; 102 | } 103 | } 104 | } 105 | // 调用Trace页面模板 106 | ob_start(); 107 | include $this->config['trace_file']; 108 | return ob_get_clean(); 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /thinkphp/library/think/exception/ClassNotFoundException.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\exception; 13 | 14 | class ClassNotFoundException extends \RuntimeException 15 | { 16 | protected $class; 17 | public function __construct($message, $class = '') 18 | { 19 | $this->message = $message; 20 | $this->class = $class; 21 | } 22 | 23 | /** 24 | * 获取类名 25 | * @access public 26 | * @return string 27 | */ 28 | public function getClass() 29 | { 30 | return $this->class; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /thinkphp/library/think/exception/DbException.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\exception; 13 | 14 | use think\Exception; 15 | 16 | /** 17 | * Database相关异常处理类 18 | */ 19 | class DbException extends Exception 20 | { 21 | /** 22 | * DbException constructor. 23 | * @param string $message 24 | * @param array $config 25 | * @param string $sql 26 | * @param int $code 27 | */ 28 | public function __construct($message, array $config, $sql, $code = 10500) 29 | { 30 | $this->message = $message; 31 | $this->code = $code; 32 | 33 | $this->setData('Database Status', [ 34 | 'Error Code' => $code, 35 | 'Error Message' => $message, 36 | 'Error SQL' => $sql, 37 | ]); 38 | 39 | unset($config['username'], $config['password']); 40 | $this->setData('Database Config', $config); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /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/HttpException.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\exception; 13 | 14 | class HttpException extends \RuntimeException 15 | { 16 | private $statusCode; 17 | private $headers; 18 | 19 | public function __construct($statusCode, $message = null, \Exception $previous = null, array $headers = [], $code = 0) 20 | { 21 | $this->statusCode = $statusCode; 22 | $this->headers = $headers; 23 | 24 | parent::__construct($message, $code, $previous); 25 | } 26 | 27 | public function getStatusCode() 28 | { 29 | return $this->statusCode; 30 | } 31 | 32 | public function getHeaders() 33 | { 34 | return $this->headers; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /thinkphp/library/think/exception/HttpResponseException.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\exception; 13 | 14 | use think\Response; 15 | 16 | class HttpResponseException extends \RuntimeException 17 | { 18 | /** 19 | * @var Response 20 | */ 21 | protected $response; 22 | 23 | public function __construct(Response $response) 24 | { 25 | $this->response = $response; 26 | } 27 | 28 | public function getResponse() 29 | { 30 | return $this->response; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /thinkphp/library/think/exception/PDOException.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\exception; 13 | 14 | /** 15 | * PDO异常处理类 16 | * 重新封装了系统的\PDOException类 17 | */ 18 | class PDOException extends DbException 19 | { 20 | /** 21 | * PDOException constructor. 22 | * @param \PDOException $exception 23 | * @param array $config 24 | * @param string $sql 25 | * @param int $code 26 | */ 27 | public function __construct(\PDOException $exception, array $config, $sql, $code = 10501) 28 | { 29 | $error = $exception->errorInfo; 30 | 31 | $this->setData('PDO Error Info', [ 32 | 'SQLSTATE' => $error[0], 33 | 'Driver Error Code' => isset($error[1]) ? $error[1] : 0, 34 | 'Driver Error Message' => isset($error[2]) ? $error[2] : '', 35 | ]); 36 | 37 | parent::__construct($exception->getMessage(), $config, $sql, $code); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /thinkphp/library/think/exception/RouteNotFoundException.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\exception; 13 | 14 | class RouteNotFoundException extends HttpException 15 | { 16 | 17 | public function __construct() 18 | { 19 | parent::__construct(404, 'Route Not Found'); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /thinkphp/library/think/exception/TemplateNotFoundException.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\exception; 13 | 14 | class TemplateNotFoundException extends \RuntimeException 15 | { 16 | protected $template; 17 | 18 | public function __construct($message, $template = '') 19 | { 20 | $this->message = $message; 21 | $this->template = $template; 22 | } 23 | 24 | /** 25 | * 获取模板文件 26 | * @access public 27 | * @return string 28 | */ 29 | public function getTemplate() 30 | { 31 | return $this->template; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /thinkphp/library/think/exception/ThrowableError.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\exception; 13 | 14 | class ThrowableError extends \ErrorException 15 | { 16 | public function __construct(\Throwable $e) 17 | { 18 | 19 | if ($e instanceof \ParseError) { 20 | $message = 'Parse error: ' . $e->getMessage(); 21 | $severity = E_PARSE; 22 | } elseif ($e instanceof \TypeError) { 23 | $message = 'Type error: ' . $e->getMessage(); 24 | $severity = E_RECOVERABLE_ERROR; 25 | } else { 26 | $message = 'Fatal error: ' . $e->getMessage(); 27 | $severity = E_ERROR; 28 | } 29 | 30 | parent::__construct( 31 | $message, 32 | $e->getCode(), 33 | $severity, 34 | $e->getFile(), 35 | $e->getLine() 36 | ); 37 | 38 | $this->setTrace($e->getTrace()); 39 | } 40 | 41 | protected function setTrace($trace) 42 | { 43 | $traceReflector = new \ReflectionProperty('Exception', 'trace'); 44 | $traceReflector->setAccessible(true); 45 | $traceReflector->setValue($this, $trace); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /thinkphp/library/think/exception/ValidateException.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\exception; 13 | 14 | class ValidateException extends \RuntimeException 15 | { 16 | protected $error; 17 | 18 | public function __construct($error) 19 | { 20 | $this->error = $error; 21 | $this->message = is_array($error) ? implode("\n\r", $error) : $error; 22 | } 23 | 24 | /** 25 | * 获取验证错误信息 26 | * @access public 27 | * @return array|string 28 | */ 29 | public function getError() 30 | { 31 | return $this->error; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /thinkphp/library/think/log/driver/File.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\log\driver; 13 | 14 | use think\App; 15 | 16 | /** 17 | * 本地化调试输出到文件 18 | */ 19 | class File 20 | { 21 | protected $config = [ 22 | 'time_format' => ' c ', 23 | 'file_size' => 2097152, 24 | 'path' => LOG_PATH, 25 | 'apart_level' => [], 26 | ]; 27 | 28 | protected $writed = []; 29 | 30 | // 实例化并传入参数 31 | public function __construct($config = []) 32 | { 33 | if (is_array($config)) { 34 | $this->config = array_merge($this->config, $config); 35 | } 36 | } 37 | 38 | /** 39 | * 日志写入接口 40 | * @access public 41 | * @param array $log 日志信息 42 | * @return bool 43 | */ 44 | public function save(array $log = []) 45 | { 46 | $cli = IS_CLI ? '_cli' : ''; 47 | $destination = $this->config['path'] . date('Ym') . DS . date('d') . $cli . '.log'; 48 | 49 | $path = dirname($destination); 50 | !is_dir($path) && mkdir($path, 0755, true); 51 | 52 | $info = ''; 53 | foreach ($log as $type => $val) { 54 | $level = ''; 55 | foreach ($val as $msg) { 56 | if (!is_string($msg)) { 57 | $msg = var_export($msg, true); 58 | } 59 | $level .= '[ ' . $type . ' ] ' . $msg . "\r\n"; 60 | } 61 | if (in_array($type, $this->config['apart_level'])) { 62 | // 独立记录的日志级别 63 | $filename = $path . DS . date('d') . '_' . $type . $cli . '.log'; 64 | $this->write($level, $filename, true); 65 | } else { 66 | $info .= $level; 67 | } 68 | } 69 | if ($info) { 70 | return $this->write($info, $destination); 71 | } 72 | return true; 73 | } 74 | 75 | protected function write($message, $destination, $apart = false) 76 | { 77 | //检测日志文件大小,超过配置大小则备份日志文件重新生成 78 | if (is_file($destination) && floor($this->config['file_size']) <= filesize($destination)) { 79 | rename($destination, dirname($destination) . DS . time() . '-' . basename($destination)); 80 | $this->writed[$destination] = false; 81 | } 82 | 83 | if (empty($this->writed[$destination]) && !IS_CLI) { 84 | if (App::$debug && !$apart) { 85 | // 获取基本信息 86 | if (isset($_SERVER['HTTP_HOST'])) { 87 | $current_uri = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 88 | } else { 89 | $current_uri = "cmd:" . implode(' ', $_SERVER['argv']); 90 | } 91 | 92 | $runtime = round(microtime(true) - THINK_START_TIME, 10); 93 | $reqs = $runtime > 0 ? number_format(1 / $runtime, 2) : '∞'; 94 | $time_str = ' [运行时间:' . number_format($runtime, 6) . 's][吞吐率:' . $reqs . 'req/s]'; 95 | $memory_use = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2); 96 | $memory_str = ' [内存消耗:' . $memory_use . 'kb]'; 97 | $file_load = ' [文件加载:' . count(get_included_files()) . ']'; 98 | 99 | $message = '[ info ] ' . $current_uri . $time_str . $memory_str . $file_load . "\r\n" . $message; 100 | } 101 | $now = date($this->config['time_format']); 102 | $server = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '0.0.0.0'; 103 | $remote = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0'; 104 | $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'CLI'; 105 | $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; 106 | $message = "---------------------------------------------------------------\r\n[{$now}] {$server} {$remote} {$method} {$uri}\r\n" . $message; 107 | 108 | $this->writed[$destination] = true; 109 | } 110 | 111 | if (IS_CLI) { 112 | $now = date($this->config['time_format']); 113 | $message = "[{$now}]" . $message; 114 | } 115 | 116 | return error_log($message, 3, $destination); 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /thinkphp/library/think/log/driver/Test.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\log\driver; 13 | 14 | /** 15 | * 模拟测试输出 16 | */ 17 | class Test 18 | { 19 | /** 20 | * 日志写入接口 21 | * @access public 22 | * @param array $log 日志信息 23 | * @return bool 24 | */ 25 | public function save(array $log = []) 26 | { 27 | return true; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /thinkphp/library/think/model/Collection.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\model; 13 | 14 | use think\Collection as BaseCollection; 15 | use think\Model; 16 | 17 | class Collection extends BaseCollection 18 | { 19 | /** 20 | * 返回数组中指定的一列 21 | * @param string $column_key 22 | * @param string|null $index_key 23 | * @return array 24 | */ 25 | public function column($column_key, $index_key = null) 26 | { 27 | if (function_exists('array_column')) { 28 | return array_column($this->toArray(), $column_key, $index_key); 29 | } 30 | return parent::column($column_key, $index_key); 31 | } 32 | 33 | /** 34 | * 延迟预载入关联查询 35 | * @access public 36 | * @param mixed $relation 关联 37 | * @return $this 38 | */ 39 | public function load($relation) 40 | { 41 | $item = current($this->items); 42 | $item->eagerlyResultSet($this->items, $relation); 43 | return $this; 44 | } 45 | 46 | /** 47 | * 设置需要隐藏的输出属性 48 | * @access public 49 | * @param array $hidden 属性列表 50 | * @param bool $override 是否覆盖 51 | * @return $this 52 | */ 53 | public function hidden($hidden = [], $override = false) 54 | { 55 | $this->each(function ($model) use ($hidden, $override) { 56 | /** @var Model $model */ 57 | $model->hidden($hidden, $override); 58 | }); 59 | return $this; 60 | } 61 | 62 | /** 63 | * 设置需要输出的属性 64 | * @param array $visible 65 | * @param bool $override 是否覆盖 66 | * @return $this 67 | */ 68 | public function visible($visible = [], $override = false) 69 | { 70 | $this->each(function ($model) use ($visible, $override) { 71 | /** @var Model $model */ 72 | $model->visible($visible, $override); 73 | }); 74 | return $this; 75 | } 76 | 77 | /** 78 | * 设置需要追加的输出属性 79 | * @access public 80 | * @param array $append 属性列表 81 | * @param bool $override 是否覆盖 82 | * @return $this 83 | */ 84 | public function append($append = [], $override = false) 85 | { 86 | $this->each(function ($model) use ($append, $override) { 87 | /** @var Model $model */ 88 | $model && $model->append($append, $override); 89 | }); 90 | return $this; 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /thinkphp/library/think/model/Pivot.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\model; 13 | 14 | use think\Model; 15 | 16 | class Pivot extends Model 17 | { 18 | 19 | /** @var Model */ 20 | public $parent; 21 | 22 | protected $autoWriteTimestamp = false; 23 | 24 | /** 25 | * 架构函数 26 | * @access public 27 | * @param Model $parent 上级模型 28 | * @param array|object $data 数据 29 | * @param string $table 中间数据表名 30 | */ 31 | public function __construct(Model $parent = null, $data = [], $table = '') 32 | { 33 | $this->parent = $parent; 34 | 35 | if (is_null($this->name)) { 36 | $this->name = $table; 37 | } 38 | 39 | parent::__construct($data); 40 | 41 | $this->class = $this->name; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /thinkphp/library/think/model/Relation.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\model; 13 | 14 | use think\db\Query; 15 | use think\Exception; 16 | use think\Model; 17 | 18 | /** 19 | * Class Relation 20 | * @package think\model 21 | * 22 | * @mixin Query 23 | */ 24 | abstract class Relation 25 | { 26 | // 父模型对象 27 | protected $parent; 28 | /** @var Model 当前关联的模型类 */ 29 | protected $model; 30 | /** @var Query 关联模型查询对象 */ 31 | protected $query; 32 | // 关联表外键 33 | protected $foreignKey; 34 | // 关联表主键 35 | protected $localKey; 36 | // 基础查询 37 | protected $baseQuery; 38 | 39 | /** 40 | * 获取关联的所属模型 41 | * @access public 42 | * @return Model 43 | */ 44 | public function getParent() 45 | { 46 | return $this->parent; 47 | } 48 | 49 | /** 50 | * 获取当前的关联模型类 51 | * @access public 52 | * @return string 53 | */ 54 | public function getModel() 55 | { 56 | return $this->model; 57 | } 58 | 59 | /** 60 | * 获取关联的查询对象 61 | * @access public 62 | * @return Query 63 | */ 64 | public function getQuery() 65 | { 66 | return $this->query; 67 | } 68 | 69 | /** 70 | * 封装关联数据集 71 | * @access public 72 | * @param array $resultSet 数据集 73 | * @return mixed 74 | */ 75 | protected function resultSetBuild($resultSet) 76 | { 77 | return (new $this->model)->toCollection($resultSet); 78 | } 79 | 80 | protected function getQueryFields($model) 81 | { 82 | $fields = $this->query->getOptions('field'); 83 | return $this->getRelationQueryFields($fields, $model); 84 | } 85 | 86 | protected function getRelationQueryFields($fields, $model) 87 | { 88 | if ($fields) { 89 | 90 | if (is_string($fields)) { 91 | $fields = explode(',', $fields); 92 | } 93 | 94 | foreach ($fields as &$field) { 95 | if (false === strpos($field, '.')) { 96 | $field = $model . '.' . $field; 97 | } 98 | } 99 | } else { 100 | $fields = $model . '.*'; 101 | } 102 | 103 | return $fields; 104 | } 105 | 106 | /** 107 | * 执行基础查询(仅执行一次) 108 | * @access protected 109 | * @return void 110 | */ 111 | protected function baseQuery() 112 | {} 113 | 114 | public function __call($method, $args) 115 | { 116 | if ($this->query) { 117 | // 执行基础查询 118 | $this->baseQuery(); 119 | 120 | $result = call_user_func_array([$this->query, $method], $args); 121 | if ($result instanceof Query) { 122 | return $this; 123 | } else { 124 | $this->baseQuery = false; 125 | return $result; 126 | } 127 | } else { 128 | throw new Exception('method not exists:' . __CLASS__ . '->' . $method); 129 | } 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /thinkphp/library/think/process/Utils.php: -------------------------------------------------------------------------------- 1 | 8 | // +---------------------------------------------------------------------- 9 | 10 | namespace think\process; 11 | 12 | class Utils 13 | { 14 | 15 | /** 16 | * 转义字符串 17 | * @param string $argument 18 | * @return string 19 | */ 20 | public static function escapeArgument($argument) 21 | { 22 | 23 | if ('' === $argument) { 24 | return escapeshellarg($argument); 25 | } 26 | $escapedArgument = ''; 27 | $quote = false; 28 | foreach (preg_split('/(")/i', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) { 29 | if ('"' === $part) { 30 | $escapedArgument .= '\\"'; 31 | } elseif (self::isSurroundedBy($part, '%')) { 32 | // Avoid environment variable expansion 33 | $escapedArgument .= '^%"' . substr($part, 1, -1) . '"^%'; 34 | } else { 35 | // escape trailing backslash 36 | if ('\\' === substr($part, -1)) { 37 | $part .= '\\'; 38 | } 39 | $quote = true; 40 | $escapedArgument .= $part; 41 | } 42 | } 43 | if ($quote) { 44 | $escapedArgument = '"' . $escapedArgument . '"'; 45 | } 46 | return $escapedArgument; 47 | } 48 | 49 | /** 50 | * 验证并进行规范化Process输入。 51 | * @param string $caller 52 | * @param mixed $input 53 | * @return string 54 | * @throws \InvalidArgumentException 55 | */ 56 | public static function validateInput($caller, $input) 57 | { 58 | if (null !== $input) { 59 | if (is_resource($input)) { 60 | return $input; 61 | } 62 | if (is_scalar($input)) { 63 | return (string) $input; 64 | } 65 | throw new \InvalidArgumentException(sprintf('%s only accepts strings or stream resources.', $caller)); 66 | } 67 | return $input; 68 | } 69 | 70 | private static function isSurroundedBy($arg, $char) 71 | { 72 | return 2 < strlen($arg) && $char === $arg[0] && $char === $arg[strlen($arg) - 1]; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /thinkphp/library/think/process/exception/Failed.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\process\exception; 13 | 14 | use think\Process; 15 | 16 | class Failed extends \RuntimeException 17 | { 18 | 19 | private $process; 20 | 21 | public function __construct(Process $process) 22 | { 23 | if ($process->isSuccessful()) { 24 | throw new \InvalidArgumentException('Expected a failed process, but the given process was successful.'); 25 | } 26 | 27 | $error = sprintf('The command "%s" failed.' . "\nExit Code: %s(%s)", $process->getCommandLine(), $process->getExitCode(), $process->getExitCodeText()); 28 | 29 | if (!$process->isOutputDisabled()) { 30 | $error .= sprintf("\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s", $process->getOutput(), $process->getErrorOutput()); 31 | } 32 | 33 | parent::__construct($error); 34 | 35 | $this->process = $process; 36 | } 37 | 38 | public function getProcess() 39 | { 40 | return $this->process; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /thinkphp/library/think/process/exception/Timeout.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\process\exception; 13 | 14 | use think\Process; 15 | 16 | class Timeout extends \RuntimeException 17 | { 18 | 19 | const TYPE_GENERAL = 1; 20 | const TYPE_IDLE = 2; 21 | 22 | private $process; 23 | private $timeoutType; 24 | 25 | public function __construct(Process $process, $timeoutType) 26 | { 27 | $this->process = $process; 28 | $this->timeoutType = $timeoutType; 29 | 30 | parent::__construct(sprintf('The process "%s" exceeded the timeout of %s seconds.', $process->getCommandLine(), $this->getExceededTimeout())); 31 | } 32 | 33 | public function getProcess() 34 | { 35 | return $this->process; 36 | } 37 | 38 | public function isGeneralTimeout() 39 | { 40 | return $this->timeoutType === self::TYPE_GENERAL; 41 | } 42 | 43 | public function isIdleTimeout() 44 | { 45 | return $this->timeoutType === self::TYPE_IDLE; 46 | } 47 | 48 | public function getExceededTimeout() 49 | { 50 | switch ($this->timeoutType) { 51 | case self::TYPE_GENERAL: 52 | return $this->process->getTimeout(); 53 | 54 | case self::TYPE_IDLE: 55 | return $this->process->getIdleTimeout(); 56 | 57 | default: 58 | throw new \LogicException(sprintf('Unknown timeout type "%d".', $this->timeoutType)); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /thinkphp/library/think/process/pipes/Pipes.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\process\pipes; 13 | 14 | abstract class Pipes 15 | { 16 | 17 | /** @var array */ 18 | public $pipes = []; 19 | 20 | /** @var string */ 21 | protected $inputBuffer = ''; 22 | /** @var resource|null */ 23 | protected $input; 24 | 25 | /** @var bool */ 26 | private $blocked = true; 27 | 28 | const CHUNK_SIZE = 16384; 29 | 30 | /** 31 | * 返回用于 proc_open 描述符的数组 32 | * @return array 33 | */ 34 | abstract public function getDescriptors(); 35 | 36 | /** 37 | * 返回一个数组的索引由其相关的流,以防这些管道使用的临时文件的文件名。 38 | * @return string[] 39 | */ 40 | abstract public function getFiles(); 41 | 42 | /** 43 | * 文件句柄和管道中读取数据。 44 | * @param bool $blocking 是否使用阻塞调用 45 | * @param bool $close 是否要关闭管道,如果他们已经到达 EOF。 46 | * @return string[] 47 | */ 48 | abstract public function readAndWrite($blocking, $close = false); 49 | 50 | /** 51 | * 返回当前状态如果有打开的文件句柄或管道。 52 | * @return bool 53 | */ 54 | abstract public function areOpen(); 55 | 56 | /** 57 | * {@inheritdoc} 58 | */ 59 | public function close() 60 | { 61 | foreach ($this->pipes as $pipe) { 62 | fclose($pipe); 63 | } 64 | $this->pipes = []; 65 | } 66 | 67 | /** 68 | * 检查系统调用已被中断 69 | * @return bool 70 | */ 71 | protected function hasSystemCallBeenInterrupted() 72 | { 73 | $lastError = error_get_last(); 74 | 75 | return isset($lastError['message']) && false !== stripos($lastError['message'], 'interrupted system call'); 76 | } 77 | 78 | protected function unblock() 79 | { 80 | if (!$this->blocked) { 81 | return; 82 | } 83 | 84 | foreach ($this->pipes as $pipe) { 85 | stream_set_blocking($pipe, 0); 86 | } 87 | if (null !== $this->input) { 88 | stream_set_blocking($this->input, 0); 89 | } 90 | 91 | $this->blocked = false; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /thinkphp/library/think/response/Json.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\response; 13 | 14 | use think\Response; 15 | 16 | class Json extends Response 17 | { 18 | // 输出参数 19 | protected $options = [ 20 | 'json_encode_param' => JSON_UNESCAPED_UNICODE, 21 | ]; 22 | 23 | protected $contentType = 'application/json'; 24 | 25 | /** 26 | * 处理数据 27 | * @access protected 28 | * @param mixed $data 要处理的数据 29 | * @return mixed 30 | * @throws \Exception 31 | */ 32 | protected function output($data) 33 | { 34 | try { 35 | // 返回JSON数据格式到客户端 包含状态信息 36 | $data = json_encode($data, $this->options['json_encode_param']); 37 | 38 | if ($data === false) { 39 | throw new \InvalidArgumentException(json_last_error_msg()); 40 | } 41 | 42 | return $data; 43 | } catch (\Exception $e) { 44 | if ($e->getPrevious()) { 45 | throw $e->getPrevious(); 46 | } 47 | throw $e; 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /thinkphp/library/think/response/Jsonp.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\response; 13 | 14 | use think\Request; 15 | use think\Response; 16 | 17 | class Jsonp extends Response 18 | { 19 | // 输出参数 20 | protected $options = [ 21 | 'var_jsonp_handler' => 'callback', 22 | 'default_jsonp_handler' => 'jsonpReturn', 23 | 'json_encode_param' => JSON_UNESCAPED_UNICODE, 24 | ]; 25 | 26 | protected $contentType = 'application/javascript'; 27 | 28 | /** 29 | * 处理数据 30 | * @access protected 31 | * @param mixed $data 要处理的数据 32 | * @return mixed 33 | * @throws \Exception 34 | */ 35 | protected function output($data) 36 | { 37 | try { 38 | // 返回JSON数据格式到客户端 包含状态信息 [当url_common_param为false时是无法获取到$_GET的数据的,故使用Request来获取] 39 | $var_jsonp_handler = Request::instance()->param($this->options['var_jsonp_handler'], ""); 40 | $handler = !empty($var_jsonp_handler) ? $var_jsonp_handler : $this->options['default_jsonp_handler']; 41 | 42 | $data = json_encode($data, $this->options['json_encode_param']); 43 | 44 | if ($data === false) { 45 | throw new \InvalidArgumentException(json_last_error_msg()); 46 | } 47 | 48 | $data = $handler . '(' . $data . ');'; 49 | return $data; 50 | } catch (\Exception $e) { 51 | if ($e->getPrevious()) { 52 | throw $e->getPrevious(); 53 | } 54 | throw $e; 55 | } 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /thinkphp/library/think/response/Redirect.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\response; 13 | 14 | use think\Request; 15 | use think\Response; 16 | use think\Session; 17 | use think\Url; 18 | 19 | class Redirect extends Response 20 | { 21 | 22 | protected $options = []; 23 | 24 | // URL参数 25 | protected $params = []; 26 | 27 | public function __construct($data = '', $code = 302, array $header = [], array $options = []) 28 | { 29 | parent::__construct($data, $code, $header, $options); 30 | $this->cacheControl('no-cache,must-revalidate'); 31 | } 32 | 33 | /** 34 | * 处理数据 35 | * @access protected 36 | * @param mixed $data 要处理的数据 37 | * @return mixed 38 | */ 39 | protected function output($data) 40 | { 41 | $this->header['Location'] = $this->getTargetUrl(); 42 | return; 43 | } 44 | 45 | /** 46 | * 重定向传值(通过Session) 47 | * @access protected 48 | * @param string|array $name 变量名或者数组 49 | * @param mixed $value 值 50 | * @return $this 51 | */ 52 | public function with($name, $value = null) 53 | { 54 | if (is_array($name)) { 55 | foreach ($name as $key => $val) { 56 | Session::flash($key, $val); 57 | } 58 | } else { 59 | Session::flash($name, $value); 60 | } 61 | return $this; 62 | } 63 | 64 | /** 65 | * 获取跳转地址 66 | * @return string 67 | */ 68 | public function getTargetUrl() 69 | { 70 | if (strpos($this->data, '://') || (0 === strpos($this->data, '/') && empty($this->params))) { 71 | return $this->data; 72 | } else { 73 | return Url::build($this->data, $this->params); 74 | } 75 | } 76 | 77 | public function params($params = []) 78 | { 79 | $this->params = $params; 80 | return $this; 81 | } 82 | 83 | /** 84 | * 记住当前url后跳转 85 | * @return $this 86 | */ 87 | public function remember() 88 | { 89 | Session::set('redirect_url', Request::instance()->url()); 90 | return $this; 91 | } 92 | 93 | /** 94 | * 跳转到上次记住的url 95 | * @return $this 96 | */ 97 | public function restore() 98 | { 99 | if (Session::has('redirect_url')) { 100 | $this->data = Session::get('redirect_url'); 101 | Session::delete('redirect_url'); 102 | } 103 | return $this; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /thinkphp/library/think/response/View.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\response; 13 | 14 | use think\Config; 15 | use think\Response; 16 | use think\View as ViewTemplate; 17 | 18 | class View extends Response 19 | { 20 | // 输出参数 21 | protected $options = []; 22 | protected $vars = []; 23 | protected $replace = []; 24 | protected $contentType = 'text/html'; 25 | 26 | /** 27 | * 处理数据 28 | * @access protected 29 | * @param mixed $data 要处理的数据 30 | * @return mixed 31 | */ 32 | protected function output($data) 33 | { 34 | // 渲染模板输出 35 | return ViewTemplate::instance(Config::get('template'), Config::get('view_replace_str')) 36 | ->fetch($data, $this->vars, $this->replace); 37 | } 38 | 39 | /** 40 | * 获取视图变量 41 | * @access public 42 | * @param string $name 模板变量 43 | * @return mixed 44 | */ 45 | public function getVars($name = null) 46 | { 47 | if (is_null($name)) { 48 | return $this->vars; 49 | } else { 50 | return isset($this->vars[$name]) ? $this->vars[$name] : null; 51 | } 52 | } 53 | 54 | /** 55 | * 模板变量赋值 56 | * @access public 57 | * @param mixed $name 变量名 58 | * @param mixed $value 变量值 59 | * @return $this 60 | */ 61 | public function assign($name, $value = '') 62 | { 63 | if (is_array($name)) { 64 | $this->vars = array_merge($this->vars, $name); 65 | return $this; 66 | } else { 67 | $this->vars[$name] = $value; 68 | } 69 | return $this; 70 | } 71 | 72 | /** 73 | * 视图内容替换 74 | * @access public 75 | * @param string|array $content 被替换内容(支持批量替换) 76 | * @param string $replace 替换内容 77 | * @return $this 78 | */ 79 | public function replace($content, $replace = '') 80 | { 81 | if (is_array($content)) { 82 | $this->replace = array_merge($this->replace, $content); 83 | } else { 84 | $this->replace[$content] = $replace; 85 | } 86 | return $this; 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /thinkphp/library/think/response/Xml.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\response; 13 | 14 | use think\Collection; 15 | use think\Model; 16 | use think\Response; 17 | 18 | class Xml extends Response 19 | { 20 | // 输出参数 21 | protected $options = [ 22 | // 根节点名 23 | 'root_node' => 'think', 24 | // 根节点属性 25 | 'root_attr' => '', 26 | //数字索引的子节点名 27 | 'item_node' => 'item', 28 | // 数字索引子节点key转换的属性名 29 | 'item_key' => 'id', 30 | // 数据编码 31 | 'encoding' => 'utf-8', 32 | ]; 33 | 34 | protected $contentType = 'text/xml'; 35 | 36 | /** 37 | * 处理数据 38 | * @access protected 39 | * @param mixed $data 要处理的数据 40 | * @return mixed 41 | */ 42 | protected function output($data) 43 | { 44 | // XML数据转换 45 | return $this->xmlEncode($data, $this->options['root_node'], $this->options['item_node'], $this->options['root_attr'], $this->options['item_key'], $this->options['encoding']); 46 | } 47 | 48 | /** 49 | * XML编码 50 | * @param mixed $data 数据 51 | * @param string $root 根节点名 52 | * @param string $item 数字索引的子节点名 53 | * @param string $attr 根节点属性 54 | * @param string $id 数字索引子节点key转换的属性名 55 | * @param string $encoding 数据编码 56 | * @return string 57 | */ 58 | protected function xmlEncode($data, $root, $item, $attr, $id, $encoding) 59 | { 60 | if (is_array($attr)) { 61 | $array = []; 62 | foreach ($attr as $key => $value) { 63 | $array[] = "{$key}=\"{$value}\""; 64 | } 65 | $attr = implode(' ', $array); 66 | } 67 | $attr = trim($attr); 68 | $attr = empty($attr) ? '' : " {$attr}"; 69 | $xml = ""; 70 | $xml .= "<{$root}{$attr}>"; 71 | $xml .= $this->dataToXml($data, $item, $id); 72 | $xml .= ""; 73 | return $xml; 74 | } 75 | 76 | /** 77 | * 数据XML编码 78 | * @param mixed $data 数据 79 | * @param string $item 数字索引时的节点名称 80 | * @param string $id 数字索引key转换为的属性名 81 | * @return string 82 | */ 83 | protected function dataToXml($data, $item, $id) 84 | { 85 | $xml = $attr = ''; 86 | 87 | if ($data instanceof Collection || $data instanceof Model) { 88 | $data = $data->toArray(); 89 | } 90 | 91 | foreach ($data as $key => $val) { 92 | if (is_numeric($key)) { 93 | $id && $attr = " {$id}=\"{$key}\""; 94 | $key = $item; 95 | } 96 | $xml .= "<{$key}{$attr}>"; 97 | $xml .= (is_array($val) || is_object($val)) ? $this->dataToXml($val, $item, $id) : $val; 98 | $xml .= ""; 99 | } 100 | return $xml; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /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' => 11211, // 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 support: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 (string) $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 | * @return bool 91 | */ 92 | public function write($sessID, $sessData) 93 | { 94 | return $this->handler->set($this->config['session_name'] . $sessID, $sessData, 0, $this->config['expire']); 95 | } 96 | 97 | /** 98 | * 删除Session 99 | * @access public 100 | * @param string $sessID 101 | * @return bool 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 | * @return true 113 | */ 114 | public function gc($sessMaxLifeTime) 115 | { 116 | return true; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /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' => 11211, // memcache端口 23 | 'expire' => 3600, // session有效期 24 | 'timeout' => 0, // 连接超时时间(单位:毫秒) 25 | 'session_name' => '', // memcache key前缀 26 | 'username' => '', //账号 27 | 'password' => '', //密码 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('memcached')) { 45 | throw new Exception('not support:memcached'); 46 | } 47 | $this->handler = new \Memcached; 48 | // 设置连接超时时间(单位:毫秒) 49 | if ($this->config['timeout'] > 0) { 50 | $this->handler->setOption(\Memcached::OPT_CONNECT_TIMEOUT, $this->config['timeout']); 51 | } 52 | // 支持集群 53 | $hosts = explode(',', $this->config['host']); 54 | $ports = explode(',', $this->config['port']); 55 | if (empty($ports[0])) { 56 | $ports[0] = 11211; 57 | } 58 | // 建立连接 59 | $servers = []; 60 | foreach ((array) $hosts as $i => $host) { 61 | $servers[] = [$host, (isset($ports[$i]) ? $ports[$i] : $ports[0]), 1]; 62 | } 63 | $this->handler->addServers($servers); 64 | if ('' != $this->config['username']) { 65 | $this->handler->setOption(\Memcached::OPT_BINARY_PROTOCOL, true); 66 | $this->handler->setSaslAuthData($this->config['username'], $this->config['password']); 67 | } 68 | return true; 69 | } 70 | 71 | /** 72 | * 关闭Session 73 | * @access public 74 | */ 75 | public function close() 76 | { 77 | $this->gc(ini_get('session.gc_maxlifetime')); 78 | $this->handler->quit(); 79 | $this->handler = null; 80 | return true; 81 | } 82 | 83 | /** 84 | * 读取Session 85 | * @access public 86 | * @param string $sessID 87 | */ 88 | public function read($sessID) 89 | { 90 | return (string) $this->handler->get($this->config['session_name'] . $sessID); 91 | } 92 | 93 | /** 94 | * 写入Session 95 | * @access public 96 | * @param string $sessID 97 | * @param String $sessData 98 | * @return bool 99 | */ 100 | public function write($sessID, $sessData) 101 | { 102 | return $this->handler->set($this->config['session_name'] . $sessID, $sessData, $this->config['expire']); 103 | } 104 | 105 | /** 106 | * 删除Session 107 | * @access public 108 | * @param string $sessID 109 | * @return bool 110 | */ 111 | public function destroy($sessID) 112 | { 113 | return $this->handler->delete($this->config['session_name'] . $sessID); 114 | } 115 | 116 | /** 117 | * Session 垃圾回收 118 | * @access public 119 | * @param string $sessMaxLifeTime 120 | * @return true 121 | */ 122 | public function gc($sessMaxLifeTime) 123 | { 124 | return true; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /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 | /** @var \Redis */ 20 | protected $handler = null; 21 | protected $config = [ 22 | 'host' => '127.0.0.1', // redis主机 23 | 'port' => 6379, // redis端口 24 | 'password' => '', // 密码 25 | 'select' => 0, // 操作库 26 | 'expire' => 3600, // 有效期(秒) 27 | 'timeout' => 0, // 超时时间(秒) 28 | 'persistent' => true, // 是否长连接 29 | 'session_name' => '', // sessionkey前缀 30 | ]; 31 | 32 | public function __construct($config = []) 33 | { 34 | $this->config = array_merge($this->config, $config); 35 | } 36 | 37 | /** 38 | * 打开Session 39 | * @access public 40 | * @param string $savePath 41 | * @param mixed $sessName 42 | * @return bool 43 | * @throws Exception 44 | */ 45 | public function open($savePath, $sessName) 46 | { 47 | // 检测php环境 48 | if (!extension_loaded('redis')) { 49 | throw new Exception('not support:redis'); 50 | } 51 | $this->handler = new \Redis; 52 | 53 | // 建立连接 54 | $func = $this->config['persistent'] ? 'pconnect' : 'connect'; 55 | $this->handler->$func($this->config['host'], $this->config['port'], $this->config['timeout']); 56 | 57 | if ('' != $this->config['password']) { 58 | $this->handler->auth($this->config['password']); 59 | } 60 | 61 | if (0 != $this->config['select']) { 62 | $this->handler->select($this->config['select']); 63 | } 64 | 65 | return true; 66 | } 67 | 68 | /** 69 | * 关闭Session 70 | * @access public 71 | */ 72 | public function close() 73 | { 74 | $this->gc(ini_get('session.gc_maxlifetime')); 75 | $this->handler->close(); 76 | $this->handler = null; 77 | return true; 78 | } 79 | 80 | /** 81 | * 读取Session 82 | * @access public 83 | * @param string $sessID 84 | * @return string 85 | */ 86 | public function read($sessID) 87 | { 88 | return (string) $this->handler->get($this->config['session_name'] . $sessID); 89 | } 90 | 91 | /** 92 | * 写入Session 93 | * @access public 94 | * @param string $sessID 95 | * @param String $sessData 96 | * @return bool 97 | */ 98 | public function write($sessID, $sessData) 99 | { 100 | if ($this->config['expire'] > 0) { 101 | return $this->handler->setex($this->config['session_name'] . $sessID, $this->config['expire'], $sessData); 102 | } else { 103 | return $this->handler->set($this->config['session_name'] . $sessID, $sessData); 104 | } 105 | } 106 | 107 | /** 108 | * 删除Session 109 | * @access public 110 | * @param string $sessID 111 | * @return bool 112 | */ 113 | public function destroy($sessID) 114 | { 115 | return $this->handler->delete($this->config['session_name'] . $sessID) > 0; 116 | } 117 | 118 | /** 119 | * Session 垃圾回收 120 | * @access public 121 | * @param string $sessMaxLifeTime 122 | * @return bool 123 | */ 124 | public function gc($sessMaxLifeTime) 125 | { 126 | return true; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /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 | * 写入编译缓存 20 | * @param string $cacheFile 缓存的文件名 21 | * @param string $content 缓存的内容 22 | * @return void|array 23 | */ 24 | public function write($cacheFile, $content) 25 | { 26 | // 检测模板目录 27 | $dir = dirname($cacheFile); 28 | if (!is_dir($dir)) { 29 | mkdir($dir, 0755, true); 30 | } 31 | // 生成模板缓存文件 32 | if (false === file_put_contents($cacheFile, $content)) { 33 | throw new Exception('cache write error:' . $cacheFile, 11602); 34 | } 35 | } 36 | 37 | /** 38 | * 读取编译编译 39 | * @param string $cacheFile 缓存的文件名 40 | * @param array $vars 变量数组 41 | * @return void 42 | */ 43 | public function read($cacheFile, $vars = []) 44 | { 45 | if (!empty($vars) && is_array($vars)) { 46 | // 模板阵列变量分解成为独立变量 47 | extract($vars, EXTR_OVERWRITE); 48 | } 49 | //载入模版缓存文件 50 | include $cacheFile; 51 | } 52 | 53 | /** 54 | * 检查编译缓存是否有效 55 | * @param string $cacheFile 缓存的文件名 56 | * @param int $cacheTime 缓存时间 57 | * @return boolean 58 | */ 59 | public function check($cacheFile, $cacheTime) 60 | { 61 | // 缓存文件不存在, 直接返回false 62 | if (!file_exists($cacheFile)) { 63 | return false; 64 | } 65 | if (0 != $cacheTime && $_SERVER['REQUEST_TIME'] > filemtime($cacheFile) + $cacheTime) { 66 | // 缓存是否在有效期 67 | return false; 68 | } 69 | return true; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /thinkphp/library/traits/model/SoftDelete.php: -------------------------------------------------------------------------------- 1 | getDeleteTimeField(); 18 | if (!empty($this->data[$field])) { 19 | return true; 20 | } 21 | return false; 22 | } 23 | 24 | /** 25 | * 查询软删除数据 26 | * @access public 27 | * @return Query 28 | */ 29 | public static function withTrashed() 30 | { 31 | $model = new static(); 32 | $field = $model->getDeleteTimeField(true); 33 | return $model->getQuery(); 34 | } 35 | 36 | /** 37 | * 只查询软删除数据 38 | * @access public 39 | * @return Query 40 | */ 41 | public static function onlyTrashed() 42 | { 43 | $model = new static(); 44 | $field = $model->getDeleteTimeField(true); 45 | return $model->getQuery() 46 | ->useSoftDelete($field, ['not null', '']); 47 | } 48 | 49 | /** 50 | * 删除当前的记录 51 | * @access public 52 | * @param bool $force 是否强制删除 53 | * @return integer 54 | */ 55 | public function delete($force = false) 56 | { 57 | if (false === $this->trigger('before_delete', $this)) { 58 | return false; 59 | } 60 | $name = $this->getDeleteTimeField(); 61 | if (!$force) { 62 | // 软删除 63 | $this->data[$name] = $this->autoWriteTimestamp($name); 64 | $result = $this->isUpdate()->save(); 65 | } else { 66 | // 删除条件 67 | $where = $this->getWhere(); 68 | // 删除当前模型数据 69 | $result = $this->getQuery()->where($where)->delete(); 70 | } 71 | 72 | // 关联删除 73 | if (!empty($this->relationWrite)) { 74 | foreach ($this->relationWrite as $key => $name) { 75 | $name = is_numeric($key) ? $name : $key; 76 | $model = $this->getAttr($name); 77 | if ($model instanceof Model) { 78 | $model->delete($force); 79 | } 80 | } 81 | } 82 | 83 | $this->trigger('after_delete', $this); 84 | // 清空原始数据 85 | $this->origin = []; 86 | return $result; 87 | } 88 | 89 | /** 90 | * 删除记录 91 | * @access public 92 | * @param mixed $data 主键列表 支持闭包查询条件 93 | * @param bool $force 是否强制删除 94 | * @return integer 成功删除的记录数 95 | */ 96 | public static function destroy($data, $force = false) 97 | { 98 | // 包含软删除数据 99 | $query = self::withTrashed(); 100 | if (is_array($data) && key($data) !== 0) { 101 | $query->where($data); 102 | $data = null; 103 | } elseif ($data instanceof \Closure) { 104 | call_user_func_array($data, [ & $query]); 105 | $data = null; 106 | } elseif (is_null($data)) { 107 | return 0; 108 | } 109 | 110 | $resultSet = $query->select($data); 111 | $count = 0; 112 | if ($resultSet) { 113 | foreach ($resultSet as $data) { 114 | $result = $data->delete($force); 115 | $count += $result; 116 | } 117 | } 118 | return $count; 119 | } 120 | 121 | /** 122 | * 恢复被软删除的记录 123 | * @access public 124 | * @param array $where 更新条件 125 | * @return integer 126 | */ 127 | public function restore($where = []) 128 | { 129 | $name = $this->getDeleteTimeField(); 130 | if (empty($where)) { 131 | $pk = $this->getPk(); 132 | $where[$pk] = $this->getData($pk); 133 | } 134 | // 恢复删除 135 | return $this->getQuery() 136 | ->useSoftDelete($name, ['not null', '']) 137 | ->where($where) 138 | ->update([$name => null]); 139 | } 140 | 141 | /** 142 | * 查询默认不包含软删除数据 143 | * @access protected 144 | * @param Query $query 查询对象 145 | * @return void 146 | */ 147 | protected function base($query) 148 | { 149 | $field = $this->getDeleteTimeField(true); 150 | $query->useSoftDelete($field); 151 | } 152 | 153 | /** 154 | * 获取软删除字段 155 | * @access public 156 | * @param bool $read 是否查询操作 写操作的时候会自动去掉表别名 157 | * @return string 158 | */ 159 | protected function getDeleteTimeField($read = false) 160 | { 161 | $field = property_exists($this, 'deleteTime') && isset($this->deleteTime) ? $this->deleteTime : 'delete_time'; 162 | if (!strpos($field, '.')) { 163 | $field = '__TABLE__.' . $field; 164 | } 165 | if (!$read && strpos($field, '.')) { 166 | $array = explode('.', $field); 167 | $field = array_pop($array); 168 | } 169 | return $field; 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /thinkphp/library/traits/think/Instance.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace traits\think; 13 | 14 | use think\Exception; 15 | 16 | trait Instance 17 | { 18 | protected static $instance = null; 19 | 20 | /** 21 | * @param array $options 22 | * @return static 23 | */ 24 | public static function instance($options = []) 25 | { 26 | if (is_null(self::$instance)) { 27 | self::$instance = new self($options); 28 | } 29 | return self::$instance; 30 | } 31 | 32 | // 静态调用 33 | public static function __callStatic($method, $params) 34 | { 35 | if (is_null(self::$instance)) { 36 | self::$instance = new self(); 37 | } 38 | $call = substr($method, 1); 39 | if (0 === strpos($method, '_') && is_callable([self::$instance, $call])) { 40 | return call_user_func_array([self::$instance, $call], $params); 41 | } else { 42 | throw new Exception("method not exists:" . $method); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /thinkphp/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rainweb521/Face-recognition-access-control/ad563f97765e23e4b82c47865b28de958b6d67e0/thinkphp/logo.png -------------------------------------------------------------------------------- /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 | // 执行应用 18 | App::run()->send(); 19 | -------------------------------------------------------------------------------- /thinkphp/tpl/default_index.tpl: -------------------------------------------------------------------------------- 1 | *{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }

:)

ThinkPHP V5
十年磨一剑 - 为API开发设计的高性能框架

[ V5.0 版本由 七牛云 独家赞助发布 ]
'; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /thinkphp/tpl/dispatch_jump.tpl: -------------------------------------------------------------------------------- 1 | {__NOLAYOUT__} 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 | -------------------------------------------------------------------------------- /vendor/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore --------------------------------------------------------------------------------