├── thinkphp ├── .htaccess ├── logo.png ├── library │ └── think │ │ ├── console │ │ ├── bin │ │ │ ├── hiddeninput.exe │ │ │ └── README.md │ │ ├── command │ │ │ ├── make │ │ │ │ ├── stubs │ │ │ │ │ ├── model.stub │ │ │ │ │ ├── controller.plain.stub │ │ │ │ │ ├── middleware.stub │ │ │ │ │ ├── validate.stub │ │ │ │ │ ├── command.stub │ │ │ │ │ ├── controller.api.stub │ │ │ │ │ └── controller.stub │ │ │ │ ├── Model.php │ │ │ │ ├── Middleware.php │ │ │ │ ├── Validate.php │ │ │ │ ├── Command.php │ │ │ │ └── Controller.php │ │ │ ├── Version.php │ │ │ ├── Build.php │ │ │ ├── RunServer.php │ │ │ ├── Help.php │ │ │ ├── Lists.php │ │ │ ├── optimize │ │ │ │ └── Route.php │ │ │ ├── Clear.php │ │ │ └── Make.php │ │ ├── LICENSE │ │ ├── output │ │ │ ├── driver │ │ │ │ ├── Nothing.php │ │ │ │ └── Buffer.php │ │ │ ├── question │ │ │ │ └── Confirmation.php │ │ │ └── formatter │ │ │ │ └── Stack.php │ │ └── input │ │ │ └── Argument.php │ │ ├── route │ │ └── dispatch │ │ │ ├── Response.php │ │ │ ├── Redirect.php │ │ │ ├── Callback.php │ │ │ ├── View.php │ │ │ └── Controller.php │ │ ├── exception │ │ ├── RouteNotFoundException.php │ │ ├── HttpResponseException.php │ │ ├── ClassNotFoundException.php │ │ ├── TemplateNotFoundException.php │ │ ├── ValidateException.php │ │ ├── HttpException.php │ │ ├── DbException.php │ │ ├── PDOException.php │ │ ├── ThrowableError.php │ │ └── ErrorException.php │ │ ├── config │ │ └── driver │ │ │ ├── Json.php │ │ │ ├── Ini.php │ │ │ └── Xml.php │ │ ├── response │ │ ├── Jump.php │ │ ├── Json.php │ │ ├── Jsonp.php │ │ ├── View.php │ │ ├── Redirect.php │ │ └── Xml.php │ │ ├── facade │ │ ├── Url.php │ │ ├── Env.php │ │ ├── Build.php │ │ ├── Config.php │ │ ├── Middleware.php │ │ ├── Template.php │ │ ├── Hook.php │ │ ├── Cookie.php │ │ ├── Lang.php │ │ ├── View.php │ │ ├── Debug.php │ │ ├── Cache.php │ │ ├── Session.php │ │ ├── Response.php │ │ ├── Log.php │ │ ├── App.php │ │ └── Route.php │ │ ├── db │ │ ├── Expression.php │ │ ├── exception │ │ │ ├── BindParamException.php │ │ │ ├── ModelNotFoundException.php │ │ │ └── DataNotFoundException.php │ │ ├── builder │ │ │ ├── Sqlite.php │ │ │ └── Pgsql.php │ │ └── connector │ │ │ ├── Sqlite.php │ │ │ └── Pgsql.php │ │ ├── model │ │ ├── Pivot.php │ │ ├── concern │ │ │ └── TimeStamp.php │ │ └── Collection.php │ │ ├── process │ │ ├── exception │ │ │ ├── Faild.php │ │ │ ├── Failed.php │ │ │ └── Timeout.php │ │ ├── Utils.php │ │ └── pipes │ │ │ └── Pipes.php │ │ ├── Exception.php │ │ ├── template │ │ └── driver │ │ │ └── File.php │ │ ├── Env.php │ │ ├── Cache.php │ │ ├── Facade.php │ │ └── session │ │ └── driver │ │ └── Memcache.php ├── tpl │ ├── default_index.tpl │ └── dispatch_jump.tpl ├── composer.json ├── LICENSE.txt ├── phpunit.xml.dist ├── base.php ├── README.md └── CONTRIBUTING.md ├── application ├── .htaccess ├── common.php ├── command.php ├── provider.php ├── tags.php └── util │ └── SougouApi.php ├── extend └── .gitignore ├── runtime └── .gitignore ├── public ├── static │ └── .gitignore ├── robots.txt ├── favicon.ico ├── .htaccess ├── router.php ├── index.php └── cover.css ├── .gitignore ├── composer.json ├── route └── route.php ├── think ├── config ├── trace.php ├── middleware.php ├── console.php ├── cache.php ├── session.php ├── cookie.php ├── log.php ├── template.php └── database.php ├── LICENSE.txt ├── .travis.yml └── README.md /thinkphp/.htaccess: -------------------------------------------------------------------------------- 1 | deny from all -------------------------------------------------------------------------------- /application/.htaccess: -------------------------------------------------------------------------------- 1 | deny from all -------------------------------------------------------------------------------- /extend/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /runtime/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /public/static/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | /.vscode 3 | /vendor 4 | *.log 5 | .env 6 | .DS_Store 7 | -------------------------------------------------------------------------------- /thinkphp/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/szvone/imgApi/HEAD/thinkphp/logo.png -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/szvone/imgApi/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /thinkphp/library/think/console/bin/hiddeninput.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/szvone/imgApi/HEAD/thinkphp/library/think/console/bin/hiddeninput.exe -------------------------------------------------------------------------------- /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/command/make/stubs/model.stub: -------------------------------------------------------------------------------- 1 | 2 | RewriteEngine on 3 | RewriteCond %{REQUEST_FILENAME} !-d 4 | RewriteCond %{REQUEST_FILENAME} !-f 5 | RewriteRule ^(.*)$ index.php?s=$1 [QSA,PT,L] 6 | RewriteRule uploads/(.*).(php)$ – [F] 7 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/make/stubs/validate.stub: -------------------------------------------------------------------------------- 1 | ['规则1','规则2'...] 12 | * 13 | * @var array 14 | */ 15 | protected $rule = []; 16 | 17 | /** 18 | * 定义错误信息 19 | * 格式:'字段名.规则名' => '错误信息' 20 | * 21 | * @var array 22 | */ 23 | protected $message = []; 24 | } 25 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/make/stubs/command.stub: -------------------------------------------------------------------------------- 1 | setName('{%commandName%}'); 15 | // 设置参数 16 | 17 | } 18 | 19 | protected function execute(Input $input, Output $output) 20 | { 21 | // 指令输出 22 | $output->writeln('{%commandName%}'); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /application/common.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | // 应用公共文件 13 | -------------------------------------------------------------------------------- /application/command.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | return []; 13 | -------------------------------------------------------------------------------- /application/provider.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | // 应用容器绑定定义 13 | return [ 14 | ]; 15 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "topthink/think", 3 | "description": "the new thinkphp framework", 4 | "type": "project", 5 | "keywords": [ 6 | "framework", 7 | "thinkphp", 8 | "ORM" 9 | ], 10 | "homepage": "http://thinkphp.cn/", 11 | "license": "Apache-2.0", 12 | "authors": [ 13 | { 14 | "name": "liu21st", 15 | "email": "liu21st@gmail.com" 16 | } 17 | ], 18 | "require": { 19 | "php": ">=5.6.0", 20 | "topthink/framework": "5.1.*" 21 | }, 22 | "autoload": { 23 | "psr-4": { 24 | "app\\": "application" 25 | } 26 | }, 27 | "extra": { 28 | "think-path": "thinkphp" 29 | }, 30 | "config": { 31 | "preferred-install": "dist" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /public/router.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | // $Id$ 12 | 13 | if (is_file($_SERVER["DOCUMENT_ROOT"] . $_SERVER["SCRIPT_NAME"])) { 14 | return false; 15 | } else { 16 | require __DIR__ . "/index.php"; 17 | } 18 | -------------------------------------------------------------------------------- /route/route.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | Route::get('think', function () { 13 | return 'hello,ThinkPHP5!'; 14 | }); 15 | 16 | Route::get('hello/:name', 'index/hello'); 17 | 18 | Route::rule('api', 'index/upImg'); 19 | 20 | return [ 21 | 22 | ]; 23 | -------------------------------------------------------------------------------- /think: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | 11 | // +---------------------------------------------------------------------- 12 | 13 | namespace think; 14 | 15 | // 加载基础文件 16 | require __DIR__ . '/thinkphp/base.php'; 17 | 18 | // 应用初始化 19 | Container::get('app')->path(__DIR__ . '/application/')->initialize(); 20 | 21 | // 控制台初始化 22 | Console::init(); -------------------------------------------------------------------------------- /thinkphp/library/think/route/dispatch/Response.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\route\dispatch; 13 | 14 | use think\route\Dispatch; 15 | 16 | class Response extends Dispatch 17 | { 18 | public function exec() 19 | { 20 | return $this->dispatch; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /config/trace.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | // +---------------------------------------------------------------------- 13 | // | Trace设置 开启 app_trace 后 有效 14 | // +---------------------------------------------------------------------- 15 | return [ 16 | // 内置Html Console 支持扩展 17 | 'type' => 'Html', 18 | ]; 19 | -------------------------------------------------------------------------------- /config/middleware.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | // +---------------------------------------------------------------------- 13 | // | 中间件配置 14 | // +---------------------------------------------------------------------- 15 | return [ 16 | // 默认中间件命名空间 17 | 'default_namespace' => 'app\\http\\middleware\\', 18 | ]; 19 | -------------------------------------------------------------------------------- /thinkphp/library/think/exception/RouteNotFoundException.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\exception; 13 | 14 | class RouteNotFoundException extends HttpException 15 | { 16 | 17 | public function __construct() 18 | { 19 | parent::__construct(404, 'Route Not Found'); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /public/index.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | // [ 应用入口文件 ] 13 | namespace think; 14 | 15 | // 加载基础文件 16 | require __DIR__ . '/../thinkphp/base.php'; 17 | 18 | // 支持事先使用静态方法设置Request对象和Config对象 19 | 20 | // 定义应用目录 21 | define('ROOT_PATH', str_replace("\\","/",__DIR__ )); 22 | 23 | // 执行应用并响应 24 | Container::get('app')->run()->send(); 25 | 26 | -------------------------------------------------------------------------------- /thinkphp/tpl/default_index.tpl: -------------------------------------------------------------------------------- 1 | *{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }

:)

ThinkPHP V5.1
12载初心不改(2006-2018) - 你值得信赖的PHP框架

'; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /thinkphp/library/think/route/dispatch/Redirect.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\route\dispatch; 13 | 14 | use think\Response; 15 | use think\route\Dispatch; 16 | 17 | class Redirect extends Dispatch 18 | { 19 | public function exec() 20 | { 21 | return Response::create($this->dispatch, 'redirect')->code($this->code); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /config/console.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | // +---------------------------------------------------------------------- 13 | // | 控制台配置 14 | // +---------------------------------------------------------------------- 15 | return [ 16 | 'name' => 'Think Console', 17 | 'version' => '0.1', 18 | 'user' => null, 19 | 'auto_path' => env('app_path') . 'command' . DIRECTORY_SEPARATOR, 20 | ]; 21 | -------------------------------------------------------------------------------- /config/cache.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | // +---------------------------------------------------------------------- 13 | // | 缓存设置 14 | // +---------------------------------------------------------------------- 15 | 16 | return [ 17 | // 驱动方式 18 | 'type' => 'File', 19 | // 缓存保存目录 20 | 'path' => '', 21 | // 缓存前缀 22 | 'prefix' => '', 23 | // 缓存有效期 0表示永久缓存 24 | 'expire' => 0, 25 | ]; 26 | -------------------------------------------------------------------------------- /application/tags.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | // 应用行为扩展定义文件 13 | return [ 14 | // 应用初始化 15 | 'app_init' => [], 16 | // 应用开始 17 | 'app_begin' => [], 18 | // 模块初始化 19 | 'module_init' => [], 20 | // 操作开始执行 21 | 'action_begin' => [], 22 | // 视图内容过滤 23 | 'view_filter' => [], 24 | // 日志写入 25 | 'log_write' => [], 26 | // 应用结束 27 | 'app_end' => [], 28 | ]; 29 | -------------------------------------------------------------------------------- /thinkphp/library/think/route/dispatch/Callback.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\route\dispatch; 13 | 14 | use think\route\Dispatch; 15 | 16 | class Callback extends Dispatch 17 | { 18 | public function exec() 19 | { 20 | // 执行回调方法 21 | $vars = array_merge($this->request->param(), $this->param); 22 | 23 | return $this->app->invoke($this->dispatch, $vars); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /thinkphp/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "topthink/framework", 3 | "description": "the new thinkphp framework", 4 | "type": "think-framework", 5 | "keywords": [ 6 | "framework", 7 | "thinkphp", 8 | "ORM" 9 | ], 10 | "homepage": "http://thinkphp.cn/", 11 | "license": "Apache-2.0", 12 | "authors": [ 13 | { 14 | "name": "liu21st", 15 | "email": "liu21st@gmail.com" 16 | }, 17 | { 18 | "name": "yunwuxin", 19 | "email": "448901948@qq.com" 20 | } 21 | ], 22 | "require": { 23 | "php": ">=5.6.0", 24 | "topthink/think-installer": "2.*" 25 | }, 26 | "require-dev": { 27 | "phpunit/phpunit": "^5.0|^6.0", 28 | "johnkary/phpunit-speedtrap": "^1.0", 29 | "mikey179/vfsStream": "~1.6", 30 | "phploc/phploc": "2.*", 31 | "sebastian/phpcpd": "2.*", 32 | "squizlabs/php_codesniffer": "2.*", 33 | "phpdocumentor/reflection-docblock": "^2.0" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /thinkphp/library/think/route/dispatch/View.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\route\dispatch; 13 | 14 | use think\Response; 15 | use think\route\Dispatch; 16 | 17 | class View extends Dispatch 18 | { 19 | public function exec() 20 | { 21 | // 渲染模板输出 22 | $vars = array_merge($this->request->param(), $this->param); 23 | 24 | return Response::create($this->dispatch, 'view')->assign($vars); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /thinkphp/library/think/config/driver/Json.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\config\driver; 13 | 14 | class Json 15 | { 16 | protected $config; 17 | 18 | public function __construct($config) 19 | { 20 | if (is_file($config)) { 21 | $config = file_get_contents($config); 22 | } 23 | 24 | $this->config = $config; 25 | } 26 | 27 | public function parse() 28 | { 29 | return json_decode($this->config, true); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /thinkphp/library/think/config/driver/Ini.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\config\driver; 13 | 14 | class Ini 15 | { 16 | protected $config; 17 | 18 | public function __construct($config) 19 | { 20 | $this->config = $config; 21 | } 22 | 23 | public function parse() 24 | { 25 | if (is_file($this->config)) { 26 | return parse_ini_file($this->config, true); 27 | } else { 28 | return parse_ini_string($this->config, true); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /thinkphp/library/think/exception/HttpResponseException.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\exception; 13 | 14 | use think\Response; 15 | 16 | class HttpResponseException extends \RuntimeException 17 | { 18 | /** 19 | * @var Response 20 | */ 21 | protected $response; 22 | 23 | public function __construct(Response $response) 24 | { 25 | $this->response = $response; 26 | } 27 | 28 | public function getResponse() 29 | { 30 | return $this->response; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /config/session.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | // +---------------------------------------------------------------------- 13 | // | 会话设置 14 | // +---------------------------------------------------------------------- 15 | 16 | return [ 17 | 'id' => '', 18 | // SESSION_ID的提交变量,解决flash上传跨域 19 | 'var_session_id' => '', 20 | // SESSION 前缀 21 | 'prefix' => 'think', 22 | // 驱动方式 支持redis memcache memcached 23 | 'type' => '', 24 | // 是否自动开启 SESSION 25 | 'auto_start' => true, 26 | ]; 27 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2004-2016 Fabien Potencier 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /thinkphp/library/think/console/output/driver/Nothing.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\output\driver; 13 | 14 | use think\console\Output; 15 | 16 | class Nothing 17 | { 18 | 19 | public function __construct(Output $output) 20 | { 21 | // do nothing 22 | } 23 | 24 | public function write($messages, $newline = false, $options = Output::OUTPUT_NORMAL) 25 | { 26 | // do nothing 27 | } 28 | 29 | public function renderException(\Exception $e) 30 | { 31 | // do nothing 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /thinkphp/library/think/exception/ClassNotFoundException.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\exception; 13 | 14 | class ClassNotFoundException extends \RuntimeException 15 | { 16 | protected $class; 17 | public function __construct($message, $class = '') 18 | { 19 | $this->message = $message; 20 | $this->class = $class; 21 | } 22 | 23 | /** 24 | * 获取类名 25 | * @access public 26 | * @return string 27 | */ 28 | public function getClass() 29 | { 30 | return $this->class; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /thinkphp/library/think/response/Jump.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\response; 13 | 14 | use think\Response; 15 | 16 | class Jump extends Response 17 | { 18 | protected $contentType = 'text/html'; 19 | 20 | /** 21 | * 处理数据 22 | * @access protected 23 | * @param mixed $data 要处理的数据 24 | * @return mixed 25 | * @throws \Exception 26 | */ 27 | protected function output($data) 28 | { 29 | $data = $this->app['view']->fetch($this->options['jump_template'], $data); 30 | return $data; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /thinkphp/library/think/route/dispatch/Controller.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\route\dispatch; 13 | 14 | use think\route\Dispatch; 15 | 16 | class Controller extends Dispatch 17 | { 18 | public function exec() 19 | { 20 | // 执行控制器的操作方法 21 | $vars = array_merge($this->request->param(), $this->param); 22 | 23 | return $this->app->action( 24 | $this->dispatch, $vars, 25 | $this->rule->getConfig('url_controller_layer'), 26 | $this->rule->getConfig('controller_suffix') 27 | ); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /thinkphp/library/think/exception/TemplateNotFoundException.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\exception; 13 | 14 | class TemplateNotFoundException extends \RuntimeException 15 | { 16 | protected $template; 17 | 18 | public function __construct($message, $template = '') 19 | { 20 | $this->message = $message; 21 | $this->template = $template; 22 | } 23 | 24 | /** 25 | * 获取模板文件 26 | * @access public 27 | * @return string 28 | */ 29 | public function getTemplate() 30 | { 31 | return $this->template; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /config/cookie.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | // +---------------------------------------------------------------------- 13 | // | Cookie设置 14 | // +---------------------------------------------------------------------- 15 | return [ 16 | // cookie 名称前缀 17 | 'prefix' => '', 18 | // cookie 保存时间 19 | 'expire' => 0, 20 | // cookie 保存路径 21 | 'path' => '/', 22 | // cookie 有效域名 23 | 'domain' => '', 24 | // cookie 启用安全传输 25 | 'secure' => false, 26 | // httponly设置 27 | 'httponly' => '', 28 | // 是否使用 setcookie 29 | 'setcookie' => true, 30 | ]; 31 | -------------------------------------------------------------------------------- /config/log.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | // +---------------------------------------------------------------------- 13 | // | 日志设置 14 | // +---------------------------------------------------------------------- 15 | return [ 16 | // 日志记录方式,内置 file socket 支持扩展 17 | 'type' => 'File', 18 | // 日志保存目录 19 | 'path' => '', 20 | // 日志记录级别 21 | 'level' => [], 22 | // 单文件日志写入 23 | 'single' => false, 24 | // 独立日志级别 25 | 'apart_level' => [], 26 | // 最大日志文件数量 27 | 'max_files' => 0, 28 | // 是否关闭日志写入 29 | 'close' => false, 30 | ]; 31 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/Version.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | namespace think\console\command; 12 | 13 | use think\console\Command; 14 | use think\console\Input; 15 | use think\console\Output; 16 | use think\facade\App; 17 | 18 | class Version extends Command 19 | { 20 | protected function configure() 21 | { 22 | // 指令配置 23 | $this->setName('version') 24 | ->setDescription('show thinkphp framework version'); 25 | } 26 | 27 | protected function execute(Input $input, Output $output) 28 | { 29 | $output->writeln('v' . App::version()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /thinkphp/library/think/facade/Url.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\facade; 13 | 14 | use think\Facade; 15 | 16 | /** 17 | * @see \think\Url 18 | * @mixin \think\Url 19 | * @method string build(string $url = '', mixed $vars = '', mixed $suffix = true, mixed $domain = false) static URL生成 支持路由反射 20 | * @method void root(string $root) static 指定当前生成URL地址的root 21 | */ 22 | class Url extends Facade 23 | { 24 | /** 25 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识) 26 | * @access protected 27 | * @return string 28 | */ 29 | protected static function getFacadeClass() 30 | { 31 | return 'url'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /thinkphp/library/think/exception/ValidateException.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\exception; 13 | 14 | class ValidateException extends \RuntimeException 15 | { 16 | protected $error; 17 | 18 | public function __construct($error, $code = 0) 19 | { 20 | $this->error = $error; 21 | $this->message = is_array($error) ? implode("\n\r", $error) : $error; 22 | $this->code = $code; 23 | } 24 | 25 | /** 26 | * 获取验证错误信息 27 | * @access public 28 | * @return array|string 29 | */ 30 | public function getError() 31 | { 32 | return $this->error; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /thinkphp/library/think/facade/Env.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\facade; 13 | 14 | use think\Facade; 15 | 16 | /** 17 | * @see \think\Env 18 | * @mixin \think\Env 19 | * @method void load(string $file) static 读取环境变量定义文件 20 | * @method mixed get(string $name = null, mixed $default = null) static 获取环境变量值 21 | * @method void set(mixed $env, string $value = null) static 设置环境变量值 22 | */ 23 | class Env extends Facade 24 | { 25 | /** 26 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识) 27 | * @access protected 28 | * @return string 29 | */ 30 | protected static function getFacadeClass() 31 | { 32 | return 'env'; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /thinkphp/library/think/facade/Build.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\facade; 13 | 14 | use think\Facade; 15 | 16 | /** 17 | * @see \think\Build 18 | * @mixin \think\Build 19 | * @method void run(array $build = [], string $namespace = 'app', bool $suffix = false) static 根据传入的build资料创建目录和文件 20 | * @method void module(string $module = '', array $list = [], string $namespace = 'app', bool $suffix = false) static 创建模块 21 | */ 22 | class Build extends Facade 23 | { 24 | /** 25 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识) 26 | * @access protected 27 | * @return string 28 | */ 29 | protected static function getFacadeClass() 30 | { 31 | return 'build'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/make/stubs/controller.api.stub: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\db; 13 | 14 | class Expression 15 | { 16 | /** 17 | * 查询表达式 18 | * 19 | * @var string 20 | */ 21 | protected $value; 22 | 23 | /** 24 | * 创建一个查询表达式 25 | * 26 | * @param string $value 27 | * @return void 28 | */ 29 | public function __construct($value) 30 | { 31 | $this->value = $value; 32 | } 33 | 34 | /** 35 | * 获取表达式 36 | * 37 | * @return string 38 | */ 39 | public function getValue() 40 | { 41 | return $this->value; 42 | } 43 | 44 | public function __toString() 45 | { 46 | return (string) $this->value; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /thinkphp/library/think/exception/HttpException.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\exception; 13 | 14 | class HttpException extends \RuntimeException 15 | { 16 | private $statusCode; 17 | private $headers; 18 | 19 | public function __construct($statusCode, $message = null, \Exception $previous = null, array $headers = [], $code = 0) 20 | { 21 | $this->statusCode = $statusCode; 22 | $this->headers = $headers; 23 | 24 | parent::__construct($message, $code, $previous); 25 | } 26 | 27 | public function getStatusCode() 28 | { 29 | return $this->statusCode; 30 | } 31 | 32 | public function getHeaders() 33 | { 34 | return $this->headers; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/make/Model.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\command\make; 13 | 14 | use think\console\command\Make; 15 | 16 | class Model extends Make 17 | { 18 | protected $type = "Model"; 19 | 20 | protected function configure() 21 | { 22 | parent::configure(); 23 | $this->setName('make:model') 24 | ->setDescription('Create a new model class'); 25 | } 26 | 27 | protected function getStub() 28 | { 29 | return __DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'model.stub'; 30 | } 31 | 32 | protected function getNamespace($appNamespace, $module) 33 | { 34 | return parent::getNamespace($appNamespace, $module) . '\model'; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /thinkphp/library/think/db/exception/BindParamException.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\db\exception; 13 | 14 | use think\exception\DbException; 15 | 16 | /** 17 | * PDO参数绑定异常 18 | */ 19 | class BindParamException extends DbException 20 | { 21 | 22 | /** 23 | * BindParamException constructor. 24 | * @access public 25 | * @param string $message 26 | * @param array $config 27 | * @param string $sql 28 | * @param array $bind 29 | * @param int $code 30 | */ 31 | public function __construct($message, $config, $sql, $bind, $code = 10502) 32 | { 33 | $this->setData('Bind Param', $bind); 34 | parent::__construct($message, $config, $sql, $code); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /config/template.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | // +---------------------------------------------------------------------- 13 | // | 模板设置 14 | // +---------------------------------------------------------------------- 15 | 16 | return [ 17 | // 模板引擎类型 支持 php think 支持扩展 18 | 'type' => 'Think', 19 | // 默认模板渲染规则 1 解析为小写+下划线 2 全部转换小写 3 保持操作方法 20 | 'auto_rule' => 1, 21 | // 模板路径 22 | 'view_path' => '', 23 | // 模板后缀 24 | 'view_suffix' => 'html', 25 | // 模板文件名分隔符 26 | 'view_depr' => DIRECTORY_SEPARATOR, 27 | // 模板引擎普通标签开始标记 28 | 'tpl_begin' => '{', 29 | // 模板引擎普通标签结束标记 30 | 'tpl_end' => '}', 31 | // 标签库标签开始标记 32 | 'taglib_begin' => '{', 33 | // 标签库标签结束标记 34 | 'taglib_end' => '}', 35 | ]; 36 | -------------------------------------------------------------------------------- /thinkphp/library/think/model/Pivot.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\model; 13 | 14 | use think\Model; 15 | 16 | class Pivot extends Model 17 | { 18 | 19 | /** @var Model */ 20 | public $parent; 21 | 22 | protected $autoWriteTimestamp = false; 23 | 24 | /** 25 | * 架构函数 26 | * @access public 27 | * @param array|object $data 数据 28 | * @param Model $parent 上级模型 29 | * @param string $table 中间数据表名 30 | */ 31 | public function __construct($data = [], Model $parent = null, $table = '') 32 | { 33 | $this->parent = $parent; 34 | 35 | if (is_null($this->name)) { 36 | $this->name = $table; 37 | } 38 | 39 | parent::__construct($data); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /thinkphp/library/think/facade/Config.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\facade; 13 | 14 | use think\Facade; 15 | 16 | /** 17 | * @see \think\Config 18 | * @mixin \think\Config 19 | * @method bool has(string $name) static 检测配置是否存在 20 | * @method array pull(string $name) static 获取一级配置 21 | * @method mixed get(string $name,mixed $default = null) static 获取配置参数 22 | * @method mixed set(string $name, mixed $value = null) static 设置配置参数 23 | * @method array reset(string $prefix ='') static 重置配置参数 24 | */ 25 | class Config extends Facade 26 | { 27 | /** 28 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识) 29 | * @access protected 30 | * @return string 31 | */ 32 | protected static function getFacadeClass() 33 | { 34 | return 'config'; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /thinkphp/library/think/config/driver/Xml.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\config\driver; 13 | 14 | class Xml 15 | { 16 | protected $config; 17 | 18 | public function __construct($config) 19 | { 20 | $this->config = $config; 21 | } 22 | 23 | public function parse() 24 | { 25 | if (is_file($this->config)) { 26 | $content = simplexml_load_file($this->config); 27 | } else { 28 | $content = simplexml_load_string($this->config); 29 | } 30 | 31 | $result = (array) $content; 32 | foreach ($result as $key => $val) { 33 | if (is_object($val)) { 34 | $result[$key] = (array) $val; 35 | } 36 | } 37 | 38 | return $result; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | ThinkPHP遵循Apache2开源协议发布,并提供免费使用。 3 | 版权所有Copyright © 2006-2016 by ThinkPHP (http://thinkphp.cn) 4 | All rights reserved。 5 | ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。 6 | 7 | Apache Licence是著名的非盈利开源组织Apache采用的协议。 8 | 该协议和BSD类似,鼓励代码共享和尊重原作者的著作权, 9 | 允许代码修改,再作为开源或商业软件发布。需要满足 10 | 的条件: 11 | 1. 需要给代码的用户一份Apache Licence ; 12 | 2. 如果你修改了代码,需要在被修改的文件中说明; 13 | 3. 在延伸的代码中(修改和有源代码衍生的代码中)需要 14 | 带有原来代码中的协议,商标,专利声明和其他原来作者规 15 | 定需要包含的说明; 16 | 4. 如果再发布的产品中包含一个Notice文件,则在Notice文 17 | 件中需要带有本协议内容。你可以在Notice中增加自己的 18 | 许可,但不可以表现为对Apache Licence构成更改。 19 | 具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | POSSIBILITY OF SUCH DAMAGE. 33 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/make/Middleware.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\command\make; 13 | 14 | use think\console\command\Make; 15 | 16 | class Middleware extends Make 17 | { 18 | protected $type = "Middleware"; 19 | 20 | protected function configure() 21 | { 22 | parent::configure(); 23 | $this->setName('make:middleware') 24 | ->setDescription('Create a new middleware class'); 25 | } 26 | 27 | protected function getStub() 28 | { 29 | return __DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'middleware.stub'; 30 | } 31 | 32 | protected function getNamespace($appNamespace, $module) 33 | { 34 | return parent::getNamespace($appNamespace, 'http') . '\middleware'; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /thinkphp/library/think/facade/Middleware.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\facade; 13 | 14 | use think\Facade; 15 | 16 | /** 17 | * @see \think\Middleware 18 | * @mixin \think\Middleware 19 | * @method void import(array $middlewares = []) static 批量设置中间件 20 | * @method void add(mixed $middleware) static 添加中间件到队列 21 | * @method void unshift(mixed $middleware) static 添加中间件到队列开头 22 | * @method array all() static 获取中间件队列 23 | * @method \think\Response dispatch(\think\Request $request) static 执行中间件调度 24 | */ 25 | class Middleware extends Facade 26 | { 27 | /** 28 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识) 29 | * @access protected 30 | * @return string 31 | */ 32 | protected static function getFacadeClass() 33 | { 34 | return 'middleware'; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /thinkphp/LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | ThinkPHP遵循Apache2开源协议发布,并提供免费使用。 3 | 版权所有Copyright © 2006-2016 by ThinkPHP (http://thinkphp.cn) 4 | All rights reserved。 5 | ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。 6 | 7 | Apache Licence是著名的非盈利开源组织Apache采用的协议。 8 | 该协议和BSD类似,鼓励代码共享和尊重原作者的著作权, 9 | 允许代码修改,再作为开源或商业软件发布。需要满足 10 | 的条件: 11 | 1. 需要给代码的用户一份Apache Licence ; 12 | 2. 如果你修改了代码,需要在被修改的文件中说明; 13 | 3. 在延伸的代码中(修改和有源代码衍生的代码中)需要 14 | 带有原来代码中的协议,商标,专利声明和其他原来作者规 15 | 定需要包含的说明; 16 | 4. 如果再发布的产品中包含一个Notice文件,则在Notice文 17 | 件中需要带有本协议内容。你可以在Notice中增加自己的 18 | 许可,但不可以表现为对Apache Licence构成更改。 19 | 具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | POSSIBILITY OF SUCH DAMAGE. 33 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/make/Validate.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\command\make; 13 | 14 | use think\console\command\Make; 15 | 16 | class Validate extends Make 17 | { 18 | protected $type = "Validate"; 19 | 20 | protected function configure() 21 | { 22 | parent::configure(); 23 | $this->setName('make:validate') 24 | ->setDescription('Create a validate class'); 25 | } 26 | 27 | protected function getStub() 28 | { 29 | $stubPath = __DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR; 30 | 31 | return $stubPath . 'validate.stub'; 32 | } 33 | 34 | protected function getNamespace($appNamespace, $module) 35 | { 36 | return parent::getNamespace($appNamespace, $module) . '\validate'; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /thinkphp/library/think/facade/Template.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\facade; 13 | 14 | use think\Facade; 15 | 16 | /** 17 | * @see \think\Template 18 | * @mixin \think\Template 19 | * @method void assign(mixed $name, mixed $value = '') static 模板变量赋值 20 | * @method mixed get(string $name = '') static 获取模板变量 21 | * @method void fetch(string $template, array $vars = [], array $config = []) static 渲染模板文件 22 | * @method void display(string $content, array $vars = [], array $config = []) static 渲染模板内容 23 | * @method mixed layout(string $name, string $replace = '') static 设置模板布局 24 | */ 25 | class Template extends Facade 26 | { 27 | /** 28 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识) 29 | * @access protected 30 | * @return string 31 | */ 32 | protected static function getFacadeClass() 33 | { 34 | return 'template'; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /thinkphp/library/think/db/exception/ModelNotFoundException.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\db\exception; 13 | 14 | use think\exception\DbException; 15 | 16 | class ModelNotFoundException extends DbException 17 | { 18 | protected $model; 19 | 20 | /** 21 | * 构造方法 22 | * @access public 23 | * @param string $message 24 | * @param string $model 25 | * @param array $config 26 | */ 27 | public function __construct($message, $model = '', array $config = []) 28 | { 29 | $this->message = $message; 30 | $this->model = $model; 31 | 32 | $this->setData('Database Config', $config); 33 | } 34 | 35 | /** 36 | * 获取模型类名 37 | * @access public 38 | * @return string 39 | */ 40 | public function getModel() 41 | { 42 | return $this->model; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /thinkphp/library/think/db/exception/DataNotFoundException.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\db\exception; 13 | 14 | use think\exception\DbException; 15 | 16 | class DataNotFoundException extends DbException 17 | { 18 | protected $table; 19 | 20 | /** 21 | * DbException constructor. 22 | * @access public 23 | * @param string $message 24 | * @param string $table 25 | * @param array $config 26 | */ 27 | public function __construct($message, $table = '', array $config = []) 28 | { 29 | $this->message = $message; 30 | $this->table = $table; 31 | 32 | $this->setData('Database Config', $config); 33 | } 34 | 35 | /** 36 | * 获取数据表名 37 | * @access public 38 | * @return string 39 | */ 40 | public function getTable() 41 | { 42 | return $this->table; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /thinkphp/library/think/facade/Hook.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\facade; 13 | 14 | use think\Facade; 15 | 16 | /** 17 | * @see \think\Hook 18 | * @mixin \think\Hook 19 | * @method \think\Hook alias(mixed $name, mixed $behavior = null) static 指定行为标识 20 | * @method void add(string $tag, mixed $behavior, bool $first = false) static 动态添加行为扩展到某个标签 21 | * @method void import(array $tags, bool $recursive = true) static 批量导入插件 22 | * @method array get(string $tag = '') static 获取插件信息 23 | * @method mixed listen(string $tag, mixed $params = null, bool $once = false) static 监听标签的行为 24 | * @method mixed exec(mixed $class, mixed $params = null) static 执行行为 25 | */ 26 | class Hook extends Facade 27 | { 28 | /** 29 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识) 30 | * @access protected 31 | * @return string 32 | */ 33 | protected static function getFacadeClass() 34 | { 35 | return 'hook'; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /thinkphp/library/think/exception/DbException.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\exception; 13 | 14 | use think\Exception; 15 | 16 | /** 17 | * Database相关异常处理类 18 | */ 19 | class DbException extends Exception 20 | { 21 | /** 22 | * DbException constructor. 23 | * @access public 24 | * @param string $message 25 | * @param array $config 26 | * @param string $sql 27 | * @param int $code 28 | */ 29 | public function __construct($message, array $config, $sql, $code = 10500) 30 | { 31 | $this->message = $message; 32 | $this->code = $code; 33 | 34 | $this->setData('Database Status', [ 35 | 'Error Code' => $code, 36 | 'Error Message' => $message, 37 | 'Error SQL' => $sql, 38 | ]); 39 | 40 | unset($config['username'], $config['password']); 41 | $this->setData('Database Config', $config); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/output/driver/Buffer.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\output\driver; 13 | 14 | use think\console\Output; 15 | 16 | class Buffer 17 | { 18 | /** 19 | * @var string 20 | */ 21 | private $buffer = ''; 22 | 23 | public function __construct(Output $output) 24 | { 25 | // do nothing 26 | } 27 | 28 | public function fetch() 29 | { 30 | $content = $this->buffer; 31 | $this->buffer = ''; 32 | return $content; 33 | } 34 | 35 | public function write($messages, $newline = false, $options = Output::OUTPUT_NORMAL) 36 | { 37 | $messages = (array) $messages; 38 | 39 | foreach ($messages as $message) { 40 | $this->buffer .= $message; 41 | } 42 | if ($newline) { 43 | $this->buffer .= "\n"; 44 | } 45 | } 46 | 47 | public function renderException(\Exception $e) 48 | { 49 | // do nothing 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /thinkphp/library/think/exception/PDOException.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\exception; 13 | 14 | /** 15 | * PDO异常处理类 16 | * 重新封装了系统的\PDOException类 17 | */ 18 | class PDOException extends DbException 19 | { 20 | /** 21 | * PDOException constructor. 22 | * @access public 23 | * @param \PDOException $exception 24 | * @param array $config 25 | * @param string $sql 26 | * @param int $code 27 | */ 28 | public function __construct(\PDOException $exception, array $config, $sql, $code = 10501) 29 | { 30 | $error = $exception->errorInfo; 31 | 32 | $this->setData('PDO Error Info', [ 33 | 'SQLSTATE' => $error[0], 34 | 'Driver Error Code' => isset($error[1]) ? $error[1] : 0, 35 | 'Driver Error Message' => isset($error[2]) ? $error[2] : '', 36 | ]); 37 | 38 | parent::__construct($exception->getMessage(), $config, $sql, $code); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /thinkphp/phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | ./library/think/*/tests/ 27 | 28 | 29 | 30 | 31 | 32 | ./library/ 33 | 34 | ./library/think/*/tests 35 | ./library/think/*/assets 36 | ./library/think/*/resources 37 | ./library/think/*/vendor 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /thinkphp/library/think/process/exception/Faild.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\process\exception; 13 | 14 | use think\Process; 15 | 16 | class Faild extends \RuntimeException 17 | { 18 | 19 | private $process; 20 | 21 | public function __construct(Process $process) 22 | { 23 | if ($process->isSuccessful()) { 24 | throw new \InvalidArgumentException('Expected a failed process, but the given process was successful.'); 25 | } 26 | 27 | $error = sprintf('The command "%s" failed.' . "\nExit Code: %s(%s)", $process->getCommandLine(), $process->getExitCode(), $process->getExitCodeText()); 28 | 29 | if (!$process->isOutputDisabled()) { 30 | $error .= sprintf("\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s", $process->getOutput(), $process->getErrorOutput()); 31 | } 32 | 33 | parent::__construct($error); 34 | 35 | $this->process = $process; 36 | } 37 | 38 | public function getProcess() 39 | { 40 | return $this->process; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /thinkphp/library/think/process/exception/Failed.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\process\exception; 13 | 14 | use think\Process; 15 | 16 | class Failed extends \RuntimeException 17 | { 18 | 19 | private $process; 20 | 21 | public function __construct(Process $process) 22 | { 23 | if ($process->isSuccessful()) { 24 | throw new \InvalidArgumentException('Expected a failed process, but the given process was successful.'); 25 | } 26 | 27 | $error = sprintf('The command "%s" failed.' . "\nExit Code: %s(%s)", $process->getCommandLine(), $process->getExitCode(), $process->getExitCodeText()); 28 | 29 | if (!$process->isOutputDisabled()) { 30 | $error .= sprintf("\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s", $process->getOutput(), $process->getErrorOutput()); 31 | } 32 | 33 | parent::__construct($error); 34 | 35 | $this->process = $process; 36 | } 37 | 38 | public function getProcess() 39 | { 40 | return $this->process; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /thinkphp/library/think/facade/Cookie.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\facade; 13 | 14 | use think\Facade; 15 | 16 | /** 17 | * @see \think\Cookie 18 | * @mixin \think\Cookie 19 | * @method void init(array $config = []) static 初始化 20 | * @method bool has(string $name,string $prefix = null) static 判断Cookie数据 21 | * @method mixed prefix(string $prefix = '') static 设置或者获取cookie作用域(前缀) 22 | * @method mixed get(string $name,string $prefix = null) static Cookie获取 23 | * @method mixed set(string $name, mixed $value = null, mixed $option = null) static 设置Cookie 24 | * @method void forever(string $name, mixed $value = null, mixed $option = null) static 永久保存Cookie数据 25 | * @method void delete(string $name, string $prefix = null) static Cookie删除 26 | * @method void clear($prefix = null) static Cookie清空 27 | */ 28 | class Cookie extends Facade 29 | { 30 | /** 31 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识) 32 | * @access protected 33 | * @return string 34 | */ 35 | protected static function getFacadeClass() 36 | { 37 | return 'cookie'; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /thinkphp/library/think/response/Json.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\response; 13 | 14 | use think\Response; 15 | 16 | class Json extends Response 17 | { 18 | // 输出参数 19 | protected $options = [ 20 | 'json_encode_param' => JSON_UNESCAPED_UNICODE, 21 | ]; 22 | 23 | protected $contentType = 'application/json'; 24 | 25 | /** 26 | * 处理数据 27 | * @access protected 28 | * @param mixed $data 要处理的数据 29 | * @return mixed 30 | * @throws \Exception 31 | */ 32 | protected function output($data) 33 | { 34 | try { 35 | // 返回JSON数据格式到客户端 包含状态信息 36 | $data = json_encode($data, $this->options['json_encode_param']); 37 | 38 | if (false === $data) { 39 | throw new \InvalidArgumentException(json_last_error_msg()); 40 | } 41 | 42 | return $data; 43 | } catch (\Exception $e) { 44 | if ($e->getPrevious()) { 45 | throw $e->getPrevious(); 46 | } 47 | throw $e; 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /application/util/SougouApi.php: -------------------------------------------------------------------------------- 1 | "-1","msg"=>"图片格式有误","img"=>null); 24 | } 25 | 26 | 27 | 28 | $img = base64_decode($img); 29 | 30 | 31 | $data = base64_decode("LS0tLS0tV2ViS2l0Rm9ybUJvdW5kYXJ5R0xmR0IwSGdVTnRwVFQxaw0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJwaWNfcGF0aCI7IGZpbGVuYW1lPSIxMS5wbmciDQpDb250ZW50LVR5cGU6IGltYWdlL3BuZw0KDQo=").$img.base64_decode("DQotLS0tLS1XZWJLaXRGb3JtQm91bmRhcnlHTGZHQjBIZ1VOdHBUVDFrLS0NCg=="); 32 | 33 | $url = "http://pic.sogou.com/pic/upload_pic.jsp"; 34 | 35 | 36 | $ch = curl_init(); 37 | $headers=array( 38 | "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryGLfGB0HgUNtpTT1k", 39 | "Content-Length: ".strlen($data) 40 | ); 41 | 42 | curl_setopt($ch, CURLOPT_URL, $url); 43 | curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 44 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 45 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 46 | 47 | 48 | $result=curl_exec($ch); 49 | curl_close($ch); 50 | return array("code"=>"1","msg"=>"上传成功","img"=>$result); 51 | 52 | } 53 | } -------------------------------------------------------------------------------- /thinkphp/library/think/Exception.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think; 13 | 14 | class Exception extends \Exception 15 | { 16 | 17 | /** 18 | * 保存异常页面显示的额外Debug数据 19 | * @var array 20 | */ 21 | protected $data = []; 22 | 23 | /** 24 | * 设置异常额外的Debug数据 25 | * 数据将会显示为下面的格式 26 | * 27 | * Exception Data 28 | * -------------------------------------------------- 29 | * Label 1 30 | * key1 value1 31 | * key2 value2 32 | * Label 2 33 | * key1 value1 34 | * key2 value2 35 | * 36 | * @access protected 37 | * @param string $label 数据分类,用于异常页面显示 38 | * @param array $data 需要显示的数据,必须为关联数组 39 | */ 40 | final protected function setData($label, array $data) 41 | { 42 | $this->data[$label] = $data; 43 | } 44 | 45 | /** 46 | * 获取异常额外Debug数据 47 | * 主要用于输出到异常页面便于调试 48 | * @access public 49 | * @return array 由setData设置的Debug数据 50 | */ 51 | final public function getData() 52 | { 53 | return $this->data; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/make/stubs/controller.stub: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\facade; 13 | 14 | use think\Facade; 15 | 16 | /** 17 | * @see \think\Lang 18 | * @mixin \think\Lang 19 | * @method mixed range($range = '') static 设定当前的语言 20 | * @method mixed set(mixed $name, string $value = null, string $range = '') static 设置语言定义 21 | * @method array load(mixed $file, string $range = '') static 加载语言定义 22 | * @method mixed get(string $name = null, array $vars = [], string $range = '') static 获取语言定义 23 | * @method mixed has(string $name, string $range = '') static 获取语言定义 24 | * @method string detect() static 自动侦测设置获取语言选择 25 | * @method void saveToCookie(string $lang = null) static 设置当前语言到Cookie 26 | * @method void setLangDetectVar(string $var) static 设置语言自动侦测的变量 27 | * @method void setLangCookieVar(string $var) static 设置语言的cookie保存变量 28 | * @method void setAllowLangList(array $list) static 设置允许的语言列表 29 | */ 30 | class Lang extends Facade 31 | { 32 | /** 33 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识) 34 | * @access protected 35 | * @return string 36 | */ 37 | protected static function getFacadeClass() 38 | { 39 | return 'lang'; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /thinkphp/library/think/exception/ThrowableError.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\exception; 13 | 14 | class ThrowableError extends \ErrorException 15 | { 16 | public function __construct(\Throwable $e) 17 | { 18 | 19 | if ($e instanceof \ParseError) { 20 | $message = 'Parse error: ' . $e->getMessage(); 21 | $severity = E_PARSE; 22 | } elseif ($e instanceof \TypeError) { 23 | $message = 'Type error: ' . $e->getMessage(); 24 | $severity = E_RECOVERABLE_ERROR; 25 | } else { 26 | $message = 'Fatal error: ' . $e->getMessage(); 27 | $severity = E_ERROR; 28 | } 29 | 30 | parent::__construct( 31 | $message, 32 | $e->getCode(), 33 | $severity, 34 | $e->getFile(), 35 | $e->getLine() 36 | ); 37 | 38 | $this->setTrace($e->getTrace()); 39 | } 40 | 41 | protected function setTrace($trace) 42 | { 43 | $traceReflector = new \ReflectionProperty('Exception', 'trace'); 44 | $traceReflector->setAccessible(true); 45 | $traceReflector->setValue($this, $trace); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /thinkphp/library/think/exception/ErrorException.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\exception; 13 | 14 | use think\Exception; 15 | 16 | /** 17 | * ThinkPHP错误异常 18 | * 主要用于封装 set_error_handler 和 register_shutdown_function 得到的错误 19 | * 除开从 think\Exception 继承的功能 20 | * 其他和PHP系统\ErrorException功能基本一样 21 | */ 22 | class ErrorException extends Exception 23 | { 24 | /** 25 | * 用于保存错误级别 26 | * @var integer 27 | */ 28 | protected $severity; 29 | 30 | /** 31 | * 错误异常构造函数 32 | * @access public 33 | * @param integer $severity 错误级别 34 | * @param string $message 错误详细信息 35 | * @param string $file 出错文件路径 36 | * @param integer $line 出错行号 37 | */ 38 | public function __construct($severity, $message, $file, $line) 39 | { 40 | $this->severity = $severity; 41 | $this->message = $message; 42 | $this->file = $file; 43 | $this->line = $line; 44 | $this->code = 0; 45 | } 46 | 47 | /** 48 | * 获取错误级别 49 | * @access public 50 | * @return integer 错误级别 51 | */ 52 | final public function getSeverity() 53 | { 54 | return $this->severity; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /thinkphp/library/think/facade/View.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\facade; 13 | 14 | use think\Facade; 15 | 16 | /** 17 | * @see \think\View 18 | * @mixin \think\View 19 | * @method \think\View init(mixed $engine = [], array $replace = []) static 初始化 20 | * @method \think\View share(mixed $name, mixed $value = '') static 模板变量静态赋值 21 | * @method \think\View assign(mixed $name, mixed $value = '') static 模板变量赋值 22 | * @method \think\View config(mixed $name, mixed $value = '') static 配置模板引擎 23 | * @method \think\View exists(mixed $name) static 检查模板是否存在 24 | * @method \think\View filter(Callable $filter) static 视图内容过滤 25 | * @method \think\View engine(mixed $engine = []) static 设置当前模板解析的引擎 26 | * @method string fetch(string $template = '', array $vars = [], array $replace = [], array $config = [], bool $renderContent = false) static 解析和获取模板内容 27 | * @method string display(string $content = '', array $vars = [], array $replace = [], array $config = []) static 渲染内容输出 28 | */ 29 | class View extends Facade 30 | { 31 | /** 32 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识) 33 | * @access protected 34 | * @return string 35 | */ 36 | protected static function getFacadeClass() 37 | { 38 | return 'view'; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /thinkphp/library/think/facade/Debug.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\facade; 13 | 14 | use think\Facade; 15 | 16 | /** 17 | * @see \think\Debug 18 | * @mixin \think\Debug 19 | * @method void remark(string $name, mixed $value = '') static 记录时间(微秒)和内存使用情况 20 | * @method int getRangeTime(string $start, string $end, mixed $dec = 6) static 统计某个区间的时间(微秒)使用情况 21 | * @method int getUseTime(int $dec = 6) static 统计从开始到统计时的时间(微秒)使用情况 22 | * @method string getThroughputRate(string $start, string $end, mixed $dec = 6) static 获取当前访问的吞吐率情况 23 | * @method string getRangeMem(string $start, string $end, mixed $dec = 2) static 记录区间的内存使用情况 24 | * @method int getUseMem(int $dec = 2) static 统计从开始到统计时的内存使用情况 25 | * @method string getMemPeak(string $start, string $end, mixed $dec = 2) static 统计区间的内存峰值情况 26 | * @method mixed getFile(bool $detail = false) static 获取文件加载信息 27 | * @method mixed dump(mixed $var, bool $echo = true, string $label = null, int $flags = ENT_SUBSTITUTE) static 浏览器友好的变量输出 28 | */ 29 | class Debug extends Facade 30 | { 31 | /** 32 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识) 33 | * @access protected 34 | * @return string 35 | */ 36 | protected static function getFacadeClass() 37 | { 38 | return 'debug'; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /thinkphp/base.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | namespace think; 12 | 13 | // 载入Loader类 14 | require __DIR__ . '/library/think/Loader.php'; 15 | 16 | // 注册自动加载 17 | Loader::register(); 18 | 19 | // 注册错误和异常处理机制 20 | Error::register(); 21 | 22 | // 实现日志接口 23 | if (interface_exists('Psr\Log\LoggerInterface')) { 24 | interface LoggerInterface extends \Psr\Log\LoggerInterface 25 | {} 26 | } else { 27 | interface LoggerInterface 28 | {} 29 | } 30 | 31 | // 注册类库别名 32 | Loader::addClassAlias([ 33 | 'App' => facade\App::class, 34 | 'Build' => facade\Build::class, 35 | 'Cache' => facade\Cache::class, 36 | 'Config' => facade\Config::class, 37 | 'Cookie' => facade\Cookie::class, 38 | 'Db' => Db::class, 39 | 'Debug' => facade\Debug::class, 40 | 'Env' => facade\Env::class, 41 | 'Facade' => Facade::class, 42 | 'Hook' => facade\Hook::class, 43 | 'Lang' => facade\Lang::class, 44 | 'Log' => facade\Log::class, 45 | 'Request' => facade\Request::class, 46 | 'Response' => facade\Response::class, 47 | 'Route' => facade\Route::class, 48 | 'Session' => facade\Session::class, 49 | 'Url' => facade\Url::class, 50 | 'Validate' => facade\Validate::class, 51 | 'View' => facade\View::class, 52 | ]); 53 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/output/question/Confirmation.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\output\question; 13 | 14 | use think\console\output\Question; 15 | 16 | class Confirmation extends Question 17 | { 18 | 19 | private $trueAnswerRegex; 20 | 21 | /** 22 | * 构造方法 23 | * @param string $question 问题 24 | * @param bool $default 默认答案 25 | * @param string $trueAnswerRegex 验证正则 26 | */ 27 | public function __construct($question, $default = true, $trueAnswerRegex = '/^y/i') 28 | { 29 | parent::__construct($question, (bool) $default); 30 | 31 | $this->trueAnswerRegex = $trueAnswerRegex; 32 | $this->setNormalizer($this->getDefaultNormalizer()); 33 | } 34 | 35 | /** 36 | * 获取默认的答案回调 37 | * @return callable 38 | */ 39 | private function getDefaultNormalizer() 40 | { 41 | $default = $this->getDefault(); 42 | $regex = $this->trueAnswerRegex; 43 | 44 | return function ($answer) use ($default, $regex) { 45 | if (is_bool($answer)) { 46 | return $answer; 47 | } 48 | 49 | $answerIsTrue = (bool) preg_match($regex, $answer); 50 | if (false === $default) { 51 | return $answer && $answerIsTrue; 52 | } 53 | 54 | return !$answer || $answerIsTrue; 55 | }; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /thinkphp/library/think/facade/Cache.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\facade; 13 | 14 | use think\Facade; 15 | 16 | /** 17 | * @see \think\Cache 18 | * @mixin \think\Cache 19 | * @method \think\cache\Driver connect(array $options = [], mixed $name = false) static 连接缓存 20 | * @method \think\cache\Driver init(array $options = []) static 初始化缓存 21 | * @method \think\cache\Driver store(string $name = '') static 切换缓存类型 22 | * @method bool has(string $name) static 判断缓存是否存在 23 | * @method mixed get(string $name, mixed $default = false) static 读取缓存 24 | * @method mixed pull(string $name) static 读取缓存并删除 25 | * @method mixed set(string $name, mixed $value, int $expire = null) static 设置缓存 26 | * @method mixed remember(string $name, mixed $value, int $expire = null) static 如果不存在则写入缓存 27 | * @method mixed inc(string $name, int $step = 1) static 自增缓存(针对数值缓存) 28 | * @method mixed dec(string $name, int $step = 1) static 自减缓存(针对数值缓存) 29 | * @method bool rm(string $name) static 删除缓存 30 | * @method bool clear(string $tag = null) static 清除缓存 31 | * @method mixed tag(string $name, mixed $keys = null, bool $overlay = false) static 缓存标签 32 | * @method object handler() static 返回句柄对象,可执行其它高级方法 33 | */ 34 | class Cache extends Facade 35 | { 36 | /** 37 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识) 38 | * @access protected 39 | * @return string 40 | */ 41 | protected static function getFacadeClass() 42 | { 43 | return 'cache'; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /config/database.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | return [ 13 | // 数据库类型 14 | 'type' => 'mysql', 15 | // 服务器地址 16 | 'hostname' => '127.0.0.1', 17 | // 数据库名 18 | 'database' => '', 19 | // 用户名 20 | 'username' => 'root', 21 | // 密码 22 | 'password' => '', 23 | // 端口 24 | 'hostport' => '', 25 | // 连接dsn 26 | 'dsn' => '', 27 | // 数据库连接参数 28 | 'params' => [], 29 | // 数据库编码默认采用utf8 30 | 'charset' => 'utf8', 31 | // 数据库表前缀 32 | 'prefix' => '', 33 | // 数据库调试模式 34 | 'debug' => true, 35 | // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) 36 | 'deploy' => 0, 37 | // 数据库读写是否分离 主从式有效 38 | 'rw_separate' => false, 39 | // 读写分离后 主服务器数量 40 | 'master_num' => 1, 41 | // 指定从服务器序号 42 | 'slave_no' => '', 43 | // 自动读取主库数据 44 | 'read_master' => false, 45 | // 是否严格检查字段是否存在 46 | 'fields_strict' => true, 47 | // 数据集返回类型 48 | 'resultset_type' => 'array', 49 | // 自动写入时间戳字段 50 | 'auto_timestamp' => false, 51 | // 时间字段取出后的默认时间格式 52 | 'datetime_format' => 'Y-m-d H:i:s', 53 | // 是否需要进行SQL性能分析 54 | 'sql_explain' => false, 55 | // Builder类 56 | 'builder' => '', 57 | // Query类 58 | 'query' => '\\think\\db\\Query', 59 | // 是否需要断线重连 60 | 'break_reconnect' => false, 61 | // 断线标识字符串 62 | 'break_match_str' => [], 63 | ]; 64 | -------------------------------------------------------------------------------- /thinkphp/library/think/process/exception/Timeout.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\process\exception; 13 | 14 | use think\Process; 15 | 16 | class Timeout extends \RuntimeException 17 | { 18 | 19 | const TYPE_GENERAL = 1; 20 | const TYPE_IDLE = 2; 21 | 22 | private $process; 23 | private $timeoutType; 24 | 25 | public function __construct(Process $process, $timeoutType) 26 | { 27 | $this->process = $process; 28 | $this->timeoutType = $timeoutType; 29 | 30 | parent::__construct(sprintf('The process "%s" exceeded the timeout of %s seconds.', $process->getCommandLine(), $this->getExceededTimeout())); 31 | } 32 | 33 | public function getProcess() 34 | { 35 | return $this->process; 36 | } 37 | 38 | public function isGeneralTimeout() 39 | { 40 | return $this->timeoutType === self::TYPE_GENERAL; 41 | } 42 | 43 | public function isIdleTimeout() 44 | { 45 | return $this->timeoutType === self::TYPE_IDLE; 46 | } 47 | 48 | public function getExceededTimeout() 49 | { 50 | switch ($this->timeoutType) { 51 | case self::TYPE_GENERAL: 52 | return $this->process->getTimeout(); 53 | 54 | case self::TYPE_IDLE: 55 | return $this->process->getIdleTimeout(); 56 | 57 | default: 58 | throw new \LogicException(sprintf('Unknown timeout type "%d".', $this->timeoutType)); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /thinkphp/library/think/facade/Session.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\facade; 13 | 14 | use think\Facade; 15 | 16 | /** 17 | * @see \think\Session 18 | * @mixin \think\Session 19 | * @method void init(array $config = []) static session初始化 20 | * @method bool has(string $name,string $prefix = null) static 判断session数据 21 | * @method mixed prefix(string $prefix = '') static 设置或者获取session作用域(前缀) 22 | * @method mixed get(string $name = '',string $prefix = null) static session获取 23 | * @method mixed pull(string $name,string $prefix = null) static session获取并删除 24 | * @method void push(string $key, mixed $value) static 添加数据到一个session数组 25 | * @method void set(string $name, mixed $value , string $prefix = null) static 设置session数据 26 | * @method void flash(string $name, mixed $value = null) static session设置 下一次请求有效 27 | * @method void flush() static 清空当前请求的session数据 28 | * @method void delete(string $name, string $prefix = null) static 删除session数据 29 | * @method void clear($prefix = null) static 清空session数据 30 | * @method void start() static 启动session 31 | * @method void destroy() static 销毁session 32 | * @method void pause() static 暂停session 33 | * @method void regenerate(bool $delete = false) static 重新生成session_id 34 | */ 35 | class Session extends Facade 36 | { 37 | /** 38 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识) 39 | * @access protected 40 | * @return string 41 | */ 42 | protected static function getFacadeClass() 43 | { 44 | return 'session'; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/Build.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\command; 13 | 14 | use think\console\Command; 15 | use think\console\Input; 16 | use think\console\input\Option; 17 | use think\console\Output; 18 | use think\facade\App; 19 | use think\facade\Build as AppBuild; 20 | 21 | class Build extends Command 22 | { 23 | /** 24 | * {@inheritdoc} 25 | */ 26 | protected function configure() 27 | { 28 | $this->setName('build') 29 | ->setDefinition([ 30 | new Option('config', null, Option::VALUE_OPTIONAL, "build.php path"), 31 | new Option('module', null, Option::VALUE_OPTIONAL, "module name"), 32 | ]) 33 | ->setDescription('Build Application Dirs'); 34 | } 35 | 36 | protected function execute(Input $input, Output $output) 37 | { 38 | if ($input->hasOption('module')) { 39 | AppBuild::module($input->getOption('module')); 40 | $output->writeln("Successed"); 41 | return; 42 | } 43 | 44 | if ($input->hasOption('config')) { 45 | $build = include $input->getOption('config'); 46 | } else { 47 | $build = include App::getAppPath() . 'build.php'; 48 | } 49 | 50 | if (empty($build)) { 51 | $output->writeln("Build Config Is Empty"); 52 | return; 53 | } 54 | 55 | AppBuild::run($build); 56 | $output->writeln("Successed"); 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/make/Command.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\command\make; 13 | 14 | use think\console\command\Make; 15 | use think\console\input\Argument; 16 | use think\facade\App; 17 | 18 | class Command extends Make 19 | { 20 | protected $type = "Command"; 21 | 22 | protected function configure() 23 | { 24 | parent::configure(); 25 | $this->setName('make:command') 26 | ->addArgument('commandName', Argument::OPTIONAL, "The name of the command") 27 | ->setDescription('Create a new command class'); 28 | } 29 | 30 | protected function buildClass($name) 31 | { 32 | $commandName = $this->input->getArgument('commandName') ?: strtolower(basename($name)); 33 | $namespace = trim(implode('\\', array_slice(explode('\\', $name), 0, -1)), '\\'); 34 | 35 | $class = str_replace($namespace . '\\', '', $name); 36 | $stub = file_get_contents($this->getStub()); 37 | 38 | return str_replace(['{%commandName%}', '{%className%}', '{%namespace%}', '{%app_namespace%}'], [ 39 | $commandName, 40 | $class, 41 | $namespace, 42 | App::getNamespace(), 43 | ], $stub); 44 | } 45 | 46 | protected function getStub() 47 | { 48 | return __DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'command.stub'; 49 | } 50 | 51 | protected function getNamespace($appNamespace, $module) 52 | { 53 | return $appNamespace . '\\command'; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /thinkphp/library/think/response/Jsonp.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\response; 13 | 14 | use think\Response; 15 | 16 | class Jsonp extends Response 17 | { 18 | // 输出参数 19 | protected $options = [ 20 | 'var_jsonp_handler' => 'callback', 21 | 'default_jsonp_handler' => 'jsonpReturn', 22 | 'json_encode_param' => JSON_UNESCAPED_UNICODE, 23 | ]; 24 | 25 | protected $contentType = 'application/javascript'; 26 | 27 | /** 28 | * 处理数据 29 | * @access protected 30 | * @param mixed $data 要处理的数据 31 | * @return mixed 32 | * @throws \Exception 33 | */ 34 | protected function output($data) 35 | { 36 | try { 37 | // 返回JSON数据格式到客户端 包含状态信息 [当url_common_param为false时是无法获取到$_GET的数据的,故使用Request来获取] 38 | $var_jsonp_handler = $this->app['request']->param($this->options['var_jsonp_handler'], ""); 39 | $handler = !empty($var_jsonp_handler) ? $var_jsonp_handler : $this->options['default_jsonp_handler']; 40 | 41 | $data = json_encode($data, $this->options['json_encode_param']); 42 | 43 | if (false === $data) { 44 | throw new \InvalidArgumentException(json_last_error_msg()); 45 | } 46 | 47 | $data = $handler . '(' . $data . ');'; 48 | 49 | return $data; 50 | } catch (\Exception $e) { 51 | if ($e->getPrevious()) { 52 | throw $e->getPrevious(); 53 | } 54 | throw $e; 55 | } 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/make/Controller.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\command\make; 13 | 14 | use think\console\command\Make; 15 | use think\console\input\Option; 16 | use think\facade\Config; 17 | 18 | class Controller extends Make 19 | { 20 | protected $type = "Controller"; 21 | 22 | protected function configure() 23 | { 24 | parent::configure(); 25 | $this->setName('make:controller') 26 | ->addOption('api', null, Option::VALUE_NONE, 'Generate an api controller class.') 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 | $stubPath = __DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR; 34 | 35 | if ($this->input->getOption('api')) { 36 | return $stubPath . 'controller.api.stub'; 37 | } 38 | 39 | if ($this->input->getOption('plain')) { 40 | return $stubPath . 'controller.plain.stub'; 41 | } 42 | 43 | return $stubPath . 'controller.stub'; 44 | } 45 | 46 | protected function getClassName($name) 47 | { 48 | return parent::getClassName($name) . (Config::get('controller_suffix') ? ucfirst(Config::get('url_controller_layer')) : ''); 49 | } 50 | 51 | protected function getNamespace($appNamespace, $module) 52 | { 53 | return parent::getNamespace($appNamespace, $module) . '\controller'; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: php 4 | 5 | branches: 6 | only: 7 | - stable 8 | 9 | cache: 10 | directories: 11 | - $HOME/.composer/cache 12 | 13 | before_install: 14 | - composer self-update 15 | 16 | install: 17 | - composer install --no-dev --no-interaction --ignore-platform-reqs 18 | - zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Core.zip . 19 | - composer require --update-no-dev --no-interaction "topthink/think-image:^1.0" 20 | - composer require --update-no-dev --no-interaction "topthink/think-migration:^1.0" 21 | - composer require --update-no-dev --no-interaction "topthink/think-captcha:^1.0" 22 | - composer require --update-no-dev --no-interaction "topthink/think-mongo:^1.0" 23 | - composer require --update-no-dev --no-interaction "topthink/think-worker:^1.0" 24 | - composer require --update-no-dev --no-interaction "topthink/think-helper:^1.0" 25 | - composer require --update-no-dev --no-interaction "topthink/think-queue:^1.0" 26 | - composer require --update-no-dev --no-interaction "topthink/think-angular:^1.0" 27 | - composer require --dev --update-no-dev --no-interaction "topthink/think-testing:^1.0" 28 | - zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Full.zip . 29 | 30 | script: 31 | - php think unit 32 | 33 | deploy: 34 | provider: releases 35 | api_key: 36 | secure: TSF6bnl2JYN72UQOORAJYL+CqIryP2gHVKt6grfveQ7d9rleAEoxlq6PWxbvTI4jZ5nrPpUcBUpWIJHNgVcs+bzLFtyh5THaLqm39uCgBbrW7M8rI26L8sBh/6nsdtGgdeQrO/cLu31QoTzbwuz1WfAVoCdCkOSZeXyT/CclH99qV6RYyQYqaD2wpRjrhA5O4fSsEkiPVuk0GaOogFlrQHx+C+lHnf6pa1KxEoN1A0UxxVfGX6K4y5g4WQDO5zT4bLeubkWOXK0G51XSvACDOZVIyLdjApaOFTwamPcD3S1tfvuxRWWvsCD5ljFvb2kSmx5BIBNwN80MzuBmrGIC27XLGOxyMerwKxB6DskNUO9PflKHDPI61DRq0FTy1fv70SFMSiAtUv9aJRT41NQh9iJJ0vC8dl+xcxrWIjU1GG6+l/ZcRqVx9V1VuGQsLKndGhja7SQ+X1slHl76fRq223sMOql7MFCd0vvvxVQ2V39CcFKao/LB1aPH3VhODDEyxwx6aXoTznvC/QPepgWsHOWQzKj9ftsgDbsNiyFlXL4cu8DWUty6rQy8zT2b4O8b1xjcwSUCsy+auEjBamzQkMJFNlZAIUrukL/NbUhQU37TAbwsFyz7X0E/u/VMle/nBCNAzgkMwAUjiHM6FqrKKBRWFbPrSIixjfjkCnrMEPw= 37 | file: 38 | - ThinkPHP_Core.zip 39 | - ThinkPHP_Full.zip 40 | skip_cleanup: true 41 | on: 42 | tags: true 43 | -------------------------------------------------------------------------------- /thinkphp/library/think/facade/Response.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\facade; 13 | 14 | use think\Facade; 15 | 16 | /** 17 | * @see \think\Response 18 | * @mixin \think\Response 19 | * @method \think\response create(mixed $data = '', string $type = '', int $code = 200, array $header = [], array $options = []) static 创建Response对象 20 | * @method void send() static 发送数据到客户端 21 | * @method \think\Response options(mixed $options = []) static 输出的参数 22 | * @method \think\Response data(mixed $data) static 输出数据设置 23 | * @method \think\Response header(mixed $name, string $value = null) static 设置响应头 24 | * @method \think\Response content(mixed $content) static 设置页面输出内容 25 | * @method \think\Response code(int $code) static 发送HTTP状态 26 | * @method \think\Response lastModified(string $time) static LastModified 27 | * @method \think\Response expires(string $time) static expires 28 | * @method \think\Response eTag(string $eTag) static eTag 29 | * @method \think\Response cacheControl(string $cache) static 页面缓存控制 30 | * @method \think\Response contentType(string $contentType, string $charset = 'utf-8') static 页面输出类型 31 | * @method mixed getHeader(string $name) static 获取头部信息 32 | * @method mixed getData() static 获取原始数据 33 | * @method mixed getContent() static 获取输出数据 34 | * @method int getCode() static 获取状态码 35 | */ 36 | class Response extends Facade 37 | { 38 | /** 39 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识) 40 | * @access protected 41 | * @return string 42 | */ 43 | protected static function getFacadeClass() 44 | { 45 | return 'response'; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /thinkphp/README.md: -------------------------------------------------------------------------------- 1 | ![](http://www.thinkphp.cn/Uploads/editor/2016-06-23/576b4732a6e04.png) 2 | 3 | ThinkPHP 5.1 —— 12载初心,你值得信赖的PHP框架 4 | =============== 5 | 6 | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/top-think/framework/badges/quality-score.png?b=5.1)](https://scrutinizer-ci.com/g/top-think/framework/?branch=5.1) 7 | [![Build Status](https://travis-ci.org/top-think/framework.svg?branch=master)](https://travis-ci.org/top-think/framework) 8 | [![Total Downloads](https://poser.pugx.org/topthink/framework/downloads)](https://packagist.org/packages/topthink/framework) 9 | [![Latest Stable Version](https://poser.pugx.org/topthink/framework/v/stable)](https://packagist.org/packages/topthink/framework) 10 | [![PHP Version](https://img.shields.io/badge/php-%3E%3D5.6-8892BF.svg)](http://www.php.net/) 11 | [![License](https://poser.pugx.org/topthink/framework/license)](https://packagist.org/packages/topthink/framework) 12 | 13 | ThinkPHP5.1对底层架构做了进一步的改进,减少依赖,其主要特性包括: 14 | 15 | + 采用容器统一管理对象 16 | + 支持Facade 17 | + 更易用的路由 18 | + 注解路由支持 19 | + 路由跨域请求支持 20 | + 验证类增强 21 | + 配置和路由目录独立 22 | + 取消系统常量 23 | + 类库别名机制 24 | + 模型和数据库增强 25 | + 依赖注入完善 26 | + 支持PSR-3日志规范 27 | + 中间件支持(`V5.1.6+`) 28 | + 支持`Swoole`/`Workerman`运行(`V5.1.18+`) 29 | 30 | 31 | ### 废除的功能: 32 | 33 | + 聚合模型 34 | + 内置控制器扩展类 35 | + 模型自动验证 36 | 37 | > ThinkPHP5.1的运行环境要求PHP5.6+。 38 | 39 | ## 安装 40 | 41 | 使用composer安装 42 | 43 | ~~~ 44 | composer create-project topthink/think tp 45 | ~~~ 46 | 47 | 启动服务 48 | 49 | ~~~ 50 | cd tp 51 | php think run 52 | ~~~ 53 | 54 | 然后就可以在浏览器中访问 55 | 56 | ~~~ 57 | http://localhost:8000 58 | ~~~ 59 | 60 | 更新框架 61 | ~~~ 62 | composer update topthink/framework 63 | ~~~ 64 | 65 | 66 | ## 在线手册 67 | 68 | + [完全开发手册](https://www.kancloud.cn/manual/thinkphp5_1/content) 69 | + [升级指导](https://www.kancloud.cn/manual/thinkphp5_1/354155) 70 | 71 | ## 命名规范 72 | 73 | `ThinkPHP5.1`遵循PSR-2命名规范和PSR-4自动加载规范。 74 | 75 | ## 参与开发 76 | 77 | 请参阅 [ThinkPHP5 核心框架包](https://github.com/top-think/framework)。 78 | 79 | ## 版权信息 80 | 81 | ThinkPHP遵循Apache2开源协议发布,并提供免费使用。 82 | 83 | 本项目包含的第三方源码和二进制文件之版权信息另行标注。 84 | 85 | 版权所有Copyright © 2006-2018 by ThinkPHP (http://thinkphp.cn) 86 | 87 | All rights reserved。 88 | 89 | ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。 90 | 91 | 更多细节参阅 [LICENSE.txt](LICENSE.txt) 92 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/RunServer.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | namespace think\console\command; 12 | 13 | use think\console\Command; 14 | use think\console\Input; 15 | use think\console\input\Option; 16 | use think\console\Output; 17 | use think\facade\App; 18 | 19 | class RunServer extends Command 20 | { 21 | public function configure() 22 | { 23 | $this->setName('run') 24 | ->addOption('host', 'H', Option::VALUE_OPTIONAL, 25 | 'The host to server the application on', '127.0.0.1') 26 | ->addOption('port', 'p', Option::VALUE_OPTIONAL, 27 | 'The port to server the application on', 8000) 28 | ->addOption('root', 'r', Option::VALUE_OPTIONAL, 29 | 'The document root of the application', App::getRootPath() . 'public') 30 | ->setDescription('PHP Built-in Server for ThinkPHP'); 31 | } 32 | 33 | public function execute(Input $input, Output $output) 34 | { 35 | $host = $input->getOption('host'); 36 | $port = $input->getOption('port'); 37 | $root = $input->getOption('root'); 38 | 39 | $command = sprintf( 40 | 'php -S %s:%d -t %s %s', 41 | $host, 42 | $port, 43 | escapeshellarg($root), 44 | escapeshellarg($root . DIRECTORY_SEPARATOR . 'router.php') 45 | ); 46 | 47 | $output->writeln(sprintf('ThinkPHP Development server is started On ', $host, $port)); 48 | $output->writeln(sprintf('You can exit with `CTRL-C`')); 49 | $output->writeln(sprintf('Document root is: %s', $root)); 50 | passthru($command); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /thinkphp/tpl/dispatch_jump.tpl: -------------------------------------------------------------------------------- 1 | {__NOLAYOUT__} 2 | 3 | 4 | 5 | 6 | 跳转提示 7 | 17 | 18 | 19 |
20 | 21 | 22 |

