From 18f50d55d0928b05c58bd825000886115774229d Mon Sep 17 00:00:00 2001 From: Anyon Date: Tue, 2 Apr 2019 16:25:51 +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 --- vendor/autoload.php | 2 +- vendor/composer/autoload_real.php | 14 +-- vendor/composer/autoload_static.php | 8 +- vendor/composer/installed.json | 8 +- .../think-library/src/Controller.php | 10 +- .../think-library/src/tools/Cors.php | 91 +++++++------------ 6 files changed, 56 insertions(+), 77 deletions(-) diff --git a/vendor/autoload.php b/vendor/autoload.php index 955efb0ad..8583ae84a 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInitdd2ee3ea59df033b75a787ac77c71af2::getLoader(); +return ComposerAutoloaderInit407a0fe5b8b66687453d756daf4a3b35::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 2000bea18..56cb5ebfe 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInitdd2ee3ea59df033b75a787ac77c71af2 +class ComposerAutoloaderInit407a0fe5b8b66687453d756daf4a3b35 { private static $loader; @@ -19,15 +19,15 @@ class ComposerAutoloaderInitdd2ee3ea59df033b75a787ac77c71af2 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInitdd2ee3ea59df033b75a787ac77c71af2', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit407a0fe5b8b66687453d756daf4a3b35', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); - spl_autoload_unregister(array('ComposerAutoloaderInitdd2ee3ea59df033b75a787ac77c71af2', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit407a0fe5b8b66687453d756daf4a3b35', '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\ComposerStaticInitdd2ee3ea59df033b75a787ac77c71af2::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit407a0fe5b8b66687453d756daf4a3b35::getInitializer($loader)); } else { $map = require __DIR__ . '/autoload_namespaces.php'; foreach ($map as $namespace => $path) { @@ -48,19 +48,19 @@ class ComposerAutoloaderInitdd2ee3ea59df033b75a787ac77c71af2 $loader->register(true); if ($useStaticLoader) { - $includeFiles = Composer\Autoload\ComposerStaticInitdd2ee3ea59df033b75a787ac77c71af2::$files; + $includeFiles = Composer\Autoload\ComposerStaticInit407a0fe5b8b66687453d756daf4a3b35::$files; } else { $includeFiles = require __DIR__ . '/autoload_files.php'; } foreach ($includeFiles as $fileIdentifier => $file) { - composerRequiredd2ee3ea59df033b75a787ac77c71af2($fileIdentifier, $file); + composerRequire407a0fe5b8b66687453d756daf4a3b35($fileIdentifier, $file); } return $loader; } } -function composerRequiredd2ee3ea59df033b75a787ac77c71af2($fileIdentifier, $file) +function composerRequire407a0fe5b8b66687453d756daf4a3b35($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 a7a2c9a75..65da3279a 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInitdd2ee3ea59df033b75a787ac77c71af2 +class ComposerStaticInit407a0fe5b8b66687453d756daf4a3b35 { public static $files = array ( '841780ea2e1d6545ea3a253239d59c05' => __DIR__ . '/..' . '/qiniu/php-sdk/src/Qiniu/functions.php', @@ -346,9 +346,9 @@ class ComposerStaticInitdd2ee3ea59df033b75a787ac77c71af2 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInitdd2ee3ea59df033b75a787ac77c71af2::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInitdd2ee3ea59df033b75a787ac77c71af2::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInitdd2ee3ea59df033b75a787ac77c71af2::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit407a0fe5b8b66687453d756daf4a3b35::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit407a0fe5b8b66687453d756daf4a3b35::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit407a0fe5b8b66687453d756daf4a3b35::$classMap; }, null, ClassLoader::class); } diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 489a0f75d..d18b540be 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -499,12 +499,12 @@ "source": { "type": "git", "url": "https://github.com/zoujingli/ThinkLibrary.git", - "reference": "9ba43129ddcfd571c88b78071ad1f347b106ff26" + "reference": "5d8dbc0707782c5b68ea5600f19001e128ee39c5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/9ba43129ddcfd571c88b78071ad1f347b106ff26", - "reference": "9ba43129ddcfd571c88b78071ad1f347b106ff26", + "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/5d8dbc0707782c5b68ea5600f19001e128ee39c5", + "reference": "5d8dbc0707782c5b68ea5600f19001e128ee39c5", "shasum": "", "mirrors": [ { @@ -523,7 +523,7 @@ "qiniu/php-sdk": "^7.2", "topthink/framework": "5.1.*" }, - "time": "2019-04-01T02:03:01+00:00", + "time": "2019-04-02T08:17:16+00:00", "type": "library", "installation-source": "dist", "autoload": { diff --git a/vendor/zoujingli/think-library/src/Controller.php b/vendor/zoujingli/think-library/src/Controller.php index 473d19e10..d00a0a7ca 100644 --- a/vendor/zoujingli/think-library/src/Controller.php +++ b/vendor/zoujingli/think-library/src/Controller.php @@ -53,8 +53,8 @@ class Controller extends \stdClass */ public function __construct() { - Cors::optionsHandler(); $this->request = request(); + Cors::setOptionHandler($this->request); } /** @@ -86,7 +86,7 @@ class Controller extends \stdClass { $result = ['code' => $code, 'info' => $info, 'data' => $data]; if ($this->_isCsrf) Csrf::clearFormToken(Csrf::getToken()); - throw new \think\exception\HttpResponseException(json($result, 200, Cors::getRequestHeader())); + throw new \think\exception\HttpResponseException(json($result, 200, Cors::getRequestHeader($this->request))); } /** @@ -98,7 +98,7 @@ class Controller extends \stdClass public function error($info, $data = [], $code = 0) { $result = ['code' => $code, 'info' => $info, 'data' => $data]; - throw new \think\exception\HttpResponseException(json($result, 200, Cors::getRequestHeader())); + throw new \think\exception\HttpResponseException(json($result, 200, Cors::getRequestHeader($this->request))); } /** @@ -127,8 +127,8 @@ class Controller extends \stdClass /** * 模板变量赋值 - * @param mixed $name 要显示的模板变量 - * @param mixed $value 变量的值 + * @param mixed $name 要显示的模板变量 + * @param mixed $value 变量的值 * @return $this */ public function assign($name, $value = '') diff --git a/vendor/zoujingli/think-library/src/tools/Cors.php b/vendor/zoujingli/think-library/src/tools/Cors.php index fb9448516..aa2b63cb9 100644 --- a/vendor/zoujingli/think-library/src/tools/Cors.php +++ b/vendor/zoujingli/think-library/src/tools/Cors.php @@ -14,11 +14,10 @@ namespace library\tools; -use think\facade\Log; -use think\facade\Session; +use think\Request; /** - * Cors跨域支持工具 + * 请求跨域支持 * Class Cors * @package library\tools */ @@ -26,57 +25,17 @@ class Cors { /** - * 配置跨域允许头部信息 - * @var array + * Option请求处理 + * @param Request $request */ - private static $allowHeader = [ - 'Host', 'Accept', 'Cookie', 'Origin', 'Pragma', 'Expires', 'Referer', - 'User-Agent', 'Keep-Alive', 'Content-Type', 'Cache-Control', 'Last-Event-ID', - 'Last-Modified', 'Content-Language', 'X-Requested-With', 'If-Modified-Since', - ]; - - /** - * 获取会话令牌 - * @return string - */ - public static function getSessionToken() + public static function setOptionHandler(Request $request) { - if (PHP_SESSION_ACTIVE !== session_status()) Session::init(config('session.')); - return Crypt::encode(session_name() . '=' . session_id()); - } - - /** - * 应用会话令牌 - */ - public static function setSessionToken() - { - try { - if (PHP_SESSION_ACTIVE !== session_status()) Session::init(config('session.')); - if ($token = request()->header('User-Token-Cors', input('_cors_'))) { - list($name, $value) = explode('=', Crypt::decode($token) . '='); - if (!empty($value) && session_name() === $name && session_id() !== $value) { - Session::destroy(); # 注销原来的会话 - session_id($value); # 切换到指定的会话 - Session::init(config('session.')); # 刷新重启会话 - } - } - } catch (\Exception $e) { - Log::error(__METHOD__ . " : {$e->getMessage()}"); - } - } - - /** - * Ajax跨域Options授权处理 - */ - public static function optionsHandler() - { - self::setSessionToken(); - if (request()->isOptions()) { + if ($request->isOptions()) { header('Access-Control-Allow-Credentials:true'); header('Access-Control-Allow-Methods:GET,POST,OPTIONS'); - header('Access-Control-Allow-Origin:' . request()->header('origin', '*')); - header('Access-Control-Allow-Headers:' . join(',', self::$allowHeader)); - header('Access-Control-Expose-Headers:User-Token-Cors,User-Token-Csrf'); + header('Access-Control-Allow-Origin:' . self::getOrigin($request)); + header('Access-Control-Allow-Headers:' . self::getAllows($request)); + header('Access-Control-Expose-Headers: User-Token-Csrf'); header('Content-Type:text/plain charset=UTF-8'); header('Access-Control-Max-Age:1728000'); header('HTTP/1.0 204 No Content'); @@ -87,19 +46,39 @@ class Cors } /** - * Ajax跨域Request头部信息 + * 获取返回Header信息 + * @param Request $request * @return array */ - public static function getRequestHeader() + public static function getRequestHeader(Request $request) { return [ 'Access-Control-Allow-Credentials' => 'true', 'Access-Control-Allow-Methods' => 'GET,POST,OPTIONS', - 'Access-Control-Allow-Origin' => request()->header('origin', '*'), - 'Access-Control-Allow-Headers' => join(',', self::$allowHeader), - 'Access-Control-Expose-Headers' => 'User-Token-Cors,User-Token-Csrf', - 'User-Token-Cors' => self::getSessionToken(), + 'Access-Control-Allow-Origin' => self::getOrigin($request), + 'Access-Control-Allow-Headers' => self::getAllows($request), + 'Access-Control-Expose-Headers' => 'User-Token-Csrf', ]; } + /** + * 获取Origin信息 + * @param Request $request + * @return string + */ + private static function getOrigin(Request $request) + { + return $request->header('origin', '*'); + } + + /** + * 获取Allow信息 + * @param Request $request + * @return string + */ + private static function getAllows(Request $request) + { + return 'Host,Accept,Cookie,Origin,Pragma,Expires,Referer,User-Agent,Keep-Alive,Content-Type,Cache-Control,Last-Event-ID,Last-Modified,Content-Language,X-Requested-With,If-Modified-Since'; + } + } \ No newline at end of file