sugar1569 7 лет назад
Родитель
Сommit
045229fad6

+ 4 - 2
composer.json

@@ -22,9 +22,11 @@
         "topthink/think-image": "^1.0",
         "topthink/think-captcha": "1.*",
         "overtrue/wechat": "^3.3",
+        "tp5er/tp5-databackup": "dev-master",
         "xaboy/form-builder": "^1.2",
-        "tp5er/tp5-databackup": "^1.0",
-        "phpoffice/phpexcel": "^1.8"
+        "phpoffice/phpexcel": "^1.8",
+        "topthink/think-helper": "^1.0",
+        "taskphp/taskphp": "dev-master"
     },
     "extra": {
         "think-path": "thinkphp"

+ 94 - 12
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "ae2e50326d8e83fd299c3350bb0f87d1",
+    "content-hash": "ea77e5047084835254d437402863700f",
     "packages": [
         {
             "name": "doctrine/cache",
@@ -869,18 +869,61 @@
             ],
             "time": "2016-09-14T18:37:20+00:00"
         },
+        {
+            "name": "taskphp/taskphp",
+            "version": "dev-master",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/qq8044023/taskPHP.git",
+                "reference": "0faf4342887c14149273de84aaeb120aa9aa4c19"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/qq8044023/taskPHP/zipball/0faf4342887c14149273de84aaeb120aa9aa4c19",
+                "reference": "0faf4342887c14149273de84aaeb120aa9aa4c19",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=5.6.0"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-0": {
+                    "taskphp\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "cunzhang",
+                    "email": "8044023@qq.com"
+                }
+            ],
+            "description": "taskphp for PHP 5.6",
+            "homepage": "https://github.com/qq8044023/taskPHP",
+            "keywords": [
+                "phptask",
+                "task",
+                "taskphp",
+                "timePHP"
+            ],
+            "time": "2018-11-07T02:59:53+00:00"
+        },
         {
             "name": "topthink/framework",
-            "version": "v5.0.23",
+            "version": "v5.0.24",
             "source": {
                 "type": "git",
                 "url": "https://github.com/top-think/framework.git",
-                "reference": "4cbc0b5e93314446243ebc7d5f005f9c32864737"
+                "reference": "c255c22b2f5fa30f320ecf6c1d29f7740eb3e8be"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/top-think/framework/zipball/4cbc0b5e93314446243ebc7d5f005f9c32864737",
-                "reference": "4cbc0b5e93314446243ebc7d5f005f9c32864737",
+                "url": "https://api.github.com/repos/top-think/framework/zipball/c255c22b2f5fa30f320ecf6c1d29f7740eb3e8be",
+                "reference": "c255c22b2f5fa30f320ecf6c1d29f7740eb3e8be",
                 "shasum": ""
             },
             "require": {
@@ -918,7 +961,7 @@
                 "orm",
                 "thinkphp"
             ],
-            "time": "2018-12-09T12:40:40+00:00"
+            "time": "2019-01-11T08:04:58+00:00"
         },
         {
             "name": "topthink/think-captcha",
@@ -956,6 +999,42 @@
             "description": "captcha package for thinkphp5",
             "time": "2016-07-06T01:47:11+00:00"
         },
+        {
+            "name": "topthink/think-helper",
+            "version": "v1.0.7",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/top-think/think-helper.git",
+                "reference": "5f92178606c8ce131d36b37a57c58eb71e55f019"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/top-think/think-helper/zipball/5f92178606c8ce131d36b37a57c58eb71e55f019",
+                "reference": "5f92178606c8ce131d36b37a57c58eb71e55f019",
+                "shasum": ""
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "think\\helper\\": "src"
+                },
+                "files": [
+                    "src/helper.php"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "Apache-2.0"
+            ],
+            "authors": [
+                {
+                    "name": "yunwuxin",
+                    "email": "448901948@qq.com"
+                }
+            ],
+            "description": "The ThinkPHP5 Helper Package",
+            "time": "2018-10-05T00:43:21+00:00"
+        },
         {
             "name": "topthink/think-image",
             "version": "v1.0.7",
@@ -1078,16 +1157,16 @@
         },
         {
             "name": "tp5er/tp5-databackup",
-            "version": "1.0.0",
+            "version": "dev-master",
             "source": {
                 "type": "git",
                 "url": "https://github.com/tp5er/tp5-databackup.git",
-                "reference": "10abd4383cf78844e1c22584fd823ef1d18e75dc"
+                "reference": "101477abe810fb91bad5c1304a93c5f461db6dc8"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/tp5er/tp5-databackup/zipball/10abd4383cf78844e1c22584fd823ef1d18e75dc",
-                "reference": "10abd4383cf78844e1c22584fd823ef1d18e75dc",
+                "url": "https://api.github.com/repos/tp5er/tp5-databackup/zipball/101477abe810fb91bad5c1304a93c5f461db6dc8",
+                "reference": "101477abe810fb91bad5c1304a93c5f461db6dc8",
                 "shasum": ""
             },
             "require": {
@@ -1110,7 +1189,7 @@
                 }
             ],
             "description": "Implement the database backup restore",
