From 631e3d19b9558a5ec45451ef604144e4a73a2229 Mon Sep 17 00:00:00 2001 From: Anyon Date: Mon, 2 Jul 2018 10:10:28 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=9B=B4=E6=96=B0]ComposerUpdate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- thinkphp/library/think/App.php | 71 ++++++----- thinkphp/library/think/Build.php | 2 +- thinkphp/library/think/Request.php | 116 +++++++++++++++++- thinkphp/library/think/Route.php | 14 ++- thinkphp/library/think/Url.php | 16 +-- thinkphp/library/think/View.php | 11 ++ thinkphp/library/think/log/driver/Test.php | 30 ----- .../think/model/concern/Conversion.php | 20 ++- .../think/model/concern/SoftDelete.php | 9 +- thinkphp/library/think/route/Dispatch.php | 10 +- vendor/autoload.php | 2 +- vendor/composer/autoload_real.php | 14 +-- vendor/composer/autoload_static.php | 8 +- vendor/composer/installed.json | 12 +- 14 files changed, 234 insertions(+), 101 deletions(-) delete mode 100644 thinkphp/library/think/log/driver/Test.php diff --git a/thinkphp/library/think/App.php b/thinkphp/library/think/App.php index e5b75d2ba..0c6ab2e2d 100644 --- a/thinkphp/library/think/App.php +++ b/thinkphp/library/think/App.php @@ -20,7 +20,7 @@ use think\route\Dispatch; */ class App extends Container { - const VERSION = '5.1.17'; + const VERSION = '5.1.18'; /** * 当前模块路径 @@ -254,8 +254,8 @@ class App extends Container // 读取语言包 $this->loadLangPack(); - // 监听app_init - $this->hook->listen('app_init'); + // 路由初始化 + $this->routeInit(); } /** @@ -286,7 +286,7 @@ class App extends Container // 加载公共文件 if (is_file($path . 'common.php')) { - include $path . 'common.php'; + include_once $path . 'common.php'; } if ('' == $module) { @@ -378,6 +378,9 @@ class App extends Container // 初始化应用 $this->initialize(); + // 监听app_init + $this->hook->listen('app_init'); + if ($this->bindModule) { // 模块/控制器绑定 $this->route->bind($this->bindModule); @@ -531,6 +534,40 @@ class App extends Container return $this->config->get($name); } + /** + * 路由初始化 导入路由定义规则 + * @access public + * @return void + */ + public function routeInit() + { + // 路由检测 + $files = scandir($this->routePath); + foreach ($files as $file) { + if (strpos($file, '.php')) { + $filename = $this->routePath . $file; + // 导入路由配置 + $rules = include $filename; + if (is_array($rules)) { + $this->route->import($rules); + } + } + } + + if ($this->route->config('route_annotation')) { + // 自动生成路由定义 + if ($this->appDebug) { + $this->build->buildRoute($this->route->config('controller_suffix')); + } + + $filename = $this->runtimePath . 'build_route.php'; + + if (is_file($filename)) { + include $filename; + } + } + } + /** * URL路由检测(根据PATH_INFO) * @access public @@ -551,32 +588,6 @@ class App extends Container // 获取应用调度信息 $path = $this->request->path(); - // 路由检测 - $files = scandir($this->routePath); - foreach ($files as $file) { - if (strpos($file, '.php')) { - $filename = $this->routePath . $file; - // 导入路由配置 - $rules = include $filename; - if (is_array($rules)) { - $this->route->import($rules); - } - } - } - - if ($this->config('route.route_annotation')) { - // 自动生成路由定义 - if ($this->appDebug) { - $this->build->buildRoute($this->config('route.controller_suffix')); - } - - $filename = $this->runtimePath . 'build_route.php'; - - if (is_file($filename)) { - include $filename; - } - } - // 是否强制路由模式 $must = !is_null($this->routeMust) ? $this->routeMust : $this->route->config('url_route_must'); diff --git a/thinkphp/library/think/Build.php b/thinkphp/library/think/Build.php index 0c3244da8..f12c79093 100644 --- a/thinkphp/library/think/Build.php +++ b/thinkphp/library/think/Build.php @@ -273,7 +273,7 @@ class Build if (false !== strpos($comment, '@route(')) { $comment = $this->parseRouteComment($comment); $route = $module . '/' . $controller; - $comment = preg_replace('/route\(\s?([\'\"][\-\_\/\:\<\>\?\$\[\]\w]+[\'\"])\s?\)/is', 'Route::resourece(\1,\'' . $route . '\')', $comment); + $comment = preg_replace('/route\(\s?([\'\"][\-\_\/\:\<\>\?\$\[\]\w]+[\'\"])\s?\)/is', 'Route::resource(\1,\'' . $route . '\')', $comment); $content .= PHP_EOL . $comment; } elseif (false !== strpos($comment, '@alias(')) { $comment = $this->parseRouteComment($comment, '@alias('); diff --git a/thinkphp/library/think/Request.php b/thinkphp/library/think/Request.php index 93fbb95b7..91d10da3e 100644 --- a/thinkphp/library/think/Request.php +++ b/thinkphp/library/think/Request.php @@ -49,6 +49,12 @@ class Request */ protected $method; + /** + * 主机名(含端口) + * @var string + */ + protected $host; + /** * 域名(含协议及端口) * @var string @@ -635,6 +641,12 @@ class Request return $root; } + public function setPathinfo($pathinfo) + { + $this->pathinfo = $pathinfo; + return $this; + } + /** * 获取当前请求URL的pathinfo信息(含URL后缀) * @access public @@ -683,6 +695,7 @@ class Request if (is_null($this->path)) { $suffix = $this->config['url_html_suffix']; $pathinfo = $this->pathinfo(); + if (false === $suffix) { // 禁止伪静态访问 $this->path = $pathinfo; @@ -1680,6 +1693,19 @@ class Request return $this->server('QUERY_STRING'); } + /** + * 设置当前请求的host(包含端口) + * @access public + * @param string $host 主机名(含端口) + * @return $this + */ + public function setHost($host) + { + $this->host = $host; + + return $this; + } + /** * 当前请求的host * @access public @@ -1688,9 +1714,11 @@ class Request */ public function host($strict = false) { - $host = $this->server('HTTP_X_REAL_HOST') ?: $this->server('HTTP_HOST'); + if (!$this->host) { + $this->host = $this->server('HTTP_X_REAL_HOST') ?: $this->server('HTTP_HOST'); + } - return true === $strict && strpos($host, ':') ? strstr($host, ':', true) : $host; + return true === $strict && strpos($this->host, ':') ? strstr($this->host, ':', true) : $this->host; } /** @@ -2003,6 +2031,90 @@ class Request return $this->cache; } + /** + * 设置GET数据 + * @access public + * @param array $get 数据 + * @return $this + */ + public function withGet(array $get) + { + $this->get = $get; + return $this; + } + + /** + * 设置POST数据 + * @access public + * @param array $post 数据 + * @return $this + */ + public function withPost(array $post) + { + $this->post = $post; + return $this; + } + + /** + * 设置COOKIE数据 + * @access public + * @param array $cookie 数据 + * @return $this + */ + public function withCookie(array $cookie) + { + $this->cookie = $cookie; + return $this; + } + + /** + * 设置SERVER数据 + * @access public + * @param array $server 数据 + * @return $this + */ + public function withServer(array $server) + { + $this->server = array_change_key_case($server, CASE_UPPER); + return $this; + } + + /** + * 设置HEADER数据 + * @access public + * @param array $header 数据 + * @return $this + */ + public function withHeader(array $header) + { + $this->header = array_change_key_case($header); + return $this; + } + + /** + * 设置ENV数据 + * @access public + * @param array $env 数据 + * @return $this + */ + public function withEnv(array $env) + { + $this->env = $env; + return $this; + } + + /** + * 设置ROUTE变量 + * @access public + * @param array $route 数据 + * @return $this + */ + public function withRoute(array $route) + { + $this->route = $route; + return $this; + } + /** * 设置请求数据 * @access public diff --git a/thinkphp/library/think/Route.php b/thinkphp/library/think/Route.php index cb0a3748e..43b7614c5 100644 --- a/thinkphp/library/think/Route.php +++ b/thinkphp/library/think/Route.php @@ -130,7 +130,8 @@ class Route $this->app = $app; $this->request = $app['request']; $this->config = $config; - $this->host = $this->request->host(true); + + $this->host = $this->request->host(true) ?: $config['app_host']; $this->setDefaultDomain(); } @@ -167,6 +168,17 @@ class Route return $route; } + /** + * 设置路由的请求对象实例 + * @access public + * @param Request $request 请求对象实例 + * @return void + */ + public function setRequest($request) + { + $this->request = $request; + } + /** * 设置路由域名及分组(包括资源路由)是否延迟解析 * @access public diff --git a/thinkphp/library/think/Url.php b/thinkphp/library/think/Url.php index aa27b3e60..e8159993b 100644 --- a/thinkphp/library/think/Url.php +++ b/thinkphp/library/think/Url.php @@ -126,16 +126,11 @@ class Url } } - if (!empty($rule) && $match = $this->getRuleUrl($rule, $vars)) { + if (!empty($rule) && $match = $this->getRuleUrl($rule, $vars, $domain)) { // 匹配路由命名标识 $url = $match[0]; - if (!empty($match[1])) { - $host = $this->config['app_host'] ?: $this->app['request']->host(true); - if ($domain || $match[1] != $host) { - $domain = $match[1]; - } - } + $domain = $match[1]; if (!is_null($match[2])) { $suffix = $match[2]; @@ -350,10 +345,15 @@ class Url } // 匹配路由地址 - public function getRuleUrl($rule, &$vars = []) + public function getRuleUrl($rule, &$vars = [], $allowDomain = '') { foreach ($rule as $item) { list($url, $pattern, $domain, $suffix) = $item; + + if (is_string($allowDomain) && $domain != $allowDomain) { + continue; + } + if (empty($pattern)) { return [rtrim($url, '?/-'), $domain, $suffix]; } diff --git a/thinkphp/library/think/View.php b/thinkphp/library/think/View.php index 4212438f9..17860a6ba 100644 --- a/thinkphp/library/think/View.php +++ b/thinkphp/library/think/View.php @@ -74,6 +74,17 @@ class View return $this; } + /** + * 清理模板变量 + * @access public + * @return void + */ + public function clear() + { + self::$var = []; + $this->data = []; + } + /** * 模板变量赋值 * @access public diff --git a/thinkphp/library/think/log/driver/Test.php b/thinkphp/library/think/log/driver/Test.php deleted file mode 100644 index e67f74727..000000000 --- a/thinkphp/library/think/log/driver/Test.php +++ /dev/null @@ -1,30 +0,0 @@ - -// +---------------------------------------------------------------------- - -namespace think\log\driver; - -/** - * 模拟测试输出 - */ -class Test -{ - /** - * 日志写入接口 - * @access public - * @param array $log 日志信息 - * @return bool - */ - public function save(array $log = []) - { - return true; - } - -} diff --git a/thinkphp/library/think/model/concern/Conversion.php b/thinkphp/library/think/model/concern/Conversion.php index 7494f76a0..b88528adb 100644 --- a/thinkphp/library/think/model/concern/Conversion.php +++ b/thinkphp/library/think/model/concern/Conversion.php @@ -167,13 +167,25 @@ trait Conversion foreach ($this->append as $key => $name) { if (is_array($name)) { // 追加关联对象属性 - $relation = $this->getAttr($key); - $item[$key] = $relation->visible($name)->append($name)->toArray(); + $relation = $this->getRelation($key); + + if (!$relation) { + $relation = $this->getAttr($key); + $relation->visible($name); + } + + $item[$key] = $relation->append($name)->toArray(); } elseif (strpos($name, '.')) { list($key, $attr) = explode('.', $name); // 追加关联对象属性 - $relation = $this->getAttr($key); - $item[$key] = $relation->visible([$attr])->append([$attr])->toArray(); + $relation = $this->getRelation($key); + + if (!$relation) { + $relation = $this->getAttr($key); + $relation->visible([$attr]); + } + + $item[$key] = $relation->append([$attr])->toArray(); } else { $value = $this->getAttr($name, $item); if (false !== $value) { diff --git a/thinkphp/library/think/model/concern/SoftDelete.php b/thinkphp/library/think/model/concern/SoftDelete.php index c35a2a8ba..7ba032432 100644 --- a/thinkphp/library/think/model/concern/SoftDelete.php +++ b/thinkphp/library/think/model/concern/SoftDelete.php @@ -91,7 +91,7 @@ trait SoftDelete * @access public * @return bool */ - public function delete() + public function delete($force = false) { if (!$this->isExists() || false === $this->trigger('before_delete', $this)) { return false; @@ -99,7 +99,7 @@ trait SoftDelete $name = $this->getDeleteTimeField(); - if ($name && !$this->isForce()) { + if ($name && !$force) { // 软删除 $this->data($name, $this->autoWriteTimestamp($name)); @@ -111,7 +111,10 @@ trait SoftDelete $where = $this->getWhere(); // 删除当前模型数据 - $result = $this->db(false)->where($where)->delete(); + $result = $this->db(false) + ->where($where) + ->removeOption('soft_delete') + ->delete(); } // 关联删除 diff --git a/thinkphp/library/think/route/Dispatch.php b/thinkphp/library/think/route/Dispatch.php index 7f1982cdb..4b187d1e5 100644 --- a/thinkphp/library/think/route/Dispatch.php +++ b/thinkphp/library/think/route/Dispatch.php @@ -126,7 +126,9 @@ abstract class Dispatch // 指定Response响应数据 if (!empty($option['response'])) { - $this->app['hook']->add('response_send', $option['response']); + foreach ($option['response'] as $response) { + $this->app['hook']->add('response_send', $response); + } } // 开启请求缓存 @@ -179,9 +181,9 @@ abstract class Dispatch $response = Response::create($data, $type); } else { $data = ob_get_clean(); - $data = false === $data ? '' : $data; - $status = '' === $data ? 204 : 200; - $response = Response::create($data, '', $status); + $content = false === $data ? '' : $data; + $status = false === $data ? 204 : 200; + $response = Response::create($content, '', $status); } return $response; diff --git a/vendor/autoload.php b/vendor/autoload.php index 0b8729629..aa0d89ae5 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit7c3323b53a4060e1aff01d0992f25786::getLoader(); +return ComposerAutoloaderInitd745dea77639476f6520b2640352c179::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 44746fae5..b86509ea4 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit7c3323b53a4060e1aff01d0992f25786 +class ComposerAutoloaderInitd745dea77639476f6520b2640352c179 { private static $loader; @@ -19,15 +19,15 @@ class ComposerAutoloaderInit7c3323b53a4060e1aff01d0992f25786 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit7c3323b53a4060e1aff01d0992f25786', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInitd745dea77639476f6520b2640352c179', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); - spl_autoload_unregister(array('ComposerAutoloaderInit7c3323b53a4060e1aff01d0992f25786', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInitd745dea77639476f6520b2640352c179', 'loadClassLoader')); $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); if ($useStaticLoader) { require_once __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit7c3323b53a4060e1aff01d0992f25786::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInitd745dea77639476f6520b2640352c179::getInitializer($loader)); } else { $map = require __DIR__ . '/autoload_namespaces.php'; foreach ($map as $namespace => $path) { @@ -48,19 +48,19 @@ class ComposerAutoloaderInit7c3323b53a4060e1aff01d0992f25786 $loader->register(true); if ($useStaticLoader) { - $includeFiles = Composer\Autoload\ComposerStaticInit7c3323b53a4060e1aff01d0992f25786::$files; + $includeFiles = Composer\Autoload\ComposerStaticInitd745dea77639476f6520b2640352c179::$files; } else { $includeFiles = require __DIR__ . '/autoload_files.php'; } foreach ($includeFiles as $fileIdentifier => $file) { - composerRequire7c3323b53a4060e1aff01d0992f25786($fileIdentifier, $file); + composerRequired745dea77639476f6520b2640352c179($fileIdentifier, $file); } return $loader; } } -function composerRequire7c3323b53a4060e1aff01d0992f25786($fileIdentifier, $file) +function composerRequired745dea77639476f6520b2640352c179($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { require $file; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 6b24847a9..32e0007d9 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit7c3323b53a4060e1aff01d0992f25786 +class ComposerStaticInitd745dea77639476f6520b2640352c179 { public static $files = array ( '1cfd2761b63b0a29ed23657ea394cb2d' => __DIR__ . '/..' . '/topthink/think-captcha/src/helper.php', @@ -303,9 +303,9 @@ class ComposerStaticInit7c3323b53a4060e1aff01d0992f25786 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit7c3323b53a4060e1aff01d0992f25786::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit7c3323b53a4060e1aff01d0992f25786::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInit7c3323b53a4060e1aff01d0992f25786::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInitd745dea77639476f6520b2640352c179::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInitd745dea77639476f6520b2640352c179::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInitd745dea77639476f6520b2640352c179::$classMap; }, null, ClassLoader::class); } diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 79c1e9c50..77871aa7e 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -191,17 +191,17 @@ }, { "name": "topthink/framework", - "version": "v5.1.17", - "version_normalized": "5.1.17.0", + "version": "v5.1.18", + "version_normalized": "5.1.18.0", "source": { "type": "git", "url": "https://github.com/top-think/framework.git", - "reference": "61a66e8eeecf1584e0dc150a530f0d116e6ccd01" + "reference": "8c4a90c1214c07d2eae15b25d763348bc084ec2b" }, "dist": { "type": "zip", - "url": "https://files.phpcomposer.com/files/top-think/framework/61a66e8eeecf1584e0dc150a530f0d116e6ccd01.zip", - "reference": "61a66e8eeecf1584e0dc150a530f0d116e6ccd01", + "url": "https://files.phpcomposer.com/files/top-think/framework/8c4a90c1214c07d2eae15b25d763348bc084ec2b.zip", + "reference": "8c4a90c1214c07d2eae15b25d763348bc084ec2b", "shasum": "" }, "require": { @@ -217,7 +217,7 @@ "sebastian/phpcpd": "2.*", "squizlabs/php_codesniffer": "2.*" }, - "time": "2018-06-19T03:11:41+00:00", + "time": "2018-07-01T15:34:18+00:00", "type": "think-framework", "installation-source": "dist", "notification-url": "https://packagist.org/downloads/",