:)

23 |

24 | 25 | 26 |

:(

27 |

28 | 29 | 30 |

31 |

32 | 页面自动 跳转 等待时间: 33 |

34 |
35 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /thinkphp/library/think/facade/Log.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\facade; 13 | 14 | use think\Facade; 15 | 16 | /** 17 | * @see \think\Log 18 | * @mixin \think\Log 19 | * @method \think\Log init(array $config = []) static 日志初始化 20 | * @method mixed getLog(string $type = '') static 获取日志信息 21 | * @method \think\Log record(mixed $msg, string $type = 'info', array $context = []) static 记录日志信息 22 | * @method \think\Log clear() static 清空日志信息 23 | * @method \think\Log key(string $key) static 当前日志记录的授权key 24 | * @method bool check(array $config) static 检查日志写入权限 25 | * @method bool save() static 保存调试信息 26 | * @method void write(mixed $msg, string $type = 'info', bool $force = false) static 实时写入日志信息 27 | * @method void log(string $level,mixed $message, array $context = []) static 记录日志信息 28 | * @method void emergency(mixed $message, array $context = []) static 记录emergency信息 29 | * @method void alert(mixed $message, array $context = []) static 记录alert信息 30 | * @method void critical(mixed $message, array $context = []) static 记录critical信息 31 | * @method void error(mixed $message, array $context = []) static 记录error信息 32 | * @method void warning(mixed $message, array $context = []) static 记录warning信息 33 | * @method void notice(mixed $message, array $context = []) static 记录notice信息 34 | * @method void info(mixed $message, array $context = []) static 记录info信息 35 | * @method void debug(mixed $message, array $context = []) static 记录debug信息 36 | * @method void sql(mixed $message, array $context = []) static 记录sql信息 37 | */ 38 | class Log extends Facade 39 | { 40 | /** 41 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识) 42 | * @access protected 43 | * @return string 44 | */ 45 | protected static function getFacadeClass() 46 | { 47 | return 'log'; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/Help.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\command; 13 | 14 | use think\console\Command; 15 | use think\console\Input; 16 | use think\console\input\Argument as InputArgument; 17 | use think\console\input\Option as InputOption; 18 | use think\console\Output; 19 | 20 | class Help extends Command 21 | { 22 | private $command; 23 | 24 | /** 25 | * {@inheritdoc} 26 | */ 27 | protected function configure() 28 | { 29 | $this->ignoreValidationErrors(); 30 | 31 | $this->setName('help')->setDefinition([ 32 | new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'), 33 | new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command help'), 34 | ])->setDescription('Displays help for a command')->setHelp(<<%command.name% command displays help for a given command: 36 | 37 | php %command.full_name% list 38 | 39 | To display the list of available commands, please use the list command. 40 | EOF 41 | ); 42 | } 43 | 44 | /** 45 | * Sets the command. 46 | * @param Command $command The command to set 47 | */ 48 | public function setCommand(Command $command) 49 | { 50 | $this->command = $command; 51 | } 52 | 53 | /** 54 | * {@inheritdoc} 55 | */ 56 | protected function execute(Input $input, Output $output) 57 | { 58 | if (null === $this->command) { 59 | $this->command = $this->getConsole()->find($input->getArgument('command_name')); 60 | } 61 | 62 | $output->describe($this->command, [ 63 | 'raw_text' => $input->getOption('raw'), 64 | ]); 65 | 66 | $this->command = null; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /thinkphp/library/think/template/driver/File.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\template\driver; 13 | 14 | use think\Exception; 15 | 16 | class File 17 | { 18 | protected $cacheFile; 19 | 20 | /** 21 | * 写入编译缓存 22 | * @access public 23 | * @param string $cacheFile 缓存的文件名 24 | * @param string $content 缓存的内容 25 | * @return void|array 26 | */ 27 | public function write($cacheFile, $content) 28 | { 29 | // 检测模板目录 30 | $dir = dirname($cacheFile); 31 | 32 | if (!is_dir($dir)) { 33 | mkdir($dir, 0755, true); 34 | } 35 | 36 | // 生成模板缓存文件 37 | if (false === file_put_contents($cacheFile, $content)) { 38 | throw new Exception('cache write error:' . $cacheFile, 11602); 39 | } 40 | } 41 | 42 | /** 43 | * 读取编译编译 44 | * @access public 45 | * @param string $cacheFile 缓存的文件名 46 | * @param array $vars 变量数组 47 | * @return void 48 | */ 49 | public function read($cacheFile, $vars = []) 50 | { 51 | $this->cacheFile = $cacheFile; 52 | 53 | if (!empty($vars) && is_array($vars)) { 54 | // 模板阵列变量分解成为独立变量 55 | extract($vars, EXTR_OVERWRITE); 56 | } 57 | 58 | //载入模版缓存文件 59 | include $this->cacheFile; 60 | } 61 | 62 | /** 63 | * 检查编译缓存是否有效 64 | * @access public 65 | * @param string $cacheFile 缓存的文件名 66 | * @param int $cacheTime 缓存时间 67 | * @return boolean 68 | */ 69 | public function check($cacheFile, $cacheTime) 70 | { 71 | // 缓存文件不存在, 直接返回false 72 | if (!file_exists($cacheFile)) { 73 | return false; 74 | } 75 | 76 | if (0 != $cacheTime && time() > filemtime($cacheFile) + $cacheTime) { 77 | // 缓存是否在有效期 78 | return false; 79 | } 80 | 81 | return true; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/Lists.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\command; 13 | 14 | use think\console\Command; 15 | use think\console\Input; 16 | use think\console\input\Argument as InputArgument; 17 | use think\console\input\Definition as InputDefinition; 18 | use think\console\input\Option as InputOption; 19 | use think\console\Output; 20 | 21 | class Lists extends Command 22 | { 23 | /** 24 | * {@inheritdoc} 25 | */ 26 | protected function configure() 27 | { 28 | $this->setName('list')->setDefinition($this->createDefinition())->setDescription('Lists commands')->setHelp(<<%command.name% command lists all commands: 30 | 31 | php %command.full_name% 32 | 33 | You can also display the commands for a specific namespace: 34 | 35 | php %command.full_name% test 36 | 37 | It's also possible to get raw list of commands (useful for embedding command runner): 38 | 39 | php %command.full_name% --raw 40 | EOF 41 | ); 42 | } 43 | 44 | /** 45 | * {@inheritdoc} 46 | */ 47 | public function getNativeDefinition() 48 | { 49 | return $this->createDefinition(); 50 | } 51 | 52 | /** 53 | * {@inheritdoc} 54 | */ 55 | protected function execute(Input $input, Output $output) 56 | { 57 | $output->describe($this->getConsole(), [ 58 | 'raw_text' => $input->getOption('raw'), 59 | 'namespace' => $input->getArgument('namespace'), 60 | ]); 61 | } 62 | 63 | /** 64 | * {@inheritdoc} 65 | */ 66 | private function createDefinition() 67 | { 68 | return new InputDefinition([ 69 | new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'), 70 | new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'), 71 | ]); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /thinkphp/library/think/model/concern/TimeStamp.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\model\concern; 13 | 14 | /** 15 | * 自动时间戳 16 | */ 17 | trait TimeStamp 18 | { 19 | /** 20 | * 是否需要自动写入时间戳 如果设置为字符串 则表示时间字段的类型 21 | * @var bool|string 22 | */ 23 | protected $autoWriteTimestamp; 24 | 25 | /** 26 | * 创建时间字段 false表示关闭 27 | * @var false|string 28 | */ 29 | protected $createTime = 'create_time'; 30 | 31 | /** 32 | * 更新时间字段 false表示关闭 33 | * @var false|string 34 | */ 35 | protected $updateTime = 'update_time'; 36 | 37 | /** 38 | * 时间字段显示格式 39 | * @var string 40 | */ 41 | protected $dateFormat; 42 | 43 | /** 44 | * 时间日期字段格式化处理 45 | * @access protected 46 | * @param mixed $time 时间日期表达式 47 | * @param mixed $format 日期格式 48 | * @param bool $timestamp 是否进行时间戳转换 49 | * @return mixed 50 | */ 51 | protected function formatDateTime($time, $format, $timestamp = false) 52 | { 53 | if (empty($time)) { 54 | return; 55 | } 56 | 57 | if (false !== strpos($format, '\\')) { 58 | $time = new $format($time); 59 | } elseif (!$timestamp && false !== $format) { 60 | $time = date($format, $time); 61 | } 62 | 63 | return $time; 64 | } 65 | 66 | /** 67 | * 检查时间字段写入 68 | * @access protected 69 | * @return void 70 | */ 71 | protected function checkTimeStampWrite() 72 | { 73 | // 自动写入创建时间和更新时间 74 | if ($this->autoWriteTimestamp) { 75 | if ($this->createTime && !isset($this->data[$this->createTime])) { 76 | $this->data[$this->createTime] = $this->autoWriteTimestamp($this->createTime); 77 | } 78 | if ($this->updateTime && !isset($this->data[$this->updateTime])) { 79 | $this->data[$this->updateTime] = $this->autoWriteTimestamp($this->updateTime); 80 | } 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/optimize/Route.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | namespace think\console\command\optimize; 12 | 13 | use think\console\Command; 14 | use think\console\Input; 15 | use think\console\Output; 16 | use think\Container; 17 | 18 | class Route extends Command 19 | { 20 | protected function configure() 21 | { 22 | $this->setName('optimize:route') 23 | ->setDescription('Build route cache.'); 24 | } 25 | 26 | protected function execute(Input $input, Output $output) 27 | { 28 | $filename = Container::get('app')->getRuntimePath() . 'route.php'; 29 | if (is_file($filename)) { 30 | unlink($filename); 31 | } 32 | file_put_contents($filename, $this->buildRouteCache()); 33 | $output->writeln('Succeed!'); 34 | } 35 | 36 | protected function buildRouteCache() 37 | { 38 | Container::get('route')->setName([]); 39 | Container::get('route')->setTestMode(true); 40 | // 路由检测 41 | $path = Container::get('app')->getRoutePath(); 42 | 43 | $files = is_dir($path) ? scandir($path) : []; 44 | 45 | foreach ($files as $file) { 46 | if (strpos($file, '.php')) { 47 | $filename = $path . DIRECTORY_SEPARATOR . $file; 48 | // 导入路由配置 49 | $rules = include $filename; 50 | if (is_array($rules)) { 51 | Container::get('route')->import($rules); 52 | } 53 | } 54 | } 55 | 56 | if (Container::get('config')->get('route_annotation')) { 57 | $suffix = Container::get('config')->get('controller_suffix') || Container::get('config')->get('class_suffix'); 58 | include Container::get('build')->buildRoute($suffix); 59 | } 60 | 61 | $content = 'getName(), true) . ';'; 63 | return $content; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /thinkphp/library/think/response/View.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\response; 13 | 14 | use think\Response; 15 | 16 | class View extends Response 17 | { 18 | // 输出参数 19 | protected $options = []; 20 | protected $vars = []; 21 | protected $filter; 22 | protected $contentType = 'text/html'; 23 | 24 | /** 25 | * 处理数据 26 | * @access protected 27 | * @param mixed $data 要处理的数据 28 | * @return mixed 29 | */ 30 | protected function output($data) 31 | { 32 | // 渲染模板输出 33 | return $this->app['view'] 34 | ->filter($this->filter) 35 | ->fetch($data, $this->vars); 36 | } 37 | 38 | /** 39 | * 获取视图变量 40 | * @access public 41 | * @param string $name 模板变量 42 | * @return mixed 43 | */ 44 | public function getVars($name = null) 45 | { 46 | if (is_null($name)) { 47 | return $this->vars; 48 | } else { 49 | return isset($this->vars[$name]) ? $this->vars[$name] : null; 50 | } 51 | } 52 | 53 | /** 54 | * 模板变量赋值 55 | * @access public 56 | * @param mixed $name 变量名 57 | * @param mixed $value 变量值 58 | * @return $this 59 | */ 60 | public function assign($name, $value = '') 61 | { 62 | if (is_array($name)) { 63 | $this->vars = array_merge($this->vars, $name); 64 | } else { 65 | $this->vars[$name] = $value; 66 | } 67 | 68 | return $this; 69 | } 70 | 71 | /** 72 | * 视图内容过滤 73 | * @access public 74 | * @param callable $filter 75 | * @return $this 76 | */ 77 | public function filter($filter) 78 | { 79 | $this->filter = $filter; 80 | return $this; 81 | } 82 | 83 | /** 84 | * 检查模板是否存在 85 | * @access private 86 | * @param string|array $name 参数名 87 | * @return bool 88 | */ 89 | public function exists($name) 90 | { 91 | return $this->app['view']->exists($name); 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /thinkphp/library/think/process/Utils.php: -------------------------------------------------------------------------------- 1 | 8 | // +---------------------------------------------------------------------- 9 | 10 | namespace think\process; 11 | 12 | class Utils 13 | { 14 | 15 | /** 16 | * 转义字符串 17 | * @param string $argument 18 | * @return string 19 | */ 20 | public static function escapeArgument($argument) 21 | { 22 | 23 | if ('' === $argument) { 24 | return escapeshellarg($argument); 25 | } 26 | $escapedArgument = ''; 27 | $quote = false; 28 | foreach (preg_split('/(")/i', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) { 29 | if ('"' === $part) { 30 | $escapedArgument .= '\\"'; 31 | } elseif (self::isSurroundedBy($part, '%')) { 32 | // Avoid environment variable expansion 33 | $escapedArgument .= '^%"' . substr($part, 1, -1) . '"^%'; 34 | } else { 35 | // escape trailing backslash 36 | if ('\\' === substr($part, -1)) { 37 | $part .= '\\'; 38 | } 39 | $quote = true; 40 | $escapedArgument .= $part; 41 | } 42 | } 43 | if ($quote) { 44 | $escapedArgument = '"' . $escapedArgument . '"'; 45 | } 46 | return $escapedArgument; 47 | } 48 | 49 | /** 50 | * 验证并进行规范化Process输入。 51 | * @param string $caller 52 | * @param mixed $input 53 | * @return string 54 | * @throws \InvalidArgumentException 55 | */ 56 | public static function validateInput($caller, $input) 57 | { 58 | if (null !== $input) { 59 | if (is_resource($input)) { 60 | return $input; 61 | } 62 | if (is_scalar($input)) { 63 | return (string) $input; 64 | } 65 | throw new \InvalidArgumentException(sprintf('%s only accepts strings or stream resources.', $caller)); 66 | } 67 | return $input; 68 | } 69 | 70 | private static function isSurroundedBy($arg, $char) 71 | { 72 | return 2 < strlen($arg) && $char === $arg[0] && $char === $arg[strlen($arg) - 1]; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /thinkphp/library/think/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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 超简Api图床 —— 专为Api而生 3 | =============== 4 | 5 | 6 | 超简Api图床 是基于ThinkPHP 5.1实现的一套Api图床程序,主要包含以下特色: 7 | 8 | + 无数据库模式,简单配置,一键搭建 9 | + 第三方接口接入,不占用服务器空间 10 | + 【已经失效】接入搜狗Api平台,无需配置,全球CDN加速,永久不限量图片存储 11 | + 接入新浪Api平台,无需配置,全球CDN加速,永久不限量图片存储 12 | + 支持服务器存储模式,代替普通图床 13 | + 超简单Api使用,提供统一Api实现图片上传 14 | + 通讯密钥过滤恶意上传 15 | + 支持跨域提交访问 16 | + 免费、开源 17 | + 支持简单返回,直接返回图片网址 18 | 19 | > 超简Api图床的运行环境要求PHP5.6以上。 20 | 21 | > 超简图床Java版本已经发布,欢迎使用【 https://github.com/szvone/imgApiJava 】 22 | 23 | ## 安装 24 | 25 | + 下载本套系统源码,解压至网站根目录 26 | + 访问 http://localhost/public/ 进入主页 27 | + 点击系统设置,进入设置页面,进行系统的首次配置,并修改管理员密码和通讯密钥 28 | + 默认管理密码为:123456 29 | + 默认通讯密钥为:123456 30 | + 保存配置后,即可开始使用 31 | 32 | > 如果登陆提示成功后还是一直弹出登陆,请修改php.ini 里面的 always_populate_raw_post_data = -1 (去掉前面的;) 33 | 34 | > 升级说明:请您直接下载新版本覆盖旧版本即可! 35 | 36 | > 如果页面显示【超简图床 -- 为您提供Api服务!】,说明您的服务器默认配置的首页为index.php,请您访问localhost/public/index.html进入主页 37 | 38 | > 官方推荐环境:宝塔面板,Nginx服务器,PHP5.6,使用宝塔面板配置伪静态 39 | ## 使用 40 | 41 | + 根据主页显示的Api接口,调用Api接口,将会返回对应的图片地址 42 | + 使用主页提供的测试工具,手动选择图片上传,会显示对应的图片地址 43 | 44 | > 如果您忘记密码,请您删除runtime下面的cache目录下面的所有文件夹,即可重置配置 45 | 46 | ## Api接口说明 47 | + 请求地址:http://localhost/api (localhost请自行替换成您的域名) 48 | + 请求方式:POST 49 | + 请求参数: 50 | + key=通讯密钥 (后台设置的通讯密钥,默认为123456) 51 | + imgBase64=需要上传图片的base64编码(请对该字段使用urlencode编码) 52 | + onlyUrl=0 (传入1则调用接口只会返回图片地址,传入其他或者不传会返回完整的json数据) 53 | 54 | + 返回数据: 55 | 56 | {"code":1,"msg":"操作成功","img":"http://img04.sogoucdn.com/app/a/100520146/d8e8b0f277d98fefaf73391f3e502ac7"} 57 | 58 | + code:返回1代表成功,-1代表失败 59 | + msg:返回接口调用的具体说明 60 | + img:失败返回null,成功返回图片的图床网址 61 | 62 | 63 | ## 注意 64 | 65 | + 如果图床模式为服务器存储,请务必参考下面的资料将public/uploads目录设定为无权限执行PHP程序目录,保证服务器的安全性 66 | + https://blog.csdn.net/alen_xiaoxin/article/details/60783141 67 | + https://www.jb51.net/article/94061.htm 68 | 69 | + 请您将服务器的伪静态设置设置成ThinkPHP支持的模式,参考以下资料 70 | + https://www.itbulu.com/tp-rwrite.html 71 | 72 | ## 更新记录 73 | + v1.4(2019.02.25) 74 | + 很抱歉搜狗图床已经失效,无法使用外链,更新去除搜狗图床 75 | + 新浪图床上传程序更新,修复新浪图床上传提示服务器繁忙的BUG 76 | + 如果程序无法正常使用如404,资源未找到等错误,请检查您的伪静态设置是否设定成功 77 | 78 | + v1.3(2018.10.27) 79 | + 修复新浪图床上传图片失败的bug 80 | + java版本超简图床发布,使用SpringBoot构建,如果PHP版本使用遇到兼容问题,请您尝试使用Java版 81 | 82 | + v1.2(2018.10.16) 83 | + 增加新浪图床账号cookie自动保持在线机制 84 | + java版本超简图床准备开发,将使用Springboot构建,敬请期待 85 | 86 | + v1.1(2018.10.08) 87 | + Api增加新参数onlyUrl, 88 | + 当onlyUrl为1时,如果上传成功,只返回图片链接,如果上传失败,则返回字符串 null 89 | + 当onlyUrl不为1或者不传入时,返回内容同v1.0版本,请参照Api文档 90 | + 增加开发者调用示例,请在SDK目录查看 91 | + 修复已知Bug 92 | 93 | 94 | + v1.0(2018.10.02) 95 | + 初版发布 96 | 97 | ## 版权信息 98 | 99 | 超简Api图床遵循 MIT License 开源协议发布,并提供免费使用。 100 | 101 | 102 | 版权所有Copyright © 28 by vone (http://szvone.cn) 103 | 104 | All rights reserved。 105 | 106 | -------------------------------------------------------------------------------- /thinkphp/library/think/db/builder/Sqlite.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\db\builder; 13 | 14 | use think\db\Builder; 15 | use think\db\Query; 16 | 17 | /** 18 | * Sqlite数据库驱动 19 | */ 20 | class Sqlite extends Builder 21 | { 22 | 23 | /** 24 | * limit 25 | * @access public 26 | * @param Query $query 查询对象 27 | * @param mixed $limit 28 | * @return string 29 | */ 30 | public function parseLimit(Query $query, $limit) 31 | { 32 | $limitStr = ''; 33 | 34 | if (!empty($limit)) { 35 | $limit = explode(',', $limit); 36 | if (count($limit) > 1) { 37 | $limitStr .= ' LIMIT ' . $limit[1] . ' OFFSET ' . $limit[0] . ' '; 38 | } else { 39 | $limitStr .= ' LIMIT ' . $limit[0] . ' '; 40 | } 41 | } 42 | 43 | return $limitStr; 44 | } 45 | 46 | /** 47 | * 随机排序 48 | * @access protected 49 | * @param Query $query 查询对象 50 | * @return string 51 | */ 52 | protected function parseRand(Query $query) 53 | { 54 | return 'RANDOM()'; 55 | } 56 | 57 | /** 58 | * 字段和表名处理 59 | * @access public 60 | * @param Query $query 查询对象 61 | * @param mixed $key 字段名 62 | * @param bool $strict 严格检测 63 | * @return string 64 | */ 65 | public function parseKey(Query $query, $key, $strict = false) 66 | { 67 | if (is_numeric($key)) { 68 | return $key; 69 | } elseif ($key instanceof Expression) { 70 | return $key->getValue(); 71 | } 72 | 73 | $key = trim($key); 74 | 75 | if (strpos($key, '.')) { 76 | list($table, $key) = explode('.', $key, 2); 77 | 78 | $alias = $query->getOptions('alias'); 79 | 80 | if ('__TABLE__' == $table) { 81 | $table = $query->getOptions('table'); 82 | $table = is_array($table) ? array_shift($table) : $table; 83 | } 84 | 85 | if (isset($alias[$table])) { 86 | $table = $alias[$table]; 87 | } 88 | } 89 | 90 | if (isset($table)) { 91 | $key = $table . '.' . $key; 92 | } 93 | 94 | return $key; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/Clear.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | namespace think\console\command; 12 | 13 | use think\console\Command; 14 | use think\console\Input; 15 | use think\console\input\Option; 16 | use think\console\Output; 17 | use think\facade\App; 18 | use think\facade\Cache; 19 | 20 | class Clear extends Command 21 | { 22 | protected function configure() 23 | { 24 | // 指令配置 25 | $this 26 | ->setName('clear') 27 | ->addOption('path', 'd', Option::VALUE_OPTIONAL, 'path to clear', null) 28 | ->addOption('cache', 'c', Option::VALUE_NONE, 'clear cache file') 29 | ->addOption('route', 'u', Option::VALUE_NONE, 'clear route cache') 30 | ->addOption('log', 'l', Option::VALUE_NONE, 'clear log file') 31 | ->addOption('dir', 'r', Option::VALUE_NONE, 'clear empty dir') 32 | ->setDescription('Clear runtime file'); 33 | } 34 | 35 | protected function execute(Input $input, Output $output) 36 | { 37 | if ($input->getOption('route')) { 38 | Cache::clear('route_cache'); 39 | } else { 40 | if ($input->getOption('cache')) { 41 | $path = App::getRuntimePath() . 'cache'; 42 | } elseif ($input->getOption('log')) { 43 | $path = App::getRuntimePath() . 'log'; 44 | } else { 45 | $path = $input->getOption('path') ?: App::getRuntimePath(); 46 | } 47 | 48 | $rmdir = $input->getOption('dir') ? true : false; 49 | $this->clear(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR, $rmdir); 50 | } 51 | 52 | $output->writeln("Clear Successed"); 53 | } 54 | 55 | protected function clear($path, $rmdir) 56 | { 57 | $files = is_dir($path) ? scandir($path) : []; 58 | 59 | foreach ($files as $file) { 60 | if ('.' != $file && '..' != $file && is_dir($path . $file)) { 61 | array_map('unlink', glob($path . $file . DIRECTORY_SEPARATOR . '*.*')); 62 | if ($rmdir) { 63 | rmdir($path . $file); 64 | } 65 | } elseif ('.gitignore' != $file && is_file($path . $file)) { 66 | unlink($path . $file); 67 | } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /thinkphp/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 如何贡献我的源代码 2 | === 3 | 4 | 此文档介绍了 ThinkPHP 团队的组成以及运转机制,您提交的代码将给 ThinkPHP 项目带来什么好处,以及如何才能加入我们的行列。 5 | 6 | ## 通过 Github 贡献代码 7 | 8 | ThinkPHP 目前使用 Git 来控制程序版本,如果你想为 ThinkPHP 贡献源代码,请先大致了解 Git 的使用方法。我们目前把项目托管在 GitHub 上,任何 GitHub 用户都可以向我们贡献代码。 9 | 10 | 参与的方式很简单,`fork`一份 ThinkPHP 的代码到你的仓库中,修改后提交,并向我们发起`pull request`申请,我们会及时对代码进行审查并处理你的申请并。审查通过后,你的代码将被`merge`进我们的仓库中,这样你就会自动出现在贡献者名单里了,非常方便。 11 | 12 | 我们希望你贡献的代码符合: 13 | 14 | * ThinkPHP 的编码规范 15 | * 适当的注释,能让其他人读懂 16 | * 遵循 Apache2 开源协议 17 | 18 | **如果想要了解更多细节或有任何疑问,请继续阅读下面的内容** 19 | 20 | ### 注意事项 21 | 22 | * 本项目代码格式化标准选用 [**PSR-2**](http://www.kancloud.cn/thinkphp/php-fig-psr/3141); 23 | * 类名和类文件名遵循 [**PSR-4**](http://www.kancloud.cn/thinkphp/php-fig-psr/3144); 24 | * 对于 Issues 的处理,请使用诸如 `fix #xxx(Issue ID)` 的 commit title 直接关闭 issue。 25 | * 系统会自动在 PHP 5.4 5.5 5.6 7.0 和 HHVM 上测试修改,其中 HHVM 下的测试容许报错,请确保你的修改符合 PHP 5.4 ~ 5.6 和 PHP 7.0 的语法规范; 26 | * 管理员不会合并造成 CI faild 的修改,若出现 CI faild 请检查自己的源代码或修改相应的[单元测试文件](tests); 27 | 28 | ## GitHub Issue 29 | 30 | GitHub 提供了 Issue 功能,该功能可以用于: 31 | 32 | * 提出 bug 33 | * 提出功能改进 34 | * 反馈使用体验 35 | 36 | 该功能不应该用于: 37 | 38 | * 提出修改意见(涉及代码署名和修订追溯问题) 39 | * 不友善的言论 40 | 41 | ## 快速修改 42 | 43 | **GitHub 提供了快速编辑文件的功能** 44 | 45 | 1. 登录 GitHub 帐号; 46 | 2. 浏览项目文件,找到要进行修改的文件; 47 | 3. 点击右上角铅笔图标进行修改; 48 | 4. 填写 `Commit changes` 相关内容(Title 必填); 49 | 5. 提交修改,等待 CI 验证和管理员合并。 50 | 51 | **若您需要一次提交大量修改,请继续阅读下面的内容** 52 | 53 | ## 完整流程 54 | 55 | 1. `fork`本项目; 56 | 2. 克隆(`clone`)你 `fork` 的项目到本地; 57 | 3. 新建分支(`branch`)并检出(`checkout`)新分支; 58 | 4. 添加本项目到你的本地 git 仓库作为上游(`upstream`); 59 | 5. 进行修改,若你的修改包含方法或函数的增减,请记得修改[单元测试文件](tests); 60 | 6. 变基(衍合 `rebase`)你的分支到上游 master 分支; 61 | 7. `push` 你的本地仓库到 GitHub; 62 | 8. 提交 `pull request`; 63 | 9. 等待 CI 验证(若不通过则重复 5~7,GitHub 会自动更新你的 `pull request`); 64 | 10. 等待管理员处理,并及时 `rebase` 你的分支到上游 master 分支(若上游 master 分支有修改)。 65 | 66 | *若有必要,可以 `git push -f` 强行推送 rebase 后的分支到自己的 `fork`* 67 | 68 | *绝对不可以使用 `git push -f` 强行推送修改到上游* 69 | 70 | ### 注意事项 71 | 72 | * 若对上述流程有任何不清楚的地方,请查阅 GIT 教程,如 [这个](http://backlogtool.com/git-guide/cn/); 73 | * 对于代码**不同方面**的修改,请在自己 `fork` 的项目中**创建不同的分支**(原因参见`完整流程`第9条备注部分); 74 | * 变基及交互式变基操作参见 [Git 交互式变基](http://pakchoi.me/2015/03/17/git-interactive-rebase/) 75 | 76 | ## 推荐资源 77 | 78 | ### 开发环境 79 | 80 | * XAMPP for Windows 5.5.x 81 | * WampServer (for Windows) 82 | * upupw Apache PHP5.4 ( for Windows) 83 | 84 | 或自行安装 85 | 86 | - Apache / Nginx 87 | - PHP 5.4 ~ 5.6 88 | - MySQL / MariaDB 89 | 90 | *Windows 用户推荐添加 PHP bin 目录到 PATH,方便使用 composer* 91 | 92 | *Linux 用户自行配置环境, Mac 用户推荐使用内置 Apache 配合 Homebrew 安装 PHP 和 MariaDB* 93 | 94 | ### 编辑器 95 | 96 | Sublime Text 3 + phpfmt 插件 97 | 98 | phpfmt 插件参数 99 | 100 | ```json 101 | { 102 | "autocomplete": true, 103 | "enable_auto_align": true, 104 | "format_on_save": true, 105 | "indent_with_space": true, 106 | "psr1_naming": false, 107 | "psr2": true, 108 | "version": 4 109 | } 110 | ``` 111 | 112 | 或其他 编辑器 / IDE 配合 PSR2 自动格式化工具 113 | 114 | ### Git GUI 115 | 116 | * SourceTree 117 | * GitHub Desktop 118 | 119 | 或其他 Git 图形界面客户端 120 | -------------------------------------------------------------------------------- /thinkphp/library/think/model/Collection.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\model; 13 | 14 | use think\Collection as BaseCollection; 15 | use think\Model; 16 | 17 | class Collection extends BaseCollection 18 | { 19 | /** 20 | * 延迟预载入关联查询 21 | * @access public 22 | * @param mixed $relation 关联 23 | * @return $this 24 | */ 25 | public function load($relation) 26 | { 27 | $item = current($this->items); 28 | $item->eagerlyResultSet($this->items, $relation); 29 | 30 | return $this; 31 | } 32 | 33 | /** 34 | * 设置需要隐藏的输出属性 35 | * @access public 36 | * @param array $hidden 属性列表 37 | * @param bool $override 是否覆盖 38 | * @return $this 39 | */ 40 | public function hidden($hidden = [], $override = false) 41 | { 42 | $this->each(function ($model) use ($hidden, $override) { 43 | /** @var Model $model */ 44 | $model->hidden($hidden, $override); 45 | }); 46 | 47 | return $this; 48 | } 49 | 50 | /** 51 | * 设置需要输出的属性 52 | * @access public 53 | * @param array $visible 54 | * @param bool $override 是否覆盖 55 | * @return $this 56 | */ 57 | public function visible($visible = [], $override = false) 58 | { 59 | $this->each(function ($model) use ($visible, $override) { 60 | /** @var Model $model */ 61 | $model->visible($visible, $override); 62 | }); 63 | 64 | return $this; 65 | } 66 | 67 | /** 68 | * 设置需要追加的输出属性 69 | * @access public 70 | * @param array $append 属性列表 71 | * @param bool $override 是否覆盖 72 | * @return $this 73 | */ 74 | public function append($append = [], $override = false) 75 | { 76 | $this->each(function ($model) use ($append, $override) { 77 | /** @var Model $model */ 78 | $model && $model->append($append, $override); 79 | }); 80 | 81 | return $this; 82 | } 83 | 84 | /** 85 | * 设置数据字段获取器 86 | * @access public 87 | * @param string|array $name 字段名 88 | * @param callable $callback 闭包获取器 89 | * @return $this 90 | */ 91 | public function withAttr($name, $callback = null) 92 | { 93 | $this->each(function ($model) use ($name, $callback) { 94 | /** @var Model $model */ 95 | $model && $model->withAttribute($name, $callback); 96 | }); 97 | 98 | return $this; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/output/formatter/Stack.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\output\formatter; 13 | 14 | class Stack 15 | { 16 | 17 | /** 18 | * @var Style[] 19 | */ 20 | private $styles; 21 | 22 | /** 23 | * @var Style 24 | */ 25 | private $emptyStyle; 26 | 27 | /** 28 | * 构造方法 29 | * @param Style|null $emptyStyle 30 | */ 31 | public function __construct(Style $emptyStyle = null) 32 | { 33 | $this->emptyStyle = $emptyStyle ?: new Style(); 34 | $this->reset(); 35 | } 36 | 37 | /** 38 | * 重置堆栈 39 | */ 40 | public function reset() 41 | { 42 | $this->styles = []; 43 | } 44 | 45 | /** 46 | * 推一个样式进入堆栈 47 | * @param Style $style 48 | */ 49 | public function push(Style $style) 50 | { 51 | $this->styles[] = $style; 52 | } 53 | 54 | /** 55 | * 从堆栈中弹出一个样式 56 | * @param Style|null $style 57 | * @return Style 58 | * @throws \InvalidArgumentException 59 | */ 60 | public function pop(Style $style = null) 61 | { 62 | if (empty($this->styles)) { 63 | return $this->emptyStyle; 64 | } 65 | 66 | if (null === $style) { 67 | return array_pop($this->styles); 68 | } 69 | 70 | /** 71 | * @var int $index 72 | * @var Style $stackedStyle 73 | */ 74 | foreach (array_reverse($this->styles, true) as $index => $stackedStyle) { 75 | if ($style->apply('') === $stackedStyle->apply('')) { 76 | $this->styles = array_slice($this->styles, 0, $index); 77 | 78 | return $stackedStyle; 79 | } 80 | } 81 | 82 | throw new \InvalidArgumentException('Incorrectly nested style tag found.'); 83 | } 84 | 85 | /** 86 | * 计算堆栈的当前样式。 87 | * @return Style 88 | */ 89 | public function getCurrent() 90 | { 91 | if (empty($this->styles)) { 92 | return $this->emptyStyle; 93 | } 94 | 95 | return $this->styles[count($this->styles) - 1]; 96 | } 97 | 98 | /** 99 | * @param Style $emptyStyle 100 | * @return Stack 101 | */ 102 | public function setEmptyStyle(Style $emptyStyle) 103 | { 104 | $this->emptyStyle = $emptyStyle; 105 | 106 | return $this; 107 | } 108 | 109 | /** 110 | * @return Style 111 | */ 112 | public function getEmptyStyle() 113 | { 114 | return $this->emptyStyle; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /thinkphp/library/think/Env.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think; 13 | 14 | class Env 15 | { 16 | /** 17 | * 环境变量数据 18 | * @var array 19 | */ 20 | protected $data = []; 21 | 22 | public function __construct() 23 | { 24 | $this->data = $_ENV; 25 | } 26 | 27 | /** 28 | * 读取环境变量定义文件 29 | * @access public 30 | * @param string $file 环境变量定义文件 31 | * @return void 32 | */ 33 | public function load($file) 34 | { 35 | $env = parse_ini_file($file, true); 36 | $this->set($env); 37 | } 38 | 39 | /** 40 | * 获取环境变量值 41 | * @access public 42 | * @param string $name 环境变量名 43 | * @param mixed $default 默认值 44 | * @return mixed 45 | */ 46 | public function get($name = null, $default = null) 47 | { 48 | if (is_null($name)) { 49 | return $this->data; 50 | } 51 | 52 | $name = strtoupper(str_replace('.', '_', $name)); 53 | 54 | if (isset($this->data[$name])) { 55 | return $this->data[$name]; 56 | } 57 | 58 | return $this->getEnv($name, $default); 59 | } 60 | 61 | protected function getEnv($name, $default = null) 62 | { 63 | $result = getenv('PHP_' . $name); 64 | 65 | if (false === $result) { 66 | return $default; 67 | } 68 | 69 | if ('false' === $result) { 70 | $result = false; 71 | } elseif ('true' === $result) { 72 | $result = true; 73 | } 74 | 75 | if (!isset($this->data[$name])) { 76 | $this->data[$name] = $result; 77 | } 78 | 79 | return $result; 80 | } 81 | 82 | /** 83 | * 设置环境变量值 84 | * @access public 85 | * @param string|array $env 环境变量 86 | * @param mixed $value 值 87 | * @return void 88 | */ 89 | public function set($env, $value = null) 90 | { 91 | if (is_array($env)) { 92 | $env = array_change_key_case($env, CASE_UPPER); 93 | 94 | foreach ($env as $key => $val) { 95 | if (is_array($val)) { 96 | foreach ($val as $k => $v) { 97 | $this->data[$key . '_' . strtoupper($k)] = $v; 98 | } 99 | } else { 100 | $this->data[$key] = $val; 101 | } 102 | } 103 | } else { 104 | $name = strtoupper(str_replace('.', '_', $env)); 105 | 106 | $this->data[$name] = $value; 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /thinkphp/library/think/facade/App.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\facade; 13 | 14 | use think\Facade; 15 | 16 | /** 17 | * @see \think\App 18 | * @mixin \think\App 19 | * @method \think\App bind(string $bind) static 绑定模块或者控制器 20 | * @method void initialize() static 初始化应用 21 | * @method void init(string $module='') static 初始化模块 22 | * @method \think\Response run() static 执行应用 23 | * @method \think\App dispatch(\think\route\Dispatch $dispatch) static 设置当前请求的调度信息 24 | * @method void log(mixed $log, string $type = 'info') static 记录调试信息 25 | * @method mixed config(string $name='') static 获取配置参数 26 | * @method \think\route\Dispatch routeCheck() static URL路由检测(根据PATH_INFO) 27 | * @method \think\App routeMust(bool $must = false) static 设置应用的路由检测机制 28 | * @method \think\Model model(string $name = '', string $layer = 'model', bool $appendSuffix = false, string $common = 'common') static 实例化模型 29 | * @method object controller(string $name, string $layer = 'controller', bool $appendSuffix = false, string $empty = '') static 实例化控制器 30 | * @method \think\Validate validate(string $name = '', string $layer = 'validate', bool $appendSuffix = false, string $common = 'common') static 实例化验证器类 31 | * @method \think\db\Query db(mixed $config = [], mixed $name = false) static 数据库初始化 32 | * @method mixed action(string $url, $vars = [], $layer = 'controller', $appendSuffix = false) static 调用模块的操作方法 33 | * @method string parseClass(string $module, string $layer, string $name, bool $appendSuffix = false) static 解析应用类的类名 34 | * @method string version() static 获取框架版本 35 | * @method bool isDebug() static 是否为调试模式 36 | * @method string getModulePath() static 获取当前模块路径 37 | * @method void setModulePath(string $path) static 设置当前模块路径 38 | * @method string getRootPath() static 获取应用根目录 39 | * @method string getAppPath() static 获取应用类库目录 40 | * @method string getRuntimePath() static 获取应用运行时目录 41 | * @method string getThinkPath() static 获取核心框架目录 42 | * @method string getRoutePath() static 获取路由目录 43 | * @method string getConfigPath() static 获取应用配置目录 44 | * @method string getConfigExt() static 获取配置后缀 45 | * @method string setNamespace(string $namespace) static 设置应用类库命名空间 46 | * @method string getNamespace() static 获取应用类库命名空间 47 | * @method string getSuffix() static 是否启用类库后缀 48 | * @method float getBeginTime() static 获取应用开启时间 49 | * @method integer getBeginMem() static 获取应用初始内存占用 50 | * @method \think\Container container() static 获取容器实例 51 | */ 52 | class App extends Facade 53 | { 54 | /** 55 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识) 56 | * @access protected 57 | * @return string 58 | */ 59 | protected static function getFacadeClass() 60 | { 61 | return 'app'; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /public/cover.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Globals 3 | */ 4 | 5 | /* Links */ 6 | a, 7 | a:focus, 8 | a:hover { 9 | color: #fff; 10 | } 11 | 12 | /* Custom default button */ 13 | .btn-default, 14 | .btn-default:hover, 15 | .btn-default:focus { 16 | color: #333; 17 | text-shadow: none; /* Prevent inheritance from `body` */ 18 | background-color: #fff; 19 | border: 1px solid #fff; 20 | } 21 | 22 | 23 | /* 24 | * Base structure 25 | */ 26 | 27 | html, 28 | body { 29 | height: 100%; 30 | background-color: #333; 31 | } 32 | body { 33 | color: #fff; 34 | text-align: center; 35 | text-shadow: 0 1px 3px rgba(0,0,0,.5); 36 | } 37 | 38 | /* Extra markup and styles for table-esque vertical and horizontal centering */ 39 | .site-wrapper { 40 | display: table; 41 | width: 100%; 42 | height: 100%; /* For at least Firefox */ 43 | min-height: 100%; 44 | -webkit-box-shadow: inset 0 0 100px rgba(0,0,0,.5); 45 | box-shadow: inset 0 0 100px rgba(0,0,0,.5); 46 | } 47 | .site-wrapper-inner { 48 | display: table-cell; 49 | vertical-align: top; 50 | } 51 | .cover-container { 52 | margin-right: auto; 53 | margin-left: auto; 54 | } 55 | 56 | /* Padding for spacing */ 57 | .inner { 58 | padding: 30px; 59 | } 60 | 61 | 62 | /* 63 | * Header 64 | */ 65 | .masthead-brand { 66 | margin-top: 10px; 67 | margin-bottom: 10px; 68 | } 69 | 70 | .masthead-nav > li { 71 | display: inline-block; 72 | } 73 | .masthead-nav > li + li { 74 | margin-left: 20px; 75 | } 76 | .masthead-nav > li > a { 77 | padding-right: 0; 78 | padding-left: 0; 79 | font-size: 16px; 80 | font-weight: bold; 81 | color: #fff; /* IE8 proofing */ 82 | color: rgba(255,255,255,.75); 83 | border-bottom: 2px solid transparent; 84 | } 85 | .masthead-nav > li > a:hover, 86 | .masthead-nav > li > a:focus { 87 | background-color: transparent; 88 | border-bottom-color: #a9a9a9; 89 | border-bottom-color: rgba(255,255,255,.25); 90 | } 91 | .masthead-nav > .active > a, 92 | .masthead-nav > .active > a:hover, 93 | .masthead-nav > .active > a:focus { 94 | color: #fff; 95 | border-bottom-color: #fff; 96 | } 97 | 98 | @media (min-width: 768px) { 99 | .masthead-brand { 100 | float: left; 101 | } 102 | .masthead-nav { 103 | float: right; 104 | } 105 | } 106 | 107 | 108 | /* 109 | * Cover 110 | */ 111 | 112 | .cover { 113 | padding: 0 20px; 114 | } 115 | .cover .btn-lg { 116 | padding: 10px 20px; 117 | font-weight: bold; 118 | } 119 | 120 | 121 | /* 122 | * Footer 123 | */ 124 | 125 | .mastfoot { 126 | color: #999; /* IE8 proofing */ 127 | color: rgba(255,255,255,.5); 128 | } 129 | 130 | 131 | /* 132 | * Affix and center 133 | */ 134 | 135 | @media (min-width: 768px) { 136 | /* Pull out the header and footer */ 137 | .masthead { 138 | position: fixed; 139 | top: 0; 140 | } 141 | .mastfoot { 142 | position: fixed; 143 | bottom: 0; 144 | } 145 | /* Start the vertical centering */ 146 | .site-wrapper-inner { 147 | vertical-align: middle; 148 | } 149 | /* Handle the widths */ 150 | .masthead, 151 | .mastfoot, 152 | .cover-container { 153 | width: 100%; /* Must be percentage or pixels for horizontal alignment */ 154 | } 155 | } 156 | 157 | @media (min-width: 992px) { 158 | .masthead, 159 | .mastfoot, 160 | .cover-container { 161 | width: 700px; 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /thinkphp/library/think/db/builder/Pgsql.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\db\builder; 13 | 14 | use think\db\Builder; 15 | use think\db\Query; 16 | 17 | /** 18 | * Pgsql数据库驱动 19 | */ 20 | class Pgsql extends Builder 21 | { 22 | 23 | protected $insertSql = 'INSERT INTO %TABLE% (%FIELD%) VALUES (%DATA%) %COMMENT%'; 24 | protected $insertAllSql = 'INSERT INTO %TABLE% (%FIELD%) %DATA% %COMMENT%'; 25 | 26 | /** 27 | * limit分析 28 | * @access protected 29 | * @param Query $query 查询对象 30 | * @param mixed $limit 31 | * @return string 32 | */ 33 | public function parseLimit(Query $query, $limit) 34 | { 35 | $limitStr = ''; 36 | 37 | if (!empty($limit)) { 38 | $limit = explode(',', $limit); 39 | if (count($limit) > 1) { 40 | $limitStr .= ' LIMIT ' . $limit[1] . ' OFFSET ' . $limit[0] . ' '; 41 | } else { 42 | $limitStr .= ' LIMIT ' . $limit[0] . ' '; 43 | } 44 | } 45 | 46 | return $limitStr; 47 | } 48 | 49 | /** 50 | * 字段和表名处理 51 | * @access public 52 | * @param Query $query 查询对象 53 | * @param mixed $key 字段名 54 | * @param bool $strict 严格检测 55 | * @return string 56 | */ 57 | public function parseKey(Query $query, $key, $strict = false) 58 | { 59 | if (is_numeric($key)) { 60 | return $key; 61 | } elseif ($key instanceof Expression) { 62 | return $key->getValue(); 63 | } 64 | 65 | $key = trim($key); 66 | 67 | if (strpos($key, '->') && false === strpos($key, '(')) { 68 | // JSON字段支持 69 | list($field, $name) = explode('->', $key); 70 | $key = $field . '->>\'' . $name . '\''; 71 | } elseif (strpos($key, '.')) { 72 | list($table, $key) = explode('.', $key, 2); 73 | 74 | $alias = $query->getOptions('alias'); 75 | 76 | if ('__TABLE__' == $table) { 77 | $table = $query->getOptions('table'); 78 | $table = is_array($table) ? array_shift($table) : $table; 79 | } 80 | 81 | if (isset($alias[$table])) { 82 | $table = $alias[$table]; 83 | } 84 | } 85 | 86 | if (isset($table)) { 87 | $key = $table . '.' . $key; 88 | } 89 | 90 | return $key; 91 | } 92 | 93 | /** 94 | * 随机排序 95 | * @access protected 96 | * @param Query $query 查询对象 97 | * @return string 98 | */ 99 | protected function parseRand(Query $query) 100 | { 101 | return 'RANDOM()'; 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /thinkphp/library/think/db/connector/Sqlite.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\db\connector; 13 | 14 | use PDO; 15 | use think\db\Connection; 16 | 17 | /** 18 | * Sqlite数据库驱动 19 | */ 20 | class Sqlite extends Connection 21 | { 22 | 23 | protected $builder = '\\think\\db\\builder\\Sqlite'; 24 | 25 | /** 26 | * 解析pdo连接的dsn信息 27 | * @access protected 28 | * @param array $config 连接信息 29 | * @return string 30 | */ 31 | protected function parseDsn($config) 32 | { 33 | $dsn = 'sqlite:' . $config['database']; 34 | 35 | return $dsn; 36 | } 37 | 38 | /** 39 | * 取得数据表的字段信息 40 | * @access public 41 | * @param string $tableName 42 | * @return array 43 | */ 44 | public function getFields($tableName) 45 | { 46 | list($tableName) = explode(' ', $tableName); 47 | $sql = 'PRAGMA table_info( ' . $tableName . ' )'; 48 | 49 | $pdo = $this->query($sql, [], false, true); 50 | $result = $pdo->fetchAll(PDO::FETCH_ASSOC); 51 | $info = []; 52 | 53 | if ($result) { 54 | foreach ($result as $key => $val) { 55 | $val = array_change_key_case($val); 56 | $info[$val['name']] = [ 57 | 'name' => $val['name'], 58 | 'type' => $val['type'], 59 | 'notnull' => 1 === $val['notnull'], 60 | 'default' => $val['dflt_value'], 61 | 'primary' => '1' == $val['pk'], 62 | 'autoinc' => '1' == $val['pk'], 63 | ]; 64 | } 65 | } 66 | 67 | return $this->fieldCase($info); 68 | } 69 | 70 | /** 71 | * 取得数据库的表信息 72 | * @access public 73 | * @param string $dbName 74 | * @return array 75 | */ 76 | public function getTables($dbName = '') 77 | { 78 | $sql = "SELECT name FROM sqlite_master WHERE type='table' " 79 | . "UNION ALL SELECT name FROM sqlite_temp_master " 80 | . "WHERE type='table' ORDER BY name"; 81 | 82 | $pdo = $this->query($sql, [], false, true); 83 | $result = $pdo->fetchAll(PDO::FETCH_ASSOC); 84 | $info = []; 85 | 86 | foreach ($result as $key => $val) { 87 | $info[$key] = current($val); 88 | } 89 | 90 | return $info; 91 | } 92 | 93 | /** 94 | * SQL性能分析 95 | * @access protected 96 | * @param string $sql 97 | * @return array 98 | */ 99 | protected function getExplain($sql) 100 | { 101 | return []; 102 | } 103 | 104 | protected function supportSavepoint() 105 | { 106 | return true; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /thinkphp/library/think/response/Redirect.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\response; 13 | 14 | use think\Response; 15 | 16 | class Redirect extends Response 17 | { 18 | 19 | protected $options = []; 20 | 21 | // URL参数 22 | protected $params = []; 23 | 24 | public function __construct($data = '', $code = 302, array $header = [], array $options = []) 25 | { 26 | parent::__construct($data, $code, $header, $options); 27 | 28 | $this->cacheControl('no-cache,must-revalidate'); 29 | } 30 | 31 | /** 32 | * 处理数据 33 | * @access protected 34 | * @param mixed $data 要处理的数据 35 | * @return mixed 36 | */ 37 | protected function output($data) 38 | { 39 | $this->header['Location'] = $this->getTargetUrl(); 40 | 41 | return; 42 | } 43 | 44 | /** 45 | * 重定向传值(通过Session) 46 | * @access protected 47 | * @param string|array $name 变量名或者数组 48 | * @param mixed $value 值 49 | * @return $this 50 | */ 51 | public function with($name, $value = null) 52 | { 53 | $session = $this->app['session']; 54 | 55 | if (is_array($name)) { 56 | foreach ($name as $key => $val) { 57 | $session->flash($key, $val); 58 | } 59 | } else { 60 | $session->flash($name, $value); 61 | } 62 | 63 | return $this; 64 | } 65 | 66 | /** 67 | * 获取跳转地址 68 | * @access public 69 | * @return string 70 | */ 71 | public function getTargetUrl() 72 | { 73 | if (strpos($this->data, '://') || (0 === strpos($this->data, '/') && empty($this->params))) { 74 | return $this->data; 75 | } else { 76 | return $this->app['url']->build($this->data, $this->params); 77 | } 78 | } 79 | 80 | public function params($params = []) 81 | { 82 | $this->params = $params; 83 | 84 | return $this; 85 | } 86 | 87 | /** 88 | * 记住当前url后跳转 89 | * @access public 90 | * @return $this 91 | */ 92 | public function remember() 93 | { 94 | $this->app['session']->set('redirect_url', $this->app['request']->url()); 95 | 96 | return $this; 97 | } 98 | 99 | /** 100 | * 跳转到上次记住的url 101 | * @access public 102 | * @param string $url 闪存数据不存在时的跳转地址 103 | * @return $this 104 | */ 105 | public function restore($url = null) 106 | { 107 | $session = $this->app['session']; 108 | 109 | if ($session->has('redirect_url')) { 110 | $this->data = $session->get('redirect_url'); 111 | $session->delete('redirect_url'); 112 | } elseif ($url) { 113 | $this->data = $url; 114 | } 115 | 116 | return $this; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/input/Argument.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\input; 13 | 14 | class Argument 15 | { 16 | 17 | const REQUIRED = 1; 18 | const OPTIONAL = 2; 19 | const IS_ARRAY = 4; 20 | 21 | private $name; 22 | private $mode; 23 | private $default; 24 | private $description; 25 | 26 | /** 27 | * 构造方法 28 | * @param string $name 参数名 29 | * @param int $mode 参数类型: self::REQUIRED 或者 self::OPTIONAL 30 | * @param string $description 描述 31 | * @param mixed $default 默认值 (仅 self::OPTIONAL 类型有效) 32 | * @throws \InvalidArgumentException 33 | */ 34 | public function __construct($name, $mode = null, $description = '', $default = null) 35 | { 36 | if (null === $mode) { 37 | $mode = self::OPTIONAL; 38 | } elseif (!is_int($mode) || $mode > 7 || $mode < 1) { 39 | throw new \InvalidArgumentException(sprintf('Argument mode "%s" is not valid.', $mode)); 40 | } 41 | 42 | $this->name = $name; 43 | $this->mode = $mode; 44 | $this->description = $description; 45 | 46 | $this->setDefault($default); 47 | } 48 | 49 | /** 50 | * 获取参数名 51 | * @return string 52 | */ 53 | public function getName() 54 | { 55 | return $this->name; 56 | } 57 | 58 | /** 59 | * 是否必须 60 | * @return bool 61 | */ 62 | public function isRequired() 63 | { 64 | return self::REQUIRED === (self::REQUIRED & $this->mode); 65 | } 66 | 67 | /** 68 | * 该参数是否接受数组 69 | * @return bool 70 | */ 71 | public function isArray() 72 | { 73 | return self::IS_ARRAY === (self::IS_ARRAY & $this->mode); 74 | } 75 | 76 | /** 77 | * 设置默认值 78 | * @param mixed $default 默认值 79 | * @throws \LogicException 80 | */ 81 | public function setDefault($default = null) 82 | { 83 | if (self::REQUIRED === $this->mode && null !== $default) { 84 | throw new \LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.'); 85 | } 86 | 87 | if ($this->isArray()) { 88 | if (null === $default) { 89 | $default = []; 90 | } elseif (!is_array($default)) { 91 | throw new \LogicException('A default value for an array argument must be an array.'); 92 | } 93 | } 94 | 95 | $this->default = $default; 96 | } 97 | 98 | /** 99 | * 获取默认值 100 | * @return mixed 101 | */ 102 | public function getDefault() 103 | { 104 | return $this->default; 105 | } 106 | 107 | /** 108 | * 获取描述 109 | * @return string 110 | */ 111 | public function getDescription() 112 | { 113 | return $this->description; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /thinkphp/library/think/facade/Route.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\facade; 13 | 14 | use think\Facade; 15 | 16 | /** 17 | * @see \think\Route 18 | * @mixin \think\Route 19 | * @method \think\route\Domain domain(mixed $name, mixed $rule = '', array $option = [], array $pattern = []) static 注册域名路由 20 | * @method \think\Route pattern(mixed $name, string $rule = '') static 注册变量规则 21 | * @method \think\Route option(mixed $name, mixed $value = '') static 注册路由参数 22 | * @method \think\Route bind(string $bind) static 设置路由绑定 23 | * @method mixed getBind(string $bind) static 读取路由绑定 24 | * @method \think\Route name(string $name) static 设置当前路由标识 25 | * @method mixed getName(string $name) static 读取路由标识 26 | * @method void setName(string $name) static 批量导入路由标识 27 | * @method void import(array $rules, string $type = '*') static 导入配置文件的路由规则 28 | * @method \think\route\RuleItem rule(string $rule, mixed $route, string $method = '*', array $option = [], array $pattern = []) static 注册路由规则 29 | * @method void rules(array $rules, string $method = '*', array $option = [], array $pattern = []) static 批量注册路由规则 30 | * @method \think\route\RuleGroup group(string|array $name, mixed $route, string $method = '*', array $option = [], array $pattern = []) static 注册路由分组 31 | * @method \think\route\RuleItem any(string $rule, mixed $route, array $option = [], array $pattern = []) static 注册路由 32 | * @method \think\route\RuleItem get(string $rule, mixed $route, array $option = [], array $pattern = []) static 注册路由 33 | * @method \think\route\RuleItem post(string $rule, mixed $route, array $option = [], array $pattern = []) static 注册路由 34 | * @method \think\route\RuleItem put(string $rule, mixed $route, array $option = [], array $pattern = []) static 注册路由 35 | * @method \think\route\RuleItem delete(string $rule, mixed $route, array $option = [], array $pattern = []) static 注册路由 36 | * @method \think\route\RuleItem patch(string $rule, mixed $route, array $option = [], array $pattern = []) static 注册路由 37 | * @method \think\route\Resource resource(string $rule, mixed $route, array $option = [], array $pattern = []) static 注册资源路由 38 | * @method \think\Route controller(string $rule, mixed $route, array $option = [], array $pattern = []) static 注册控制器路由 39 | * @method \think\Route alias(string $rule, mixed $route, array $option = [], array $pattern = []) static 注册别名路由 40 | * @method \think\Route setMethodPrefix(mixed $method, string $prefix = '') static 设置不同请求类型下面的方法前缀 41 | * @method \think\Route rest(string $name, array $resource = []) static rest方法定义和修改 42 | * @method \think\Route\RuleItem miss(string $route, string $method = '*', array $option = []) static 注册未匹配路由规则后的处理 43 | * @method \think\Route\RuleItem auto(string $route) static 注册一个自动解析的URL路由 44 | * @method \think\Route\Dispatch check(string $url, string $depr = '/', bool $must = false, bool $completeMatch = false) static 检测URL路由 45 | */ 46 | class Route extends Facade 47 | { 48 | /** 49 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识) 50 | * @access protected 51 | * @return string 52 | */ 53 | protected static function getFacadeClass() 54 | { 55 | return 'route'; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /thinkphp/library/think/console/command/Make.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\console\command; 13 | 14 | use think\console\Command; 15 | use think\console\Input; 16 | use think\console\input\Argument; 17 | use think\console\Output; 18 | use think\facade\App; 19 | use think\facade\Config; 20 | use think\facade\Env; 21 | 22 | abstract class Make extends Command 23 | { 24 | 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(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%}', '{%actionSuffix%}', '{%namespace%}', '{%app_namespace%}'], [ 66 | $class, 67 | Config::get('action_suffix'), 68 | $namespace, 69 | App::getNamespace(), 70 | ], $stub); 71 | } 72 | 73 | protected function getPathName($name) 74 | { 75 | $name = str_replace(App::getNamespace() . '\\', '', $name); 76 | 77 | return Env::get('app_path') . ltrim(str_replace('\\', '/', $name), '/') . '.php'; 78 | } 79 | 80 | protected function getClassName($name) 81 | { 82 | $appNamespace = App::getNamespace(); 83 | 84 | if (strpos($name, $appNamespace . '\\') !== false) { 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/Cache.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think; 13 | 14 | use think\cache\Driver; 15 | 16 | /** 17 | * Class Cache 18 | * 19 | * @package think 20 | * 21 | * @mixin Driver 22 | * @mixin \think\cache\driver\File 23 | */ 24 | class Cache 25 | { 26 | /** 27 | * 缓存实例 28 | * @var array 29 | */ 30 | protected $instance = []; 31 | 32 | /** 33 | * 缓存配置 34 | * @var array 35 | */ 36 | protected $config = []; 37 | 38 | /** 39 | * 操作句柄 40 | * @var object 41 | */ 42 | protected $handler; 43 | 44 | public function __construct(array $config = []) 45 | { 46 | $this->config = $config; 47 | $this->init($config); 48 | } 49 | 50 | /** 51 | * 连接缓存 52 | * @access public 53 | * @param array $options 配置数组 54 | * @param bool|string $name 缓存连接标识 true 强制重新连接 55 | * @return Driver 56 | */ 57 | public function connect(array $options = [], $name = false) 58 | { 59 | if (false === $name) { 60 | $name = md5(serialize($options)); 61 | } 62 | 63 | if (true === $name || !isset($this->instance[$name])) { 64 | $type = !empty($options['type']) ? $options['type'] : 'File'; 65 | 66 | if (true === $name) { 67 | $name = md5(serialize($options)); 68 | } 69 | 70 | $this->instance[$name] = Loader::factory($type, '\\think\\cache\\driver\\', $options); 71 | } 72 | 73 | return $this->instance[$name]; 74 | } 75 | 76 | /** 77 | * 自动初始化缓存 78 | * @access public 79 | * @param array $options 配置数组 80 | * @param bool $force 强制更新 81 | * @return Driver 82 | */ 83 | public function init(array $options = [], $force = false) 84 | { 85 | if (is_null($this->handler) || $force) { 86 | 87 | if ('complex' == $options['type']) { 88 | $default = $options['default']; 89 | $options = isset($options[$default['type']]) ? $options[$default['type']] : $default; 90 | } 91 | 92 | $this->handler = $this->connect($options); 93 | } 94 | 95 | return $this->handler; 96 | } 97 | 98 | public static function __make(Config $config) 99 | { 100 | return new static($config->pull('cache')); 101 | } 102 | 103 | public function getConfig() 104 | { 105 | return $this->config; 106 | } 107 | 108 | public function setConfig(array $config) 109 | { 110 | $this->config = array_merge($this->config, $config); 111 | } 112 | 113 | /** 114 | * 切换缓存类型 需要配置 cache.type 为 complex 115 | * @access public 116 | * @param string $name 缓存标识 117 | * @return Driver 118 | */ 119 | public function store($name = '') 120 | { 121 | if ('' !== $name && 'complex' == $this->config['type']) { 122 | return $this->connect($this->config[$name], strtolower($name)); 123 | } 124 | 125 | return $this->init(); 126 | } 127 | 128 | public function __call($method, $args) 129 | { 130 | return call_user_func_array([$this->init(), $method], $args); 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /thinkphp/library/think/Facade.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think; 13 | 14 | class Facade 15 | { 16 | /** 17 | * 绑定对象 18 | * @var array 19 | */ 20 | protected static $bind = []; 21 | 22 | /** 23 | * 始终创建新的对象实例 24 | * @var bool 25 | */ 26 | protected static $alwaysNewInstance; 27 | 28 | /** 29 | * 绑定类的静态代理 30 | * @static 31 | * @access public 32 | * @param string|array $name 类标识 33 | * @param string $class 类名 34 | * @return object 35 | */ 36 | public static function bind($name, $class = null) 37 | { 38 | if (__CLASS__ != static::class) { 39 | return self::__callStatic('bind', func_get_args()); 40 | } 41 | 42 | if (is_array($name)) { 43 | self::$bind = array_merge(self::$bind, $name); 44 | } else { 45 | self::$bind[$name] = $class; 46 | } 47 | } 48 | 49 | /** 50 | * 创建Facade实例 51 | * @static 52 | * @access protected 53 | * @param string $class 类名或标识 54 | * @param array $args 变量 55 | * @param bool $newInstance 是否每次创建新的实例 56 | * @return object 57 | */ 58 | protected static function createFacade($class = '', $args = [], $newInstance = false) 59 | { 60 | $class = $class ?: static::class; 61 | 62 | $facadeClass = static::getFacadeClass(); 63 | 64 | if ($facadeClass) { 65 | $class = $facadeClass; 66 | } elseif (isset(self::$bind[$class])) { 67 | $class = self::$bind[$class]; 68 | } 69 | 70 | if (static::$alwaysNewInstance) { 71 | $newInstance = true; 72 | } 73 | 74 | return Container::getInstance()->make($class, $args, $newInstance); 75 | } 76 | 77 | /** 78 | * 获取当前Facade对应类名(或者已经绑定的容器对象标识) 79 | * @access protected 80 | * @return string 81 | */ 82 | protected static function getFacadeClass() 83 | {} 84 | 85 | /** 86 | * 带参数实例化当前Facade类 87 | * @access public 88 | * @return mixed 89 | */ 90 | public static function instance(...$args) 91 | { 92 | if (__CLASS__ != static::class) { 93 | return self::createFacade('', $args); 94 | } 95 | } 96 | 97 | /** 98 | * 调用类的实例 99 | * @access public 100 | * @param string $class 类名或者标识 101 | * @param array|true $args 变量 102 | * @param bool $newInstance 是否每次创建新的实例 103 | * @return mixed 104 | */ 105 | public static function make($class, $args = [], $newInstance = false) 106 | { 107 | if (__CLASS__ != static::class) { 108 | return self::__callStatic('make', func_get_args()); 109 | } 110 | 111 | if (true === $args) { 112 | // 总是创建新的实例化对象 113 | $newInstance = true; 114 | $args = []; 115 | } 116 | 117 | return self::createFacade($class, $args, $newInstance); 118 | } 119 | 120 | // 调用实际类的方法 121 | public static function __callStatic($method, $params) 122 | { 123 | return call_user_func_array([static::createFacade(), $method], $params); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /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 | // PDO连接参数 25 | protected $params = [ 26 | PDO::ATTR_CASE => PDO::CASE_NATURAL, 27 | PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, 28 | PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, 29 | PDO::ATTR_STRINGIFY_FETCHES => false, 30 | ]; 31 | 32 | /** 33 | * 解析pdo连接的dsn信息 34 | * @access protected 35 | * @param array $config 连接信息 36 | * @return string 37 | */ 38 | protected function parseDsn($config) 39 | { 40 | $dsn = 'pgsql:dbname=' . $config['database'] . ';host=' . $config['hostname']; 41 | 42 | if (!empty($config['hostport'])) { 43 | $dsn .= ';port=' . $config['hostport']; 44 | } 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 | $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 . '\');'; 59 | 60 | $pdo = $this->query($sql, [], false, true); 61 | $result = $pdo->fetchAll(PDO::FETCH_ASSOC); 62 | $info = []; 63 | 64 | if ($result) { 65 | foreach ($result as $key => $val) { 66 | $val = array_change_key_case($val); 67 | $info[$val['field']] = [ 68 | 'name' => $val['field'], 69 | 'type' => $val['type'], 70 | 'notnull' => (bool) ('' !== $val['null']), 71 | 'default' => $val['default'], 72 | 'primary' => !empty($val['key']), 73 | 'autoinc' => (0 === strpos($val['extra'], 'nextval(')), 74 | ]; 75 | } 76 | } 77 | 78 | return $this->fieldCase($info); 79 | } 80 | 81 | /** 82 | * 取得数据库的表信息 83 | * @access public 84 | * @param string $dbName 85 | * @return array 86 | */ 87 | public function getTables($dbName = '') 88 | { 89 | $sql = "select tablename as Tables_in_test from pg_tables where schemaname ='public'"; 90 | $pdo = $this->query($sql, [], false, true); 91 | $result = $pdo->fetchAll(PDO::FETCH_ASSOC); 92 | $info = []; 93 | 94 | foreach ($result as $key => $val) { 95 | $info[$key] = current($val); 96 | } 97 | 98 | return $info; 99 | } 100 | 101 | /** 102 | * SQL性能分析 103 | * @access protected 104 | * @param string $sql 105 | * @return array 106 | */ 107 | protected function getExplain($sql) 108 | { 109 | return []; 110 | } 111 | 112 | protected function supportSavepoint() 113 | { 114 | return true; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /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 | if (is_string($data)) { 45 | if (0 !== strpos($data, 'options['encoding']; 47 | $xml = ""; 48 | $data = $xml . $data; 49 | } 50 | return $data; 51 | } 52 | 53 | // XML数据转换 54 | return $this->xmlEncode($data, $this->options['root_node'], $this->options['item_node'], $this->options['root_attr'], $this->options['item_key'], $this->options['encoding']); 55 | } 56 | 57 | /** 58 | * XML编码 59 | * @access protected 60 | * @param mixed $data 数据 61 | * @param string $root 根节点名 62 | * @param string $item 数字索引的子节点名 63 | * @param string $attr 根节点属性 64 | * @param string $id 数字索引子节点key转换的属性名 65 | * @param string $encoding 数据编码 66 | * @return string 67 | */ 68 | protected function xmlEncode($data, $root, $item, $attr, $id, $encoding) 69 | { 70 | if (is_array($attr)) { 71 | $array = []; 72 | foreach ($attr as $key => $value) { 73 | $array[] = "{$key}=\"{$value}\""; 74 | } 75 | $attr = implode(' ', $array); 76 | } 77 | 78 | $attr = trim($attr); 79 | $attr = empty($attr) ? '' : " {$attr}"; 80 | $xml = ""; 81 | $xml .= "<{$root}{$attr}>"; 82 | $xml .= $this->dataToXml($data, $item, $id); 83 | $xml .= ""; 84 | 85 | return $xml; 86 | } 87 | 88 | /** 89 | * 数据XML编码 90 | * @access protected 91 | * @param mixed $data 数据 92 | * @param string $item 数字索引时的节点名称 93 | * @param string $id 数字索引key转换为的属性名 94 | * @return string 95 | */ 96 | protected function dataToXml($data, $item, $id) 97 | { 98 | $xml = $attr = ''; 99 | 100 | if ($data instanceof Collection || $data instanceof Model) { 101 | $data = $data->toArray(); 102 | } 103 | 104 | foreach ($data as $key => $val) { 105 | if (is_numeric($key)) { 106 | $id && $attr = " {$id}=\"{$key}\""; 107 | $key = $item; 108 | } 109 | $xml .= "<{$key}{$attr}>"; 110 | $xml .= (is_array($val) || is_object($val)) ? $this->dataToXml($val, $item, $id) : $val; 111 | $xml .= ""; 112 | } 113 | 114 | return $xml; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /thinkphp/library/think/session/driver/Memcache.php: -------------------------------------------------------------------------------- 1 | 10 | // +---------------------------------------------------------------------- 11 | 12 | namespace think\session\driver; 13 | 14 | use SessionHandlerInterface; 15 | use think\Exception; 16 | 17 | class Memcache implements SessionHandlerInterface 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 | 47 | $this->handler = new \Memcache; 48 | 49 | // 支持集群 50 | $hosts = explode(',', $this->config['host']); 51 | $ports = explode(',', $this->config['port']); 52 | 53 | if (empty($ports[0])) { 54 | $ports[0] = 11211; 55 | } 56 | 57 | // 建立连接 58 | foreach ((array) $hosts as $i => $host) { 59 | $port = isset($ports[$i]) ? $ports[$i] : $ports[0]; 60 | $this->config['timeout'] > 0 ? 61 | $this->handler->addServer($host, $port, $this->config['persistent'], 1, $this->config['timeout']) : 62 | $this->handler->addServer($host, $port, $this->config['persistent'], 1); 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 | 78 | return true; 79 | } 80 | 81 | /** 82 | * 读取Session 83 | * @access public 84 | * @param string $sessID 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 | return $this->handler->set($this->config['session_name'] . $sessID, $sessData, 0, $this->config['expire']); 101 | } 102 | 103 | /** 104 | * 删除Session 105 | * @access public 106 | * @param string $sessID 107 | * @return bool 108 | */ 109 | public function destroy($sessID) 110 | { 111 | return $this->handler->delete($this->config['session_name'] . $sessID); 112 | } 113 | 114 | /** 115 | * Session 垃圾回收 116 | * @access public 117 | * @param string $sessMaxLifeTime 118 | * @return true 119 | */ 120 | public function gc($sessMaxLifeTime) 121 | { 122 | return true; 123 | } 124 | } 125 | --------------------------------------------------------------------------------