-            "time": "2017-12-29T05:36:58+00:00"
+            "time": "2018-04-07T11:20:53+00:00"
         },
         {
             "name": "xaboy/form-builder",
@@ -1154,7 +1233,10 @@
     "packages-dev": [],
     "aliases": [],
     "minimum-stability": "stable",
-    "stability-flags": [],
+    "stability-flags": {
+        "tp5er/tp5-databackup": 20,
+        "taskphp/taskphp": 20
+    },
     "prefer-stable": false,
     "prefer-lowest": false,
     "platform": {

+ 1 - 1
thinkphp/base.php

@@ -9,7 +9,7 @@
 // | Author: liu21st <liu21st@gmail.com>
 // +----------------------------------------------------------------------
 
-define('THINK_VERSION', '5.0.23');
+define('THINK_VERSION', '5.0.24');
 define('THINK_START_TIME', microtime(true));
 define('THINK_START_MEM', memory_get_usage());
 define('EXT', '.php');

+ 12 - 2
thinkphp/library/think/Collection.php

@@ -99,6 +99,16 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
         return new static(array_keys($this->items));
     }
 
+    /**
+     * 返回数组中所有的值组成的新 Collection 实例
+     * @access public
+     * @return static
+     */
+    public function values()
+    {
+        return new static(array_values($this->items));
+    }
+
     /**
      * 合并数组并返回一个新的 Collection 实例
      * @access public
@@ -273,7 +283,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
 
         $result = [];
         foreach ($this->items as $row) {
-            $key    = $value    = null;
+            $key    = $value = null;
             $keySet = $valueSet = false;
 
             if (null !== $indexKey && array_key_exists($indexKey, $row)) {
@@ -309,7 +319,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
      */
     public function sort(callable $callback = null)
     {
-        $items = $this->items;
+        $items    = $this->items;
         $callback = $callback ?: function ($a, $b) {
             return $a == $b ? 0 : (($a < $b) ? -1 : 1);
         };

+ 9 - 7
thinkphp/library/think/Model.php

@@ -1043,15 +1043,17 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
         }
 
         // 数据自动验证
-        if (!$this->validateData($data)) {
-            return false;
-        }
+        if (!empty($data)) {
+            if (!$this->validateData($data)) {
+                return false;
+            }
 
-        // 数据对象赋值
-        foreach ($data as $key => $value) {
-            $this->setAttr($key, $value, $data);
+            // 数据对象赋值
+            foreach ($data as $key => $value) {
+                $this->setAttr($key, $value, $data);
+            }
         }
-        
+
         if (!empty($where)) {
             $this->isUpdate    = true;
             $this->updateWhere = $where;

+ 17 - 11
thinkphp/library/think/Request.php

@@ -415,7 +415,7 @@ class Request
                 foreach (Config::get('pathinfo_fetch') as $type) {
                     if (!empty($_SERVER[$type])) {
                         $_SERVER['PATH_INFO'] = (0 === strpos($_SERVER[$type], $_SERVER['SCRIPT_NAME'])) ?
-                            substr($_SERVER[$type], strlen($_SERVER['SCRIPT_NAME'])) : $_SERVER[$type];
+                        substr($_SERVER[$type], strlen($_SERVER['SCRIPT_NAME'])) : $_SERVER[$type];
                         break;
                     }
                 }
@@ -522,8 +522,14 @@ class Request
             return $this->server('REQUEST_METHOD') ?: 'GET';
         } elseif (!$this->method) {
             if (isset($_POST[Config::get('var_method')])) {
-                $this->method = strtoupper($_POST[Config::get('var_method')]);
-                $this->{$this->method}($_POST);
+                $method = strtoupper($_POST[Config::get('var_method')]);
+                if (in_array($method, ['GET', 'POST', 'DELETE', 'PUT', 'PATCH'])) {
+                    $this->method = $method;
+                    $this->{$this->method}($_POST);
+                } else {
+                    $this->method = 'POST';
+                }
+                unset($_POST[Config::get('var_method')]);
             } elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
                 $this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
             } else {
@@ -672,8 +678,8 @@ class Request
     public function route($name = '', $default = null, $filter = '')
     {
         if (is_array($name)) {
-            $this->param      = [];
-            $this->mergeParam = false;
+            $this->param        = [];
+            $this->mergeParam   = false;
             return $this->route = array_merge($this->route, $name);
         }
         return $this->input($this->route, $name, $default, $filter);
@@ -719,8 +725,8 @@ class Request
             }
         }
         if (is_array($name)) {
-            $this->param      = [];
-            $this->mergeParam = false;
+            $this->param       = [];
+            $this->mergeParam  = false;
             return $this->post = array_merge($this->post, $name);
         }
         return $this->input($this->post, $name, $default, $filter);
@@ -792,8 +798,8 @@ class Request
             $this->request = $_REQUEST;
         }
         if (is_array($name)) {
-            $this->param      = [];
-            $this->mergeParam = false;
+            $this->param          = [];
+            $this->mergeParam     = false;
             return $this->request = array_merge($this->request, $name);
         }
         return $this->input($this->request, $name, $default, $filter);
@@ -1294,7 +1300,7 @@ class Request
      */
     public function ip($type = 0, $adv = true)
     {
-        $type = $type ? 1 : 0;
+        $type      = $type ? 1 : 0;
         static $ip = null;
         if (null !== $ip) {
             return $ip[$type];
@@ -1633,7 +1639,7 @@ class Request
                 throw new \think\exception\HttpResponseException($response);
             } elseif (Cache::has($key)) {
                 list($content, $header) = Cache::get($key);
-                $response = Response::create($content)->header($header);
+                $response               = Response::create($content)->header($header);
                 throw new \think\exception\HttpResponseException($response);
             } else {
                 $this->cache = [$key, $expire, $tag];

+ 6 - 2
thinkphp/library/think/Validate.php

@@ -880,12 +880,16 @@ class Validate
             // 支持多个字段验证
             $fields = explode('^', $key);
             foreach ($fields as $key) {
-                $map[$key] = $data[$key];
+                if (isset($data[$key])) {
+                    $map[$key] = $data[$key];
+                }
             }
         } elseif (strpos($key, '=')) {
             parse_str($key, $map);
-        } else {
+        } elseif (isset($data[$field])) {
             $map[$key] = $data[$field];
+        } else {
+            $map = [];
         }
 
         $pk = isset($rule[3]) ? $rule[3] : $db->getPk();

+ 1 - 1
thinkphp/library/think/db/Query.php

@@ -54,7 +54,7 @@ class Query
     // 回调事件
     private static $event = [];
     // 读取主库
-    private static $readMaster = [];
+    protected static $readMaster = [];
 
     /**
      * 构造函数

+ 8 - 1
thinkphp/library/think/model/relation/HasMany.php

@@ -202,7 +202,14 @@ class HasMany extends Relation
      */
     public function save($data)
     {
-        $model = $this->make($data);
+        if ($data instanceof Model) {
+            $data = $data->getData();
+        }
+
+        // 保存关联表数据
+        $data[$this->foreignKey] = $this->parent->{$this->localKey};
+
+        $model = new $this->model();
         return $model->save($data) ? $model : false;
     }
 

+ 12 - 2
thinkphp/library/think/model/relation/MorphMany.php

@@ -245,9 +245,19 @@ class MorphMany extends Relation
      */
     public function save($data)
     {
-        $model = $this->make($data);
+        if ($data instanceof Model) {
+            $data = $data->getData();
+        }
+
+        // 保存关联表数据
+        $pk = $this->parent->getPk();
+
+        $data[$this->morphKey]  = $this->parent->$pk;
+        $data[$this->morphType] = $this->type;
+
+        $model = new $this->model();
 
-        return $model->save($data) ? $model : false;
+        return $model->save() ? $model : false;
     }
 
     /**

+ 12 - 1
thinkphp/library/think/model/relation/MorphOne.php

@@ -199,7 +199,18 @@ class MorphOne extends Relation
      */
     public function save($data)
     {
-        $model = $this->make($data);
+        if ($data instanceof Model) {
+            $data = $data->getData();
+        }
+
+        // 保存关联表数据
+        $pk = $this->parent->getPk();
+
+        $data[$this->morphKey]  = $this->parent->$pk;
+        $data[$this->morphType] = $this->type;
+
+        $model = new $this->model();
+
         return $model->save() ? $model : false;
     }