From 76b7f02ea4fed4612815e8bf01ac2fe9c0215e11 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 6 Oct 2016 19:48:11 +0800 Subject: [PATCH 0001/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9Bjoin=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=92=8Calias=E6=96=B9=E6=B3=95=E7=9A=84=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=20=E6=94=B9=E8=BF=9B=E8=BD=AF=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E7=9A=84base=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Builder.php | 73 ++++++++++++++++++----------- library/think/db/Query.php | 51 +++++++++++++++----- library/think/db/builder/Mysql.php | 11 ++++- library/think/db/builder/Pgsql.php | 11 ++++- library/think/db/builder/Sqlite.php | 21 +++++++++ library/think/db/builder/Sqlsrv.php | 14 +++++- library/traits/model/SoftDelete.php | 7 ++- 7 files changed, 140 insertions(+), 48 deletions(-) diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index 15a240ad..4f57c84a 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -89,7 +89,7 @@ abstract class Builder $result = []; foreach ($data as $key => $val) { - $item = $this->parseKey($key); + $item = $this->parseKey($key, $options); if (!in_array($key, $fields, true)) { if ($options['strict']) { throw new Exception('fields not exists:[' . $key . ']'); @@ -115,9 +115,10 @@ abstract class Builder * 字段名分析 * @access protected * @param string $key + * @param array $options * @return string */ - protected function parseKey($key) + protected function parseKey($key, $options = []) { return $key; } @@ -146,10 +147,11 @@ abstract class Builder /** * field分析 * @access protected - * @param mixed $fields + * @param mixed $fields + * @param array $options * @return string */ - protected function parseField($fields) + protected function parseField($fields, $options = []) { if ('*' == $fields || empty($fields)) { $fieldsStr = '*'; @@ -158,9 +160,9 @@ abstract class Builder $array = []; foreach ($fields as $key => $field) { if (!is_numeric($key)) { - $array[] = $this->parseKey($key) . ' AS ' . $this->parseKey($field); + $array[] = $this->parseKey($key, $options) . ' AS ' . $this->parseKey($field, $options); } else { - $array[] = $this->parseKey($field); + $array[] = $this->parseKey($field, $options); } } $fieldsStr = implode(',', $array); @@ -172,9 +174,10 @@ abstract class Builder * table分析 * @access protected * @param mixed $table + * @param array $options * @return string */ - protected function parseTable($tables) + protected function parseTable($tables, $options = []) { if (is_array($tables)) { // 支持别名定义 @@ -183,12 +186,16 @@ abstract class Builder $this->parseKey($table) . ' ' . $this->parseKey($alias) : $this->parseKey($alias); } - $tables = $array; + $tables = implode(',', $array); } elseif (is_string($tables)) { $tables = $this->parseSqlTable($tables); - $tables = array_map([$this, 'parseKey'], explode(',', $tables)); + if (isset($options['alias'][$tables])) { + $tables = $this->parseKey($tables) . ' ' . $this->parseKey($options['alias'][$tables]); + } else { + $tables = $this->parseKey($tables); + } } - return implode(',', $tables); + return $tables; } /** @@ -263,7 +270,7 @@ abstract class Builder protected function parseWhereItem($field, $val, $rule = '', $options = [], $binds = [], $bindName = null) { // 字段分析 - $key = $field ? $this->parseKey($field) : ''; + $key = $field ? $this->parseKey($field, $options) : ''; // 查询规则和条件 if (!is_array($val)) { @@ -425,14 +432,24 @@ abstract class Builder /** * join分析 * @access protected - * @param mixed $join + * @param array $join + * @param array $options 查询条件 * @return string */ - protected function parseJoin($join) + protected function parseJoin($join, $options = []) { $joinStr = ''; if (!empty($join)) { - $joinStr = ' ' . implode(' ', $join) . ' '; + foreach ($join as $item) { + list($table, $type, $on) = $item; + if (!empty($options['alias'])) { + foreach ($options['alias'] as $key => $val) { + $on = str_replace($key . '.', $this->parseKey($val, $options) . '.', $on); + } + } + $table = $this->parseTable($table, $options); + $joinStr .= ' ' . $type . ' JOIN ' . $table . ' ON ' . $on; + } } return $joinStr; } @@ -450,13 +467,13 @@ abstract class Builder foreach ($order as $key => $val) { if (is_numeric($key)) { if (false === strpos($val, '(')) { - $array[] = $this->parseKey($val); + $array[] = $this->parseKey($val, $options); } elseif ('[rand]' == $val) { $array[] = $this->parseRand(); } } else { $sort = in_array(strtolower(trim($val)), ['asc', 'desc']) ? ' ' . $val : ''; - $array[] = $this->parseKey($key) . ' ' . $sort; + $array[] = $this->parseKey($key, $options) . ' ' . $sort; } } $order = implode(',', $array); @@ -572,10 +589,10 @@ abstract class Builder $sql = str_replace( ['%TABLE%', '%DISTINCT%', '%FIELD%', '%JOIN%', '%WHERE%', '%GROUP%', '%HAVING%', '%ORDER%', '%LIMIT%', '%UNION%', '%LOCK%', '%COMMENT%', '%FORCE%'], [ - $this->parseTable($options['table']), + $this->parseTable($options['table'], $options), $this->parseDistinct($options['distinct']), - $this->parseField($options['field']), - $this->parseJoin($options['join']), + $this->parseField($options['field'], $options), + $this->parseJoin($options['join'], $options), $this->parseWhere($options['where'], $options), $this->parseGroup($options['group']), $this->parseHaving($options['having']), @@ -611,7 +628,7 @@ abstract class Builder ['%INSERT%', '%TABLE%', '%FIELD%', '%DATA%', '%COMMENT%'], [ $replace ? 'REPLACE' : 'INSERT', - $this->parseTable($options['table']), + $this->parseTable($options['table'], $options), implode(' , ', $fields), implode(' , ', $values), $this->parseComment($options['comment']), @@ -657,7 +674,7 @@ abstract class Builder $sql = str_replace( ['%TABLE%', '%FIELD%', '%DATA%', '%COMMENT%'], [ - $this->parseTable($options['table']), + $this->parseTable($options['table'], $options), implode(' , ', $fields), implode(' UNION ALL ', $values), $this->parseComment($options['comment']), @@ -681,7 +698,7 @@ abstract class Builder } $fields = array_map([$this, 'parseKey'], $fields); - $sql = 'INSERT INTO ' . $this->parseTable($table) . ' (' . implode(',', $fields) . ') ' . $this->select($options); + $sql = 'INSERT INTO ' . $this->parseTable($table, $options) . ' (' . implode(',', $fields) . ') ' . $this->select($options); return $sql; } @@ -694,7 +711,7 @@ abstract class Builder */ public function update($data, $options) { - $table = $this->parseTable($options['table']); + $table = $this->parseTable($options['table'], $options); $data = $this->parseData($data, $options); if (empty($data)) { return ''; @@ -706,9 +723,9 @@ abstract class Builder $sql = str_replace( ['%TABLE%', '%SET%', '%JOIN%', '%WHERE%', '%ORDER%', '%LIMIT%', '%LOCK%', '%COMMENT%'], [ - $this->parseTable($options['table']), + $this->parseTable($options['table'], $options), implode(',', $set), - $this->parseJoin($options['join']), + $this->parseJoin($options['join'], $options), $this->parseWhere($options['where'], $options), $this->parseOrder($options['order']), $this->parseLimit($options['limit']), @@ -730,9 +747,9 @@ abstract class Builder $sql = str_replace( ['%TABLE%', '%USING%', '%JOIN%', '%WHERE%', '%ORDER%', '%LIMIT%', '%LOCK%', '%COMMENT%'], [ - $this->parseTable($options['table']), - !empty($options['using']) ? ' USING ' . $this->parseTable($options['using']) . ' ' : '', - $this->parseJoin($options['join']), + $this->parseTable($options['table'], $options), + !empty($options['using']) ? ' USING ' . $this->parseTable($options['using'], $options) . ' ' : '', + $this->parseJoin($options['join'], $options), $this->parseWhere($options['where'], $options), $this->parseOrder($options['order']), $this->parseLimit($options['limit']), diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 2e9308cc..1af39e58 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -668,7 +668,9 @@ class Query if (is_array($join)) { if (0 !== $key = key($join)) { // 设置了键名则键名为表名,键值作为表的别名 - $table = $key . ' ' . array_shift($join); + $table = $key; + $alias = array_shift($join); + $this->alias([$table => $alias]); } else { $table = array_shift($join); } @@ -689,11 +691,15 @@ class Query } else { $table = $join; } + if (strpos($table, ' ')) { + list($table, $alias) = explode(' ', $table); + $this->alias([$table => $alias]); + } } if (is_array($condition)) { $condition = implode(' AND ', $condition); } - $this->options['join'][] = strtoupper($type) . ' JOIN ' . $table . ' ON ' . $condition; + $this->options['join'][] = [$table, strtoupper($type), $condition]; } return $this; } @@ -1021,11 +1027,29 @@ class Query /** * 指定当前操作的数据表 * @access public - * @param string $table 表名 + * @param mixed $table 表名 * @return $this */ public function table($table) { + if (is_string($table)) { + if (strpos($table, ',')) { + $tables = explode(',', $table); + $table = []; + foreach ($tables as $item) { + list($item, $alias) = explode(' ', trim($item)); + if ($alias) { + $this->alias([$item => $alias]); + $table[$item] = $alias; + } else { + $table[] = $item; + } + } + } elseif (strpos($table, ' ')) { + list($table, $alias) = explode(' ', $table); + $this->alias([$table => $alias]); + } + } $this->options['table'] = $table; return $this; } @@ -1145,12 +1169,20 @@ class Query /** * 指定数据表别名 * @access public - * @param string $alias 数据表别名 + * @param mixed $alias 数据表别名 * @return $this */ public function alias($alias) { - $this->options['alias'] = $alias; + if (is_array($alias)) { + foreach ($alias as $key => $val) { + $this->options['alias'][$key] = $val; + } + } else { + $table = isset($this->options['table']) ? $this->options['table'] : $this->getTable(); + + $this->options['alias'][$table] = $alias; + } return $this; } @@ -1630,8 +1662,8 @@ class Query { $pk = $this->getPk($options); // 获取当前数据表 - if (!empty($options['alias'])) { - $alias = $options['alias']; + if (!empty($options['alias'][$options['table']])) { + $alias = $options['alias'][$options['table']]; } if (is_string($pk)) { $key = isset($alias) ? $alias . '.' . $pk : $pk; @@ -2201,11 +2233,6 @@ class Query } } - // 表别名 - if (!empty($options['alias'])) { - $options['table'] .= ' ' . $options['alias']; - } - if (!isset($options['field'])) { $options['field'] = '*'; } diff --git a/library/think/db/builder/Mysql.php b/library/think/db/builder/Mysql.php index 04586906..7744be9a 100644 --- a/library/think/db/builder/Mysql.php +++ b/library/think/db/builder/Mysql.php @@ -24,19 +24,28 @@ class Mysql extends Builder * 字段和表名处理 * @access protected * @param string $key + * @param array $options * @return string */ - protected function parseKey($key) + protected function parseKey($key, $options = []) { $key = trim($key); if (strpos($key, '$.') && false === strpos($key, '(')) { // JSON字段支持 list($field, $name) = explode('$.', $key); $key = 'json_extract(' . $field . ', \'$.' . $name . '\')'; + } elseif (strpos($key, '.')) { + list($table, $key) = explode('.', $key, 2); + if (isset($options['alias'][$table])) { + $table = $options['alias'][$table]; + } } if (!preg_match('/[,\'\"\*\(\)`.\s]/', $key)) { $key = '`' . $key . '`'; } + if (isset($table)) { + $key = '`' . $table . '`.' . $key; + } return $key; } diff --git a/library/think/db/builder/Pgsql.php b/library/think/db/builder/Pgsql.php index 0a955a5b..e6e7dffa 100644 --- a/library/think/db/builder/Pgsql.php +++ b/library/think/db/builder/Pgsql.php @@ -43,15 +43,24 @@ class Pgsql extends Builder * 字段和表名处理 * @access protected * @param string $key + * @param array $options * @return string */ - protected function parseKey($key) + protected function parseKey($key, $options = []) { $key = trim($key); if (strpos($key, '$.') && false === strpos($key, '(')) { // JSON字段支持 list($field, $name) = explode('$.', $key); $key = $field . '->>\'' . $name . '\''; + } elseif (strpos($key, '.')) { + list($table, $key) = explode('.', $key, 2); + if (isset($options['alias'][$table])) { + $table = $options['alias'][$table]; + } + } + if (isset($table)) { + $key = $table . '.' . $key; } return $key; } diff --git a/library/think/db/builder/Sqlite.php b/library/think/db/builder/Sqlite.php index 17e59cb2..c9f55027 100644 --- a/library/think/db/builder/Sqlite.php +++ b/library/think/db/builder/Sqlite.php @@ -48,4 +48,25 @@ class Sqlite extends Builder return 'RANDOM()'; } + /** + * 字段和表名处理 + * @access protected + * @param string $key + * @param array $options + * @return string + */ + protected function parseKey($key, $options = []) + { + $key = trim($key); + if (strpos($key, '.')) { + list($table, $key) = explode('.', $key, 2); + if (isset($options['alias'][$table])) { + $table = $options['alias'][$table]; + } + } + if (isset($table)) { + $key = $table . '.' . $key; + } + return $key; + } } diff --git a/library/think/db/builder/Sqlsrv.php b/library/think/db/builder/Sqlsrv.php index bf630d90..3ef28f7c 100644 --- a/library/think/db/builder/Sqlsrv.php +++ b/library/think/db/builder/Sqlsrv.php @@ -61,17 +61,27 @@ class Sqlsrv extends Builder } /** - * 字段名分析 + * 字段和表名处理 * @access protected * @param string $key + * @param array $options * @return string */ - protected function parseKey($key) + protected function parseKey($key, $options = []) { $key = trim($key); + if (strpos($key, '.')) { + list($table, $key) = explode('.', $key, 2); + if (isset($options['alias'][$table])) { + $table = $options['alias'][$table]; + } + } if (!is_numeric($key) && !preg_match('/[,\'\"\*\(\)\[.\s]/', $key)) { $key = '[' . $key . ']'; } + if (isset($table)) { + $key = '[' . $table . '].' . $key; + } return $key; } diff --git a/library/traits/model/SoftDelete.php b/library/traits/model/SoftDelete.php index e08d96aa..4bb072dc 100644 --- a/library/traits/model/SoftDelete.php +++ b/library/traits/model/SoftDelete.php @@ -133,10 +133,9 @@ trait SoftDelete */ protected function getDeleteTimeField($read = false) { - if (isset($this->deleteTime)) { - $field = $this->deleteTime; - } else { - $field = 'delete_time'; + $field = isset($this->deleteTime) ? $this->deleteTime : 'delete_time'; + if (!strpos($field, '.')) { + $field = $this->db(false)->getTable() . '.' . $field; } if (!$read && strpos($field, '.')) { list($alias, $field) = explode('.', $field); -- Gitee From e6976918de9a3ad7c255f90b113bf02a92c57714 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 6 Oct 2016 20:18:54 +0800 Subject: [PATCH 0002/1170] =?UTF-8?q?=E5=A2=9E=E5=8A=A0yaml=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=A0=BC=E5=BC=8F=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Config.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/library/think/Config.php b/library/think/Config.php index 5ab032fd..d7c3dc56 100644 --- a/library/think/Config.php +++ b/library/think/Config.php @@ -60,10 +60,12 @@ class Config } if (is_file($file)) { $type = pathinfo($file, PATHINFO_EXTENSION); - if ('php' != $type) { - return self::parse($file, $type, $name, $range); - } else { + if ('php' == $type) { return self::set(include $file, $name, $range); + } elseif ('yaml' == $type && function_exists('yaml_parse_file')) { + return self::set(yaml_parse_file($file), $name, $range); + } else { + return self::parse($file, $type, $name, $range); } } else { return self::$config[$range]; -- Gitee From 32e001cdc68ef41308b2d80b21290f5555d6309f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 6 Oct 2016 20:37:12 +0800 Subject: [PATCH 0003/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9Btable=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E7=9A=84=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Builder.php | 26 +++++++++++--------------- library/think/db/Query.php | 11 +++++++++++ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index 4f57c84a..80defb75 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -173,29 +173,25 @@ abstract class Builder /** * table分析 * @access protected - * @param mixed $table + * @param mixed $tables * @param array $options * @return string */ protected function parseTable($tables, $options = []) { - if (is_array($tables)) { - // 支持别名定义 - foreach ($tables as $table => $alias) { - $array[] = !is_numeric($table) ? - $this->parseKey($table) . ' ' . $this->parseKey($alias) : - $this->parseKey($alias); - } - $tables = implode(',', $array); - } elseif (is_string($tables)) { - $tables = $this->parseSqlTable($tables); - if (isset($options['alias'][$tables])) { - $tables = $this->parseKey($tables) . ' ' . $this->parseKey($options['alias'][$tables]); + if (is_string($tables)) { + $tables = (array) $tables; + } + $item = []; + foreach ($tables as $table) { + $table = $this->parseSqlTable($table); + if (isset($options['alias'][$table])) { + $item[] = $this->parseKey($table) . ' ' . $this->parseKey($options['alias'][$table]); } else { - $tables = $this->parseKey($tables); + $item[] = $this->parseKey($table); } } - return $tables; + return implode(',', $item); } /** diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 1af39e58..c6b49ebf 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1049,6 +1049,17 @@ class Query list($table, $alias) = explode(' ', $table); $this->alias([$table => $alias]); } + } else { + $tables = $table; + $table = []; + foreach ($tables as $key => $val) { + if (is_numeric($key)) { + $table[] = $val; + } else { + $this->alias([$key => $val]); + $table[] = $key; + } + } } $this->options['table'] = $table; return $this; -- Gitee From 7c49bd442067c1d4ca05ec9ad590156155b21a24 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 6 Oct 2016 21:50:10 +0800 Subject: [PATCH 0004/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9Bjoin=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Builder.php | 16 +++++++--------- library/think/db/Query.php | 3 --- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index 80defb75..75c4aa86 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -179,11 +179,8 @@ abstract class Builder */ protected function parseTable($tables, $options = []) { - if (is_string($tables)) { - $tables = (array) $tables; - } $item = []; - foreach ($tables as $table) { + foreach ((array) $tables as $table) { $table = $this->parseSqlTable($table); if (isset($options['alias'][$table])) { $item[] = $this->parseKey($table) . ' ' . $this->parseKey($options['alias'][$table]); @@ -438,13 +435,14 @@ abstract class Builder if (!empty($join)) { foreach ($join as $item) { list($table, $type, $on) = $item; - if (!empty($options['alias'])) { - foreach ($options['alias'] as $key => $val) { - $on = str_replace($key . '.', $this->parseKey($val, $options) . '.', $on); - } + $condition = []; + foreach ((array) $on as $val) { + list($val1, $val2) = explode('=', $val, 2); + $condition[] = $this->parseKey($val1, $options) . '=' . $this->parseKey($val2, $options); } + $table = $this->parseTable($table, $options); - $joinStr .= ' ' . $type . ' JOIN ' . $table . ' ON ' . $on; + $joinStr .= ' ' . $type . ' JOIN ' . $table . ' ON ' . implode(' AND ', $condition); } } return $joinStr; diff --git a/library/think/db/Query.php b/library/think/db/Query.php index c6b49ebf..79933838 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -696,9 +696,6 @@ class Query $this->alias([$table => $alias]); } } - if (is_array($condition)) { - $condition = implode(' AND ', $condition); - } $this->options['join'][] = [$table, strtoupper($type), $condition]; } return $this; -- Gitee From fb3170bcfcfd7a274955c552383b84ff83f19f6c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 6 Oct 2016 22:37:46 +0800 Subject: [PATCH 0005/1170] =?UTF-8?q?=E9=AA=8C=E8=AF=81=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=94=AF=E6=8C=81=E5=A4=9A=E8=AF=AD=E8=A8=80?= =?UTF-8?q?=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index 5fa15424..3c6e847a 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -12,6 +12,7 @@ namespace think; use think\File; +use think\Lang; use think\Request; use think\Session; @@ -376,6 +377,9 @@ class Validate // 验证失败 返回错误信息 if (isset($msg[$i])) { $message = $msg[$i]; + if (is_string($message) && strpos($message, '{%')) { + $message = Lang::get(substr($message, 2, -1)); + } } else { $message = $this->getRuleMsg($field, $title, $info, $rule); } @@ -1163,7 +1167,11 @@ class Validate } else { $msg = $title . '规则错误'; } - // TODO 多语言支持 + + if (is_string($msg) && strpos($msg, '{%')) { + $msg = Lang::get(substr($msg, 2, -1)); + } + if (is_string($msg) && false !== strpos($msg, ':')) { // 变量替换 if (strpos($rule, ',')) { -- Gitee From 7af500de84bdb3cc17c67530b54b7fe1ac62d396 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 7 Oct 2016 11:28:30 +0800 Subject: [PATCH 0006/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Query=E7=B1=BBparse?= =?UTF-8?q?Order=E6=96=B9=E6=B3=95=E4=B8=80=E5=A4=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Builder.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index 75c4aa86..f38e20bc 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -452,9 +452,10 @@ abstract class Builder * order分析 * @access protected * @param mixed $order + * @param array $options 查询条件 * @return string */ - protected function parseOrder($order) + protected function parseOrder($order, $options = []) { if (is_array($order)) { $array = []; @@ -590,7 +591,7 @@ abstract class Builder $this->parseWhere($options['where'], $options), $this->parseGroup($options['group']), $this->parseHaving($options['having']), - $this->parseOrder($options['order']), + $this->parseOrder($options['order'], $options), $this->parseLimit($options['limit']), $this->parseUnion($options['union']), $this->parseLock($options['lock']), @@ -721,7 +722,7 @@ abstract class Builder implode(',', $set), $this->parseJoin($options['join'], $options), $this->parseWhere($options['where'], $options), - $this->parseOrder($options['order']), + $this->parseOrder($options['order'], $options), $this->parseLimit($options['limit']), $this->parseLock($options['lock']), $this->parseComment($options['comment']), @@ -745,7 +746,7 @@ abstract class Builder !empty($options['using']) ? ' USING ' . $this->parseTable($options['using'], $options) . ' ' : '', $this->parseJoin($options['join'], $options), $this->parseWhere($options['where'], $options), - $this->parseOrder($options['order']), + $this->parseOrder($options['order'], $options), $this->parseLimit($options['limit']), $this->parseLock($options['lock']), $this->parseComment($options['comment']), -- Gitee From 14f4302156592146a5ee02ab89d8ec049262c0d1 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 7 Oct 2016 11:43:08 +0800 Subject: [PATCH 0007/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BparseKey=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/builder/Mysql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/db/builder/Mysql.php b/library/think/db/builder/Mysql.php index 7744be9a..a3e223ed 100644 --- a/library/think/db/builder/Mysql.php +++ b/library/think/db/builder/Mysql.php @@ -34,7 +34,7 @@ class Mysql extends Builder // JSON字段支持 list($field, $name) = explode('$.', $key); $key = 'json_extract(' . $field . ', \'$.' . $name . '\')'; - } elseif (strpos($key, '.')) { + } elseif (strpos($key, '.') && !preg_match('/[,\'\"\(\)`\s]/', $key)) { list($table, $key) = explode('.', $key, 2); if (isset($options['alias'][$table])) { $table = $options['alias'][$table]; -- Gitee From de7d3e39e0c15e1f1a1f595816d8bf83e71fa6ae Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 7 Oct 2016 11:47:44 +0800 Subject: [PATCH 0008/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9Bsqlsrv=E9=A9=B1?= =?UTF-8?q?=E5=8A=A8=E7=B1=BBparseKey=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/builder/Sqlsrv.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/db/builder/Sqlsrv.php b/library/think/db/builder/Sqlsrv.php index 3ef28f7c..c53f3848 100644 --- a/library/think/db/builder/Sqlsrv.php +++ b/library/think/db/builder/Sqlsrv.php @@ -70,7 +70,7 @@ class Sqlsrv extends Builder protected function parseKey($key, $options = []) { $key = trim($key); - if (strpos($key, '.')) { + if (strpos($key, '.') && !preg_match('/[,\'\"\(\)\[\s]/', $key)) { list($table, $key) = explode('.', $key, 2); if (isset($options['alias'][$table])) { $table = $options['alias'][$table]; -- Gitee From cd13dfbcd8fc28f26ac89daf58313de9d4f3e25b Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 7 Oct 2016 13:53:51 +0800 Subject: [PATCH 0009/1170] =?UTF-8?q?=E6=9B=B4=E6=96=B0composer.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 444d6889..9552f0de 100644 --- a/composer.json +++ b/composer.json @@ -27,5 +27,10 @@ "sebastian/phpcpd": "2.*", "squizlabs/php_codesniffer": "2.*", "phpdocumentor/reflection-docblock": "^2.0" - } + }, + "autoload": { + "psr-4": { + "think\\": "library/think" + } + } } -- Gitee From 13ef244b80f23b59f42220e10a63055230f48915 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 7 Oct 2016 14:45:57 +0800 Subject: [PATCH 0010/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E7=9A=84url=E5=88=86=E9=9A=94=E7=AC=A6=E5=8F=82=E6=95=B0=20?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E8=A7=84=E5=88=99=E6=94=AF=E6=8C=81=E5=8D=95?= =?UTF-8?q?=E7=8B=AC=E8=AE=BE=E7=BD=AEurl=E5=88=86=E9=9A=94=E7=AC=A6?= =?UTF-8?q?=EF=BC=8C=E5=8F=82=E6=95=B0=E4=B8=BA=20param=5Fdepr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修正url分隔符设置后 使用 / 仍然可以访问的问题,确保URL访问唯一性 --- library/think/Route.php | 70 ++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index c18a2d67..6a48960a 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -798,11 +798,9 @@ class Route public static function check($request, $url, $depr = '/', $checkDomain = false) { // 分隔符替换 确保路由定义使用统一的分隔符 - if ('/' != $depr) { - $url = str_replace($depr, '/', $url); - } + $url = str_replace($depr, '|', $url); - if (strpos($url, '/') && isset(self::$rules['alias'][strstr($url, '/', true)])) { + if (strpos($url, '|') && isset(self::$rules['alias'][strstr($url, '|', true)])) { // 检测路由别名 $result = self::checkRouteAlias($request, $url, $depr); if (false !== $result) { @@ -821,8 +819,8 @@ class Route if (false !== $return) { return $return; } - if ('/' != $url) { - $url = rtrim($url, '/'); + if ('|' != $url) { + $url = rtrim($url, '|'); } if (isset($rules[$url])) { // 静态路由规则检测 @@ -912,7 +910,7 @@ class Route if (isset($options['bind_model']) && isset($option['bind_model'])) { $option['bind_model'] = array_merge($options['bind_model'], $option['bind_model']); } - $result = self::checkRule($rule, $route, $url, $pattern, $option); + $result = self::checkRule($rule, $route, $url, $pattern, $option, $depr); if (false !== $result) { return $result; } @@ -938,7 +936,7 @@ class Route */ private static function checkRouteAlias($request, $url, $depr) { - $array = explode('/', $url, 2); + $array = explode('|', $url, 2); $item = self::$rules['alias'][$array[0]]; if (is_array($item)) { @@ -1000,7 +998,8 @@ class Route */ public static function bindToClass($url, $class, $depr = '/') { - $array = explode($depr, $url, 2); + $url = str_replace($depr, '|', $url); + $array = explode('|', $url, 2); $action = !empty($array[0]) ? $array[0] : Config::get('default_action'); if (!empty($array[1])) { self::parseUrlParams($array[1]); @@ -1018,7 +1017,8 @@ class Route */ public static function bindToNamespace($url, $namespace, $depr = '/') { - $array = explode($depr, $url, 3); + $url = str_replace($depr, '|', $url); + $array = explode('|', $url, 3); $class = !empty($array[0]) ? $array[0] : Config::get('default_controller'); $method = !empty($array[1]) ? $array[1] : Config::get('default_action'); if (!empty($array[2])) { @@ -1037,7 +1037,8 @@ class Route */ public static function bindToController($url, $controller, $depr = '/') { - $array = explode($depr, $url, 2); + $url = str_replace($depr, '|', $url); + $array = explode('|', $url, 2); $action = !empty($array[0]) ? $array[0] : Config::get('default_action'); if (!empty($array[1])) { self::parseUrlParams($array[1]); @@ -1055,7 +1056,8 @@ class Route */ public static function bindToModule($url, $controller, $depr = '/') { - $array = explode($depr, $url, 2); + $url = str_replace($depr, '|', $url); + $array = explode('|', $url, 2); $action = !empty($array[0]) ? $array[0] : Config::get('default_action'); if (!empty($array[1])) { self::parseUrlParams($array[1]); @@ -1095,21 +1097,22 @@ class Route * @param string $url URL地址 * @param array $pattern 变量规则 * @param array $option 路由参数 + * @param string $depr URL分隔符(全局) * @return array|false */ - private static function checkRule($rule, $route, $url, $pattern, $option) + private static function checkRule($rule, $route, $url, $pattern, $option, $depr) { // 检查完整规则定义 if (isset($pattern['__url__']) && !preg_match('/^' . $pattern['__url__'] . '/', $url)) { return false; } - // 检测是否设置了参数分隔符 - if ($depr = Config::get('url_params_depr')) { - $url = str_replace($depr, '/', $url); - $rule = str_replace($depr, '/', $rule); + // 检查路由的参数分隔符 + if (isset($option['param_depr'])) { + $url = str_replace('|', $depr, $url); + $url = str_replace($option['param_depr'], '|', $url); } - $len1 = substr_count($url, '/'); + $len1 = substr_count($url, '|'); $len2 = substr_count($rule, '/'); // 多余参数是否合并 $merge = !empty($option['merge_extra_vars']) ? true : false; @@ -1140,12 +1143,13 @@ class Route */ public static function parseUrl($url, $depr = '/', $autoSearch = false) { + if (isset(self::$bind['module'])) { // 如果有模块/控制器绑定 $url = self::$bind['module'] . '/' . ltrim($url, '/'); } - - list($path, $var) = self::parseUrlPath($url, $depr); + $url = str_replace($depr, '|', $url); + list($path, $var) = self::parseUrlPath($url); $route = [null, null, null]; if (isset($path)) { // 解析模块 @@ -1171,7 +1175,7 @@ class Route // 解析操作 $action = !empty($path) ? array_shift($path) : null; // 解析额外参数 - self::parseUrlParams(empty($path) ? '' : implode('/', $path)); + self::parseUrlParams(empty($path) ? '' : implode('|', $path)); // 封装路由 $route = [$module, $controller, $action]; if (isset(self::$rules['name'][implode($depr, $route)])) { @@ -1185,15 +1189,12 @@ class Route * 解析URL的pathinfo参数和变量 * @access private * @param string $url URL地址 - * @param string $depr URL分隔符 * @return array */ - private static function parseUrlPath($url, $depr = '/') + private static function parseUrlPath($url) { // 分隔符替换 确保路由定义使用统一的分隔符 - if ('/' != $depr) { - $url = str_replace($depr, '/', $url); - } + $url = str_replace('|', '/', $url); $url = trim($url, '/'); $var = []; if (false !== strpos($url, '?')) { @@ -1225,7 +1226,7 @@ class Route private static function match($url, $rule, $pattern, $merge) { $m2 = explode('/', $rule); - $m1 = $merge ? explode('/', $url, count($m2)) : explode('/', $url); + $m1 = $merge ? explode('|', $url, count($m2)) : explode('|', $url); $var = []; foreach ($m2 as $key => $val) { @@ -1300,7 +1301,7 @@ class Route if ($rule) { $rule = explode('/', $rule); // 获取URL地址中的参数 - $paths = $merge ? explode('/', $pathinfo, count($rule)) : explode('/', $pathinfo); + $paths = $merge ? explode('|', $pathinfo, count($rule)) : explode('|', $pathinfo); foreach ($rule as $item) { $fun = ''; if (0 === strpos($item, '[:')) { @@ -1315,7 +1316,7 @@ class Route } } } else { - $paths = explode('/', $pathinfo); + $paths = explode('|', $pathinfo); } // 获取路由地址规则 @@ -1372,7 +1373,7 @@ class Route } // 解析额外参数 - self::parseUrlParams(empty($paths) ? '' : implode('/', $paths), $matches); + self::parseUrlParams(empty($paths) ? '' : implode('|', $paths), $matches); // 记录匹配的路由信息 $request->routeInfo(['rule' => $rule, 'route' => $route, 'option' => $option, 'var' => $matches]); @@ -1432,12 +1433,11 @@ class Route * 解析URL地址为 模块/控制器/操作 * @access private * @param string $url URL地址 - * @param string $depr URL分隔符 * @return array */ - private static function parseModule($url, $depr = '/') + private static function parseModule($url) { - list($path, $var) = self::parseUrlPath($url, $depr); + list($path, $var) = self::parseUrlPath($url); $action = array_pop($path); $controller = !empty($path) ? array_pop($path) : null; $module = Config::get('app_multi_module') && !empty($path) ? array_pop($path) : null; @@ -1463,9 +1463,9 @@ class Route { if ($url) { if (Config::get('url_param_type')) { - $var += explode('/', $url); + $var += explode('|', $url); } else { - preg_replace_callback('/(\w+)\/([^\/]+)/', function ($match) use (&$var) { + preg_replace_callback('/(\w+)\|([^\|]+)/', function ($match) use (&$var) { $var[$match[1]] = strip_tags($match[2]); }, $url); } -- Gitee From 84904130983a9b7c743c10bb8e76e747262448d3 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 7 Oct 2016 15:13:47 +0800 Subject: [PATCH 0011/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E5=88=86=E7=BB=84=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Route.php b/library/think/Route.php index 6a48960a..3db38183 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -889,7 +889,7 @@ class Route } else { $str = $key; } - if (is_string($str) && $str && 0 !== strpos($url, $str)) { + if (is_string($str) && $str && 0 !== strpos(str_replace('|', '/', $url), $str)) { continue; } -- Gitee From 2dc434435e8420fed79be5eebef6886b5d1e951e Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 7 Oct 2016 15:26:55 +0800 Subject: [PATCH 0012/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=AE=8C=E6=95=B4U?= =?UTF-8?q?RL=E8=A7=84=E5=88=99=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index 3db38183..2a454af7 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1103,13 +1103,12 @@ class Route private static function checkRule($rule, $route, $url, $pattern, $option, $depr) { // 检查完整规则定义 - if (isset($pattern['__url__']) && !preg_match('/^' . $pattern['__url__'] . '/', $url)) { + if (isset($pattern['__url__']) && !preg_match('/^' . $pattern['__url__'] . '/', str_replace('|', $depr, $url))) { return false; } // 检查路由的参数分隔符 if (isset($option['param_depr'])) { - $url = str_replace('|', $depr, $url); - $url = str_replace($option['param_depr'], '|', $url); + $url = str_replace(['|', $option['param_depr']], [$depr, '|'], $url); } $len1 = substr_count($url, '|'); -- Gitee From 8f59235a0a8fa850f382a330f01e2beabcbf0af6 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 8 Oct 2016 10:34:57 +0800 Subject: [PATCH 0013/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3sqlsrv=E9=A9=B1?= =?UTF-8?q?=E5=8A=A8parseOrder=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/builder/Sqlsrv.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/library/think/db/builder/Sqlsrv.php b/library/think/db/builder/Sqlsrv.php index c53f3848..d2f418f3 100644 --- a/library/think/db/builder/Sqlsrv.php +++ b/library/think/db/builder/Sqlsrv.php @@ -27,22 +27,23 @@ class Sqlsrv extends Builder * order分析 * @access protected * @param mixed $order + * @param array $options * @return string */ - protected function parseOrder($order) + protected function parseOrder($order, $options = []) { if (is_array($order)) { $array = []; foreach ($order as $key => $val) { if (is_numeric($key)) { if (false === strpos($val, '(')) { - $array[] = $this->parseKey($val); + $array[] = $this->parseKey($val, $options); } elseif ('[rand]' == $val) { $array[] = $this->parseRand(); } } else { $sort = in_array(strtolower(trim($val)), ['asc', 'desc']) ? ' ' . $val : ''; - $array[] = $this->parseKey($key) . ' ' . $sort; + $array[] = $this->parseKey($key, $options) . ' ' . $sort; } } $order = implode(',', $array); -- Gitee From 01c3d3494027710d274dc7fb0fa28ad3188d321a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 8 Oct 2016 14:45:14 +0800 Subject: [PATCH 0014/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BModel=E7=B1=BB?= =?UTF-8?q?=E7=9A=84save=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index f062e3c5..b9b55c44 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -680,15 +680,13 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $where = $this->updateWhere; } - if (!empty($where)) { - $pk = $this->getPk(); - if (is_string($pk) && isset($data[$pk])) { - if (!isset($where[$pk])) { - unset($where); - $where[$pk] = $data[$pk]; - } - unset($data[$pk]); + $pk = $this->getPk(); + if (is_string($pk) && isset($data[$pk])) { + if (!isset($where[$pk])) { + unset($where); + $where[$pk] = $data[$pk]; } + unset($data[$pk]); } $result = $this->db()->where($where)->update($data); -- Gitee From b810c9a3ca2b4a1ae2977856d1725221e81e3f11 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 8 Oct 2016 15:49:41 +0800 Subject: [PATCH 0015/1170] =?UTF-8?q?=E7=AE=80=E5=8C=96Route=E7=B1=BB?= =?UTF-8?q?=E7=9A=84=E5=90=88=E5=B9=B6=E5=8F=82=E6=95=B0=E5=A4=84=E7=90=86?= =?UTF-8?q?=20=E6=94=B9=E8=BF=9B=E5=90=88=E5=B9=B6=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E7=9A=84=E6=AD=A3=E7=A1=AE=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index 2a454af7..883082e7 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1115,6 +1115,10 @@ class Route $len2 = substr_count($rule, '/'); // 多余参数是否合并 $merge = !empty($option['merge_extra_vars']) ? true : false; + if ($merge && $len1 > $len2) { + $url = str_replace('|', $depr, $url); + $url = implode('|', explode($depr, $url, $len2 + 1)); + } if ($len1 >= $len2 || strpos($rule, '[')) { if (!empty($option['complete_match'])) { @@ -1219,13 +1223,12 @@ class Route * @param string $url URL地址 * @param string $rule 路由规则 * @param array $pattern 变量规则 - * @param bool $merge 合并额外变量 * @return array|false */ - private static function match($url, $rule, $pattern, $merge) + private static function match($url, $rule, $pattern) { $m2 = explode('/', $rule); - $m1 = $merge ? explode('|', $url, count($m2)) : explode('|', $url); + $m1 = explode('|', $url); $var = []; foreach ($m2 as $key => $val) { @@ -1290,17 +1293,16 @@ class Route * @param string $pathinfo URL地址 * @param array $option 路由参数 * @param array $matches 匹配的变量 - * @param bool $merge 合并额外变量 * @return array */ - private static function parseRule($rule, $route, $pathinfo, $option = [], $matches = [], $merge = false) + private static function parseRule($rule, $route, $pathinfo, $option = [], $matches = []) { $request = Request::instance(); // 解析路由规则 if ($rule) { $rule = explode('/', $rule); // 获取URL地址中的参数 - $paths = $merge ? explode('|', $pathinfo, count($rule)) : explode('|', $pathinfo); + $paths = explode('|', $pathinfo); foreach ($rule as $item) { $fun = ''; if (0 === strpos($item, '[:')) { -- Gitee From 6f9fc912df83880d2cc162ea98470ae85bfdaed5 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 8 Oct 2016 21:53:27 +0800 Subject: [PATCH 0016/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BparseTable=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=92=8CparseJoin=20=E5=85=B3=E8=81=94=E9=A2=84?= =?UTF-8?q?=E8=BD=BD=E5=85=A5=E6=94=AF=E6=8C=81hasOne=E8=87=AA=E5=85=B3?= =?UTF-8?q?=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Builder.php | 15 ++++++++++----- library/think/db/Query.php | 29 +++++++++++++++++++---------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index f38e20bc..232e7b16 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -180,12 +180,17 @@ abstract class Builder protected function parseTable($tables, $options = []) { $item = []; - foreach ((array) $tables as $table) { - $table = $this->parseSqlTable($table); - if (isset($options['alias'][$table])) { - $item[] = $this->parseKey($table) . ' ' . $this->parseKey($options['alias'][$table]); + foreach ((array) $tables as $key => $table) { + if (!is_numeric($key)) { + $key = $this->parseSqlTable($key); + $item[] = $this->parseKey($key) . ' ' . $this->parseKey($table); } else { - $item[] = $this->parseKey($table); + $table = $this->parseSqlTable($table); + if (isset($options['alias'][$table])) { + $item[] = $this->parseKey($table) . ' ' . $this->parseKey($options['alias'][$table]); + } else { + $item[] = $this->parseKey($table); + } } } return implode(',', $item); diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 79933838..c277c9d9 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -671,6 +671,7 @@ class Query $table = $key; $alias = array_shift($join); $this->alias([$table => $alias]); + $table = [$table => $alias]; } else { $table = array_shift($join); } @@ -694,6 +695,7 @@ class Query if (strpos($table, ' ')) { list($table, $alias) = explode(' ', $table); $this->alias([$table => $alias]); + $table = [$table => $alias]; } } $this->options['join'][] = [$table, strtoupper($type), $condition]; @@ -1054,7 +1056,7 @@ class Query $table[] = $val; } else { $this->alias([$key => $val]); - $table[] = $key; + $table[$key] = $val; } } } @@ -1365,7 +1367,7 @@ class Query /** * 获取数据表信息 * @access public - * @param string $tableName 数据表名 留空自动获取 + * @param mixed $tableName 数据表名 留空自动获取 * @param string $fetch 获取信息类型 包括 fields type bind pk * @return mixed */ @@ -1575,7 +1577,7 @@ class Query $name = Loader::parseName(basename(str_replace('\\', '/', $currentModel))); $table = $this->getTable(); $alias = isset($info['alias'][$name]) ? $info['alias'][$name] : $name; - $this->table($table)->alias($alias); + $this->table([$table => $alias]); if (isset($this->options['field'])) { $field = $this->options['field']; unset($this->options['field']); @@ -1587,7 +1589,7 @@ class Query // 预载入封装 $joinTable = $model->getTable(); $joinName = Loader::parseName(basename(str_replace('\\', '/', $info['model']))); - $joinAlias = isset($info['alias'][$joinName]) ? $info['alias'][$joinName] : $joinName; + $joinAlias = isset($info['alias'][$joinName]) ? $info['alias'][$joinName] : $relation; $this->via($joinAlias); if (Relation::HAS_ONE == $info['type']) { @@ -1670,8 +1672,9 @@ class Query { $pk = $this->getPk($options); // 获取当前数据表 - if (!empty($options['alias'][$options['table']])) { - $alias = $options['alias'][$options['table']]; + $table = is_array($options['table']) ? key($options['table']) : $options['table']; + if (!empty($options['alias'][$table])) { + $alias = $options['alias'][$table]; } if (is_string($pk)) { $key = isset($alias) ? $alias . '.' . $pk : $pk; @@ -1983,7 +1986,7 @@ class Query // 判断查询缓存 $cache = $options['cache']; if (true === $cache['key'] && !is_null($data) && !is_array($data)) { - $key = 'think:' . $options['table'] . '|' . $data; + $key = 'think:' . (is_array($options['table']) ? key($options['table']) : $options['table']) . '|' . $data; } else { $key = is_string($cache['key']) ? $cache['key'] : md5(serialize($options)); } @@ -2053,7 +2056,8 @@ class Query if (!empty($this->model)) { throw new ModelNotFoundException('model data Not Found:' . $this->model, $this->model, $options); } else { - throw new DataNotFoundException('table data not Found:' . $options['table'], $options['table'], $options); + $table = is_array($options['table']) ? key($options['table']) : $options['table']; + throw new DataNotFoundException('table data not Found:' . $table, $table, $options); } } @@ -2095,8 +2099,13 @@ class Query */ public function chunk($count, $callback, $column = null) { - $options = $this->getOptions(); - $column = $column ?: $this->getPk(isset($options['table']) ? $options['table'] : ''); + $options = $this->getOptions(); + if (isset($options['table'])) { + $table = is_array($options['table']) ? key($options['table']) : $options['table']; + } else { + $table = ''; + } + $column = $column ?: $this->getPk($table); $bind = $this->bind; $resultSet = $this->limit($count)->order($column, 'asc')->select(); -- Gitee From e3ec75d001eec2067d84e4e91907d226d02c2fe2 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 9 Oct 2016 12:08:49 +0800 Subject: [PATCH 0017/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BB?= =?UTF-8?q?=E7=9A=84table=E6=96=B9=E6=B3=95=E5=92=8Calias=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index c277c9d9..2e37e1a3 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1046,7 +1046,8 @@ class Query } } elseif (strpos($table, ' ')) { list($table, $alias) = explode(' ', $table); - $this->alias([$table => $alias]); + $table = [$table => $alias]; + $this->alias($table); } } else { $tables = $table; @@ -1189,7 +1190,11 @@ class Query $this->options['alias'][$key] = $val; } } else { - $table = isset($this->options['table']) ? $this->options['table'] : $this->getTable(); + if (isset($this->options['table'])) { + $table = is_array($this->options['table']) ? key($this->options['table']) : $this->options['table']; + } else { + $table = $this->getTable(); + } $this->options['alias'][$table] = $alias; } -- Gitee From b754709dbfc9172cdc0504d48b13ad9163e86135 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 9 Oct 2016 15:07:19 +0800 Subject: [PATCH 0018/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Query=E7=9A=84join?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Builder.php | 8 ++++++-- library/think/db/Query.php | 17 ++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index 232e7b16..69484ffe 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -442,8 +442,12 @@ abstract class Builder list($table, $type, $on) = $item; $condition = []; foreach ((array) $on as $val) { - list($val1, $val2) = explode('=', $val, 2); - $condition[] = $this->parseKey($val1, $options) . '=' . $this->parseKey($val2, $options); + if (strpos($val, '=')) { + list($val1, $val2) = explode('=', $val, 2); + $condition[] = $this->parseKey($val1, $options) . '=' . $this->parseKey($val2, $options); + } else { + $condition[] = $val; + } } $table = $this->parseTable($table, $options); diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 2e37e1a3..ec37e49d 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -666,22 +666,25 @@ class Query $prefix = $this->prefix; // 传入的表名为数组 if (is_array($join)) { + if (count($join) > 1) { + $prefix = array_pop($join); + } if (0 !== $key = key($join)) { // 设置了键名则键名为表名,键值作为表的别名 $table = $key; + if (false === strpos($table, '.')) { + $table = $prefix . $table; + } $alias = array_shift($join); $this->alias([$table => $alias]); $table = [$table => $alias]; } else { $table = array_shift($join); + if (false === strpos($table, '.')) { + $table = $prefix . $table; + } } - if (count($join)) { - // 有设置第二个元素则把第二元素作为表前缀 - $table = (string) current($join) . $table; - } elseif (false === strpos($table, '.')) { - // 加上默认的表前缀 - $table = $prefix . $table; - } + } else { $join = trim($join); if (0 === strpos($join, '__')) { -- Gitee From 38b21f25baac39147770b9b72f0a761a45422d6d Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 9 Oct 2016 15:39:54 +0800 Subject: [PATCH 0019/1170] =?UTF-8?q?=E7=AE=80=E5=8C=96join=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index ec37e49d..0ba4b3c7 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -663,38 +663,19 @@ class Query } } } else { - $prefix = $this->prefix; // 传入的表名为数组 if (is_array($join)) { - if (count($join) > 1) { - $prefix = array_pop($join); - } if (0 !== $key = key($join)) { // 设置了键名则键名为表名,键值作为表的别名 $table = $key; - if (false === strpos($table, '.')) { - $table = $prefix . $table; - } $alias = array_shift($join); $this->alias([$table => $alias]); $table = [$table => $alias]; } else { $table = array_shift($join); - if (false === strpos($table, '.')) { - $table = $prefix . $table; - } } - } else { - $join = trim($join); - if (0 === strpos($join, '__')) { - $table = $this->parseSqlTable($join); - } elseif (false === strpos($join, '(') && false === strpos($join, '.') && !empty($prefix) && 0 !== strpos($join, $prefix)) { - // 传入的表名中不带有'('并且不以默认的表前缀开头时加上默认的表前缀 - $table = $prefix . $join; - } else { - $table = $join; - } + $table = trim($join); if (strpos($table, ' ')) { list($table, $alias) = explode(' ', $table); $this->alias([$table => $alias]); -- Gitee From 107f272eb3f4794118f6a1a478759933ed363ab1 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 9 Oct 2016 21:10:56 +0800 Subject: [PATCH 0020/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BLang=E7=B1=BBload?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Lang.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/think/Lang.php b/library/think/Lang.php index 16e7f545..e064ae45 100644 --- a/library/think/Lang.php +++ b/library/think/Lang.php @@ -83,7 +83,9 @@ class Lang // 记录加载信息 App::$debug && Log::record('[ LANG ] ' . $_file, 'info'); $_lang = include $_file; - $lang = array_change_key_case($_lang) + $lang; + if (is_array($_lang)) { + $lang = array_change_key_case($_lang) + $lang; + } } } if (!empty($lang)) { -- Gitee From f50140bbe24cd2e243b259f42609aadb6c94da43 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 9 Oct 2016 23:31:51 +0800 Subject: [PATCH 0021/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E8=A7=84=E5=88=99=E7=9A=84=E7=BB=84=E5=90=88=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E7=9A=84=E6=97=B6=E5=80=99=20=E5=8F=AF?= =?UTF-8?q?=E9=80=89=E5=88=86=E9=9A=94=E7=AC=A6=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20=E6=94=AF=E6=8C=81=E4=BD=BF=E7=94=A8=20Route::rules('item-(-=3F)','item/read');?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Url.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/think/Url.php b/library/think/Url.php index 4e145702..77d9f32b 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -77,6 +77,8 @@ class Url if (!empty($rule) && $match = self::getRuleUrl($rule, $vars)) { // 匹配路由命名标识 $url = $match[0]; + // 替换可选分隔符 + $url = preg_replace(['/\((\W)\?\)$/', '/\((\W)\?\)/'], ['', '\1'], $url); if (!empty($match[1])) { $domain = $match[1]; } -- Gitee From 0b8327d135adbd25a4493090182451d8bd3dd851 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 10 Oct 2016 10:51:32 +0800 Subject: [PATCH 0022/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 0ba4b3c7..3ca3382d 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -667,10 +667,8 @@ class Query if (is_array($join)) { if (0 !== $key = key($join)) { // 设置了键名则键名为表名,键值作为表的别名 - $table = $key; - $alias = array_shift($join); - $this->alias([$table => $alias]); - $table = [$table => $alias]; + $table = [$key => array_shift($join)]; + $this->alias($table); } else { $table = array_shift($join); } @@ -678,8 +676,8 @@ class Query $table = trim($join); if (strpos($table, ' ')) { list($table, $alias) = explode(' ', $table); - $this->alias([$table => $alias]); - $table = [$table => $alias]; + $table = [$table => $alias]; + $this->alias($table); } } $this->options['join'][] = [$table, strtoupper($type), $condition]; -- Gitee From cbfd825311d49a034bdeae3e869d4334cc22464c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 10 Oct 2016 12:17:48 +0800 Subject: [PATCH 0023/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E5=BC=95=E6=93=8E=E7=9A=84Think=E5=8F=98=E9=87=8F=E8=A7=A3?= =?UTF-8?q?=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Template.php | 80 ++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 46 deletions(-) diff --git a/library/think/Template.php b/library/think/Template.php index 036b367e..0c2265c0 100644 --- a/library/think/Template.php +++ b/library/think/Template.php @@ -959,78 +959,66 @@ class Template * @param array $vars 变量数组 * @return string */ - public function parseThinkVar(&$vars) + public function parseThinkVar($vars) { - $vars[0] = strtoupper(trim($vars[0])); - $parseStr = ''; - if (count($vars) >= 2) { - $vars[1] = trim($vars[1]); - switch ($vars[0]) { + $type = strtoupper(trim(array_shift($vars))); + $param = implode('.', $vars); + if ($vars) { + switch ($type) { case 'SERVER': - $parseStr = '$_SERVER[\'' . strtoupper($vars[1]) . '\']'; + $parseStr = '\\think\\Request::instance()->server(\'' . $param . '\')'; break; case 'GET': - $parseStr = '$_GET[\'' . $vars[1] . '\']'; + $parseStr = '\\think\\Request::instance()->get(\'' . $param . '\')'; break; case 'POST': - $parseStr = '$_POST[\'' . $vars[1] . '\']'; + $parseStr = '\\think\\Request::instance()->post(\'' . $param . '\')'; break; case 'COOKIE': - if (isset($vars[2])) { - $parseStr = '\\think\\Cookie::get(\'' . $vars[1] . '.' . $vars[2] . '\')'; - } else { - $parseStr = '\\think\\Cookie::get(\'' . $vars[1] . '\')'; - } + $parseStr = '\\think\\Cookie::get(\'' . $param . '\')'; break; case 'SESSION': - if (isset($vars[2])) { - $parseStr = '\\think\\Session::get(\'' . $vars[1] . '.' . $vars[2] . '\')'; - } else { - $parseStr = '\\think\\Session::get(\'' . $vars[1] . '\')'; - } + $parseStr = '\\think\\Session::get(\'' . $param . '\')'; break; case 'ENV': - $parseStr = '$_ENV[\'' . strtoupper($vars[1]) . '\']'; + $parseStr = '\\think\\Request::instance()->env(\'' . $param . '\')'; break; case 'REQUEST': - $parseStr = '$_REQUEST[\'' . $vars[1] . '\']'; + $parseStr = '\\think\\Request::instance()->request(\'' . $param . '\')'; break; case 'CONST': - $parseStr = strtoupper($vars[1]); + $parseStr = strtoupper($param); break; case 'LANG': - $parseStr = '\\think\\Lang::get(\'' . $vars[1] . '\')'; + $parseStr = '\\think\\Lang::get(\'' . $param . '\')'; break; case 'CONFIG': - if (isset($vars[2])) { - $vars[1] .= '.' . $vars[2]; - } - $parseStr = '\\think\\Config::get(\'' . $vars[1] . '\')'; + $parseStr = '\\think\\Config::get(\'' . $param . '\')'; break; default: $parseStr = '\'\''; break; } } else { - if (count($vars) == 1) { - switch ($vars[0]) { - case 'NOW': - $parseStr = "date('Y-m-d g:i a',time())"; - break; - case 'VERSION': - $parseStr = 'THINK_VERSION'; - break; - case 'LDELIM': - $parseStr = '\'' . ltrim($this->config['tpl_begin'], '\\') . '\''; - break; - case 'RDELIM': - $parseStr = '\'' . ltrim($this->config['tpl_end'], '\\') . '\''; - break; - default: - if (defined($vars[0])) { - $parseStr = $vars[0]; - } - } + switch ($type) { + case 'NOW': + $parseStr = "date('Y-m-d g:i a',time())"; + break; + case 'VERSION': + $parseStr = 'THINK_VERSION'; + break; + case 'LDELIM': + $parseStr = '\'' . ltrim($this->config['tpl_begin'], '\\') . '\''; + break; + case 'RDELIM': + $parseStr = '\'' . ltrim($this->config['tpl_end'], '\\') . '\''; + break; + default: + if (defined($type)) { + $parseStr = $type; + } else { + $parseStr = ''; + } } } return $parseStr; -- Gitee From f2d44a4775eac9cca5eb327a894dfa27408044c6 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 10 Oct 2016 12:27:32 +0800 Subject: [PATCH 0024/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/thinkphp/library/think/templateTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/thinkphp/library/think/templateTest.php b/tests/thinkphp/library/think/templateTest.php index 29100f4d..49c0eb39 100644 --- a/tests/thinkphp/library/think/templateTest.php +++ b/tests/thinkphp/library/think/templateTest.php @@ -291,15 +291,15 @@ EOF; {\$Think.SITE.URL} EOF; $data = <<
-
-
+server('SERVER_NAME'); ?>
+get('action'); ?>
+post('action'); ?>




-
-
+env('OS'); ?>
+request('action'); ?>



-- Gitee From e3466b43833e5afaa94f40c3907027d2c6d51f75 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 10 Oct 2016 16:29:47 +0800 Subject: [PATCH 0025/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BBjoin?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=AF=B9=E5=AD=90=E6=9F=A5=E8=AF=A2=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 3ca3382d..79ad05ba 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -674,7 +674,7 @@ class Query } } else { $table = trim($join); - if (strpos($table, ' ')) { + if (strpos($table, ' ') && !strpos($table, ')')) { list($table, $alias) = explode(' ', $table); $table = [$table => $alias]; $this->alias($table); -- Gitee From c67eb5adc87596772cb5a1e6632c01e49d24f6e8 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 10 Oct 2016 17:25:37 +0800 Subject: [PATCH 0026/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BB?= =?UTF-8?q?=E7=9A=84value=E6=96=B9=E6=B3=95=E7=BC=93=E5=AD=98=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 79ad05ba..5c3e0f0e 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -377,7 +377,7 @@ class Query */ public function value($field, $default = null) { - $result = null; + $result = false; if (!empty($this->options['cache'])) { // 判断查询缓存 $cache = $this->options['cache']; @@ -387,7 +387,7 @@ class Query $key = is_string($cache['key']) ? $cache['key'] : md5($field . serialize($this->options)); $result = Cache::get($key); } - if (!$result) { + if (false === $result) { if (isset($this->options['field'])) { unset($this->options['field']); } @@ -409,7 +409,7 @@ class Query // 清空查询条件 $this->options = []; } - return !is_null($result) ? $result : $default; + return false !== $result ? $result : $default; } /** @@ -431,7 +431,7 @@ class Query $guid = is_string($cache['key']) ? $cache['key'] : md5($field . serialize($this->options)); $result = Cache::get($guid); } - if (!$result) { + if (false === $result) { if (isset($this->options['field'])) { unset($this->options['field']); } -- Gitee From 6440a640cdda724cf28f4fbf60392ef5c80a70b1 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 10 Oct 2016 18:11:45 +0800 Subject: [PATCH 0027/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E5=88=86=E7=BB=84=E7=9A=84url=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index 883082e7..63bf4153 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -305,7 +305,8 @@ class Route } $vars = self::parseVar($rule); if (isset($name)) { - self::name($name, [$rule, $vars, self::$domain]); + $key = $group ? $group . '/' . $rule : $rule; + self::name($name, [$key, $vars, self::$domain]); } if ($group) { if ('*' != $type) { @@ -425,7 +426,7 @@ class Route $vars = self::parseVar($key); $item[] = ['rule' => $key, 'route' => $route, 'var' => $vars, 'option' => $options, 'pattern' => $patterns]; // 设置路由标识 - self::name($route, [$key, $vars, self::$domain]); + self::name($route, [$name . '/' . $key, $vars, self::$domain]); } self::$rules['*'][$name] = ['rule' => $item, 'route' => '', 'var' => [], 'option' => $option, 'pattern' => $pattern]; } -- Gitee From 5ff97ce68d36a9e3e3dc2ddb77c87303c760008c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 11 Oct 2016 12:27:22 +0800 Subject: [PATCH 0028/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BModel=E7=B1=BBhas?= =?UTF-8?q?=E5=92=8ChasWhere=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index b9b55c44..a96c7d6e 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -1144,8 +1144,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess ->join($table . ' b', 'a.' . $info['localKey'] . '=b.' . $info['foreignKey'], $info['joinType']) ->group('b.' . $info['foreignKey']) ->having('count(' . $id . ')' . $operator . $count); - case Relation::HAS_MANY_THROUGH: - // TODO + case Relation::HAS_MANY_THROUGH: // TODO + default: + return $model; } } @@ -1176,8 +1177,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess ->field('a.*') ->join($table . ' b', 'a.' . $info['localKey'] . '=b.' . $info['foreignKey'], $info['joinType']) ->where($where); - case Relation::HAS_MANY_THROUGH: - // TODO + case Relation::HAS_MANY_THROUGH: // TODO + default: + return $model; } } -- Gitee From ca112f5637c1d7b5489fe102439059397175aa64 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 11 Oct 2016 23:20:11 +0800 Subject: [PATCH 0029/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=88=AB=E5=90=8D?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E7=9A=84=E8=B7=AF=E7=94=B1=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=20=E6=94=AF=E6=8C=81=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=8D=95=E7=8B=AC=E6=96=B9=E6=B3=95=E7=9A=84=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index 883082e7..572e82b7 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -828,7 +828,7 @@ class Route if (true === $rule) { $rule = self::getRouteExpress($url); } - if (!empty($rule['route']) && self::checkOption($rule['option'], $url, $request)) { + if (!empty($rule['route']) && self::checkOption($rule['option'], $request)) { return self::parseRule($url, $rule['route'], $url, $rule['option']); } } @@ -872,7 +872,7 @@ class Route $pattern = $item['pattern']; // 检查参数有效性 - if (!self::checkOption($option, $url, $request)) { + if (!self::checkOption($option, $request)) { continue; } @@ -936,27 +936,32 @@ class Route */ private static function checkRouteAlias($request, $url, $depr) { - $array = explode('|', $url, 2); - $item = self::$rules['alias'][$array[0]]; + $array = explode('|', $url); + $alias = array_shift($array); + $item = self::$rules['alias'][$alias]; if (is_array($item)) { list($rule, $option) = $item; + if (isset($option['method'][$array[0]])) { + $option['method'] = $option['method'][$array[0]]; + } } else { $rule = $item; } + $bind = implode('|', $array); // 参数有效性检查 - if (isset($option) && !self::checkOption($option, $url, $request)) { + if (isset($option) && !self::checkOption($option, $request)) { // 路由不匹配 return false; } elseif (0 === strpos($rule, '\\')) { // 路由到类 - return self::bindToClass($array[1], substr($rule, 1), $depr); + return self::bindToClass($bind, substr($rule, 1), $depr); } elseif (0 === strpos($url, '@')) { // 路由到控制器类 - return self::bindToController($array[1], substr($rule, 1), $depr); + return self::bindToController($bind, substr($rule, 1), $depr); } else { // 路由到模块/控制器 - return self::bindToModule($array[1], $rule, $depr); + return self::bindToModule($bind, $rule, $depr); } } @@ -1069,19 +1074,18 @@ class Route * 路由参数有效性检查 * @access private * @param array $option 路由参数 - * @param string $url URL地址 * @param Request $request Request对象 * @return bool */ - private static function checkOption($option, $url, $request) + private static function checkOption($option, $request) { // 请求类型检测 - if ((isset($option['method']) && false === stripos($option['method'], $request->method())) + if ((isset($option['method']) && is_string($option['method']) && false === stripos($option['method'], $request->method())) || (isset($option['ext']) && false === stripos($option['ext'], $request->ext())) // 伪静态后缀检测 || (isset($option['deny_ext']) && false !== stripos($option['deny_ext'], $request->ext())) || (isset($option['domain']) && !in_array($option['domain'], [$_SERVER['HTTP_HOST'], self::$subDomain])) // 域名检测 || (!empty($option['https']) && !$request->isSsl()) // https检测 - || (!empty($option['before_behavior']) && false === Hook::exec($option['before_behavior'], '', $url)) // 行为检测 + || (!empty($option['before_behavior']) && false === Hook::exec($option['before_behavior'])) // 行为检测 || (!empty($option['callback']) && is_callable($option['callback']) && false === call_user_func($option['callback'])) // 自定义检测 ) { return false; -- Gitee From aa0028cef6dc67eaef968fb04beb5610ea1ff94a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 12 Oct 2016 18:06:49 +0800 Subject: [PATCH 0030/1170] =?UTF-8?q?Request=E7=B1=BB=E7=9A=84header?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?header=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/library/think/Request.php b/library/think/Request.php index 077e190d..6d49aa09 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -910,18 +910,22 @@ class Request { if (empty($this->header)) { $header = []; - $server = $this->server ?: $_SERVER; - foreach ($server as $key => $val) { - if (0 === strpos($key, 'HTTP_')) { - $key = str_replace('_', '-', strtolower(substr($key, 5))); - $header[$key] = $val; + if (function_exists('apache_request_headers') && $result = apache_request_headers()) { + $header = $result; + } else { + $server = $this->server ?: $_SERVER; + foreach ($server as $key => $val) { + if (0 === strpos($key, 'HTTP_')) { + $key = str_replace('_', '-', strtolower(substr($key, 5))); + $header[$key] = $val; + } + } + if (isset($server['CONTENT_TYPE'])) { + $header['content-type'] = $server['CONTENT_TYPE']; + } + if (isset($server['CONTENT_LENGTH'])) { + $header['content-length'] = $server['CONTENT_LENGTH']; } - } - if (isset($server['CONTENT_TYPE'])) { - $header['content-type'] = $server['CONTENT_TYPE']; - } - if (isset($server['CONTENT_LENGTH'])) { - $header['content-length'] = $server['CONTENT_LENGTH']; } $this->header = array_change_key_case($header); } -- Gitee From 245dba00a7023437d31a01a85f12e8cf9d9a9e49 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 12 Oct 2016 22:07:36 +0800 Subject: [PATCH 0031/1170] =?UTF-8?q?=E5=88=AB=E5=90=8D=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=93=8D=E4=BD=9C=E6=96=B9=E6=B3=95=E6=8E=92?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index 8f7dbe76..98bca3d4 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -943,8 +943,16 @@ class Route if (is_array($item)) { list($rule, $option) = $item; - if (isset($option['method'][$array[0]])) { - $option['method'] = $option['method'][$array[0]]; + $action = $array[0]; + if (isset($option['except'])) { + // 排除操作 + $except = is_string($option['except']) ? explode(',', $option['except']) : $option['except']; + if (in_array($action, $except)) { + return false; + } + } + if (isset($option['method'][$action])) { + $option['method'] = $option['method'][$action]; } } else { $rule = $item; -- Gitee From 112f22506510fe1f2ed569fcb3ddf23aa3449b27 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 12 Oct 2016 22:26:38 +0800 Subject: [PATCH 0032/1170] =?UTF-8?q?=E5=88=AB=E5=90=8D=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=93=8D=E4=BD=9C=E7=99=BD=E5=90=8D=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/library/think/Route.php b/library/think/Route.php index 98bca3d4..ca97e505 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -944,7 +944,13 @@ class Route if (is_array($item)) { list($rule, $option) = $item; $action = $array[0]; - if (isset($option['except'])) { + if (isset($option['allow'])) { + // 允许操作 + $allow = is_string($option['allow']) ? explode(',', $option['allow']) : $option['allow']; + if (!in_array($action, $allow)) { + return false; + } + } elseif (isset($option['except'])) { // 排除操作 $except = is_string($option['except']) ? explode(',', $option['except']) : $option['except']; if (in_array($action, $except)) { -- Gitee From cb3278b725028594591bff845f266e2f6ed9c836 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 13 Oct 2016 11:53:19 +0800 Subject: [PATCH 0033/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E7=9A=84=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/library/think/App.php b/library/think/App.php index 7e140ca9..67aac096 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -225,7 +225,7 @@ class App } $args = self::bindParams($reflect, $vars); - self::$debug && Log::record('[ RUN ] ' . $reflect->__toString(), 'info'); + self::$debug && Log::record('[ RUN ] ' . $reflect->class . '->' . $reflect->name . '[ ' . $reflect->getFileName() . ' ]', 'info'); return $reflect->invokeArgs(isset($class) ? $class : null, $args); } @@ -245,8 +245,6 @@ class App } else { $args = []; } - - self::$debug && Log::record('[ RUN ] ' . $reflect->__toString(), 'info'); return $reflect->newInstanceArgs($args); } -- Gitee From fff423a5eb2475f28757aeb278d76016840fd4c6 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 13 Oct 2016 12:31:39 +0800 Subject: [PATCH 0034/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Route=E7=B1=BBcheck?= =?UTF-8?q?RouteAlias=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index ca97e505..4b588b5e 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -944,18 +944,12 @@ class Route if (is_array($item)) { list($rule, $option) = $item; $action = $array[0]; - if (isset($option['allow'])) { + if (isset($option['allow']) && !in_array($action, explode(',', $option['allow']))) { // 允许操作 - $allow = is_string($option['allow']) ? explode(',', $option['allow']) : $option['allow']; - if (!in_array($action, $allow)) { - return false; - } - } elseif (isset($option['except'])) { + return false; + } elseif (isset($option['except']) && in_array($action, explode(',', $option['except']))) { // 排除操作 - $except = is_string($option['except']) ? explode(',', $option['except']) : $option['except']; - if (in_array($action, $except)) { - return false; - } + return false; } if (isset($option['method'][$action])) { $option['method'] = $option['method'][$action]; @@ -971,7 +965,7 @@ class Route } elseif (0 === strpos($rule, '\\')) { // 路由到类 return self::bindToClass($bind, substr($rule, 1), $depr); - } elseif (0 === strpos($url, '@')) { + } elseif (0 === strpos($rule, '@')) { // 路由到控制器类 return self::bindToController($bind, substr($rule, 1), $depr); } else { -- Gitee From 3fdd4f1009e2414482cf46c84de7d33ae6729a4e Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 13 Oct 2016 14:18:01 +0800 Subject: [PATCH 0035/1170] =?UTF-8?q?Route=E9=87=8D=E5=AE=9A=E5=90=91?= =?UTF-8?q?=E8=A7=84=E5=88=99=E6=94=AF=E6=8C=81=E6=9B=B4=E5=A4=9A=20schema?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Route.php b/library/think/Route.php index 4b588b5e..8ecbcb7e 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1414,7 +1414,7 @@ class Route if ($route instanceof \Closure) { // 执行闭包 $result = ['type' => 'function', 'function' => $route]; - } elseif (0 === strpos($route, '/') || 0 === strpos($route, 'http')) { + } elseif (0 === strpos($route, '/') || strpos($route, '://')) { // 路由到重定向地址 $result = ['type' => 'redirect', 'url' => $route, 'status' => isset($option['status']) ? $option['status'] : 301]; } elseif (false !== strpos($route, '\\')) { -- Gitee From d65daa2fdc4a8df6ba1fd11003776f9610cfee00 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 13 Oct 2016 23:17:19 +0800 Subject: [PATCH 0036/1170] =?UTF-8?q?URL=E7=94=9F=E6=88=90=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=88=AB=E5=90=8D=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Url.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/library/think/Url.php b/library/think/Url.php index 77d9f32b..850e5ff5 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -85,13 +85,29 @@ class Url } elseif (!empty($rule) && isset($name)) { throw new \InvalidArgumentException('route name not exists:' . $name); } else { + // 检查别名路由 + $alias = Route::rules('alias'); + if ($alias) { + // 别名路由解析 + foreach ($alias as $key => $val) { + if (is_array($val)) { + $val = $val[0]; + } + if (0 === strpos($url, $val)) { + $url = $key . substr($url, strlen($val)); + break; + } + } + } else { + // 路由标识不存在 直接解析 + $url = self::parseUrl($url, $domain); + } if (isset($info['query'])) { // 解析地址里面参数 合并到vars parse_str($info['query'], $params); $vars = array_merge($params, $vars); } - // 路由标识不存在 直接解析 - $url = self::parseUrl($url, $domain); + } // 检测URL绑定 -- Gitee From 4c285d94d91ab05e8259c8fb7943d5b0dfbcc2ab Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 13 Oct 2016 23:28:53 +0800 Subject: [PATCH 0037/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BUrl=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Url.php | 10 +--------- tests/thinkphp/library/think/urlTest.php | 13 ++++++++++++- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/library/think/Url.php b/library/think/Url.php index 850e5ff5..77c15a2f 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -35,11 +35,6 @@ class Url $domain = true; } // 解析URL - if (0 === strpos($url, '[') && $pos = strpos($url, ']')) { - // [name] 表示使用路由命名标识生成URL - $name = substr($url, 1, $pos - 1); - $url = 'name' . substr($url, $pos + 1); - } $info = parse_url($url); $url = !empty($info['path']) ? $info['path'] : ''; if (isset($info['fragment'])) { @@ -65,7 +60,7 @@ class Url } if ($url) { - $rule = Route::name(isset($name) ? $name : $url . (isset($info['query']) ? '?' . $info['query'] : '')); + $rule = Route::name($url . (isset($info['query']) ? '?' . $info['query'] : '')); if (is_null($rule) && isset($info['query'])) { $rule = Route::name($url); // 解析地址里面参数 合并到vars @@ -82,8 +77,6 @@ class Url if (!empty($match[1])) { $domain = $match[1]; } - } elseif (!empty($rule) && isset($name)) { - throw new \InvalidArgumentException('route name not exists:' . $name); } else { // 检查别名路由 $alias = Route::rules('alias'); @@ -107,7 +100,6 @@ class Url parse_str($info['query'], $params); $vars = array_merge($params, $vars); } - } // 检测URL绑定 diff --git a/tests/thinkphp/library/think/urlTest.php b/tests/thinkphp/library/think/urlTest.php index 94dfc71d..ef49b89f 100644 --- a/tests/thinkphp/library/think/urlTest.php +++ b/tests/thinkphp/library/think/urlTest.php @@ -25,7 +25,18 @@ class urlTest extends \PHPUnit_Framework_TestCase public function setUp() { - Route::rules([]); + Route::rules(['GET' => [], + 'POST' => [], + 'PUT' => [], + 'DELETE' => [], + 'PATCH' => [], + 'HEAD' => [], + 'OPTIONS' => [], + '*' => [], + 'alias' => [], + 'domain' => [], + 'pattern' => [], + 'name' => []]); Route::name([]); } -- Gitee From b9b7e34b6d8c13e6a6286ad505ad70accf9c09e4 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 13 Oct 2016 23:34:34 +0800 Subject: [PATCH 0038/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Url.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/library/think/Url.php b/library/think/Url.php index 77c15a2f..79e3c1cb 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -35,6 +35,11 @@ class Url $domain = true; } // 解析URL + if (0 === strpos($url, '[') && $pos = strpos($url, ']')) { + // [name] 表示使用路由命名标识生成URL + $name = substr($url, 1, $pos - 1); + $url = 'name' . substr($url, $pos + 1); + } $info = parse_url($url); $url = !empty($info['path']) ? $info['path'] : ''; if (isset($info['fragment'])) { @@ -60,7 +65,7 @@ class Url } if ($url) { - $rule = Route::name($url . (isset($info['query']) ? '?' . $info['query'] : '')); + $rule = Route::name(isset($name) ? $name : $url . (isset($info['query']) ? '?' . $info['query'] : '')); if (is_null($rule) && isset($info['query'])) { $rule = Route::name($url); // 解析地址里面参数 合并到vars @@ -77,6 +82,8 @@ class Url if (!empty($match[1])) { $domain = $match[1]; } + } elseif (!empty($rule) && isset($name)) { + throw new \InvalidArgumentException('route name not exists:' . $name); } else { // 检查别名路由 $alias = Route::rules('alias'); -- Gitee From ba555eba000705e1df3a43279e7bf274a2a0d124 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 14 Oct 2016 16:28:26 +0800 Subject: [PATCH 0039/1170] =?UTF-8?q?Request=E7=B1=BB=E7=9A=84=E6=9E=B6?= =?UTF-8?q?=E6=9E=84=E6=96=B9=E6=B3=95=E6=94=B9=E4=B8=BAprotected?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/think/Request.php b/library/think/Request.php index 6d49aa09..75f2b9ef 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -124,10 +124,10 @@ class Request /** * 架构函数 - * @access public + * @access protected * @param array $options 参数 */ - public function __construct($options = []) + protected function __construct($options = []) { foreach ($options as $name => $item) { if (property_exists($this, $name)) { -- Gitee From dc5f0458d3329a4000f76f003e5970254c73a173 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 14 Oct 2016 18:04:55 +0800 Subject: [PATCH 0040/1170] =?UTF-8?q?=E8=B7=AF=E7=94=B1=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E7=94=9F=E6=88=90=E6=94=AF=E6=8C=81url=5Fparam=5Ftype=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Url.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/think/Url.php b/library/think/Url.php index 79e3c1cb..2e1fcc19 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -134,7 +134,11 @@ class Url } else { foreach ($vars as $var => $val) { if ('' !== trim($val)) { - $url .= $depr . $var . $depr . urlencode($val); + if (Config::get('url_param_type')) { + $url .= $depr . urlencode($val); + } else { + $url .= $depr . $var . $depr . urlencode($val); + } } } $url .= $suffix . $anchor; -- Gitee From 27bf7b2af9c1b854ddffcaa23f2002dfb9575aef Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 14 Oct 2016 23:03:19 +0800 Subject: [PATCH 0041/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BUrl=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Url.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/think/Url.php b/library/think/Url.php index 2e1fcc19..f0bb30b8 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -132,9 +132,10 @@ class Url $vars = urldecode(http_build_query($vars)); $url .= $suffix . '?' . $vars . $anchor; } else { + $paramType = Config::get('url_param_type'); foreach ($vars as $var => $val) { if ('' !== trim($val)) { - if (Config::get('url_param_type')) { + if ($paramType) { $url .= $depr . urlencode($val); } else { $url .= $depr . $var . $depr . urlencode($val); -- Gitee From 381a56f3348de270c97c9a424012ac7a743524b4 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 14 Oct 2016 23:38:38 +0800 Subject: [PATCH 0042/1170] =?UTF-8?q?=E8=B7=AF=E7=94=B1=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=AF=B9=20=E8=B7=AF=E7=94=B1=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E4=B8=BA=E7=B1=BB=E7=9A=84=E6=96=B9=E6=B3=95=E7=9A=84?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Url.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Url.php b/library/think/Url.php index f0bb30b8..0c22cd61 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -53,7 +53,7 @@ class Url // 解析域名 list($anchor, $domain) = explode('@', $anchor, 2); } - } elseif (strpos($url, '@')) { + } elseif (strpos($url, '@') && false === strpos($url, '\\')) { // 解析域名 list($url, $domain) = explode('@', $url, 2); } -- Gitee From fbd76aaf51d9d7f90bfc6eaae610c3658558fbea Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 15 Oct 2016 00:02:02 +0800 Subject: [PATCH 0043/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Url.php | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/library/think/Url.php b/library/think/Url.php index 0c22cd61..24087fc4 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -40,22 +40,24 @@ class Url $name = substr($url, 1, $pos - 1); $url = 'name' . substr($url, $pos + 1); } - $info = parse_url($url); - $url = !empty($info['path']) ? $info['path'] : ''; - if (isset($info['fragment'])) { - // 解析锚点 - $anchor = $info['fragment']; - if (false !== strpos($anchor, '?')) { - // 解析参数 - list($anchor, $info['query']) = explode('?', $anchor, 2); - } - if (false !== strpos($anchor, '@')) { + if (false === strpos($url, '://') && 0 !== strpos($url, '/')) { + $info = parse_url($url); + $url = !empty($info['path']) ? $info['path'] : ''; + if (isset($info['fragment'])) { + // 解析锚点 + $anchor = $info['fragment']; + if (false !== strpos($anchor, '?')) { + // 解析参数 + list($anchor, $info['query']) = explode('?', $anchor, 2); + } + if (false !== strpos($anchor, '@')) { + // 解析域名 + list($anchor, $domain) = explode('@', $anchor, 2); + } + } elseif (strpos($url, '@') && false === strpos($url, '\\')) { // 解析域名 - list($anchor, $domain) = explode('@', $anchor, 2); + list($url, $domain) = explode('@', $url, 2); } - } elseif (strpos($url, '@') && false === strpos($url, '\\')) { - // 解析域名 - list($url, $domain) = explode('@', $url, 2); } // 解析参数 -- Gitee From 9bb981368a0e5a17e92ffc8de8e7769c3e76d2df Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 15 Oct 2016 09:04:38 +0800 Subject: [PATCH 0044/1170] =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/thinkphp/library/think/requestTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/thinkphp/library/think/requestTest.php b/tests/thinkphp/library/think/requestTest.php index 964b5c85..837aa839 100644 --- a/tests/thinkphp/library/think/requestTest.php +++ b/tests/thinkphp/library/think/requestTest.php @@ -103,13 +103,13 @@ class requestTest extends \PHPUnit_Framework_TestCase { $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'DELETE'; - $request = new Request(); + $request = Request::create(''); $this->assertEquals('DELETE', $request->method()); $this->assertEquals('GET', $request->method(true)); Config::set('var_method', '_method'); $_POST['_method'] = 'POST'; - $request = new Request(); + $request = Request::create(''); $this->assertEquals('POST', $request->method()); $this->assertEquals('GET', $request->method(true)); $this->assertTrue($request->isPost()); @@ -156,28 +156,28 @@ class requestTest extends \PHPUnit_Framework_TestCase public function testIsAjax() { - $request = new Request(); + $request = Request::create(''); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'xmlhttprequest'; $this->assertTrue($request->isAjax()); } public function testIsPjax() { - $request = new Request(); + $request = Request::create(''); $_SERVER['HTTP_X_PJAX'] = true; $this->assertTrue($request->isPjax()); } public function testIsMobile() { - $request = new Request(); + $request = Request::create(''); $_SERVER['HTTP_VIA'] = 'wap'; $this->assertTrue($request->isMobile()); } public function testBind() { - $request = new Request(); + $request = Request::create(''); $request->user = 'User1'; $request->bind(['user' => 'User2']); $this->assertEquals('User2', $request->user); -- Gitee From 2ef3ad748b887ba29b2e19a58e3be3709e6d20d2 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 15 Oct 2016 11:03:56 +0800 Subject: [PATCH 0045/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 2 ++ tests/thinkphp/library/think/requestTest.php | 2 +- tests/thinkphp/library/think/urlTest.php | 6 +++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/library/think/Request.php b/library/think/Request.php index 75f2b9ef..d9286298 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -210,6 +210,8 @@ class Request unset($server['HTTPS']); $server['SERVER_PORT'] = 80; } + } else { + $info['scheme'] = 'http'; } if (isset($info['port'])) { $server['SERVER_PORT'] = $info['port']; diff --git a/tests/thinkphp/library/think/requestTest.php b/tests/thinkphp/library/think/requestTest.php index 837aa839..1b5afa34 100644 --- a/tests/thinkphp/library/think/requestTest.php +++ b/tests/thinkphp/library/think/requestTest.php @@ -130,7 +130,7 @@ class requestTest extends \PHPUnit_Framework_TestCase public function testVar() { Config::set('app_multi_module', true); - $request = new Request(); + $request = Request::create(''); $request->route(['name' => 'thinkphp', 'id' => 6]); $request->get(['id' => 10]); $request->post(['id' => 8]); diff --git a/tests/thinkphp/library/think/urlTest.php b/tests/thinkphp/library/think/urlTest.php index ef49b89f..ced519d7 100644 --- a/tests/thinkphp/library/think/urlTest.php +++ b/tests/thinkphp/library/think/urlTest.php @@ -74,7 +74,7 @@ class urlTest extends \PHPUnit_Framework_TestCase public function testBuildMethod() { Route::get('blog/:id', '\app\index\controller\blog@read'); - $this->assertEquals('/blog/10.html', Url::build('[\app\index\controller\blog@read]', 'id=10', 'html')); + $this->assertEquals('/blog/10.html', Url::build('\app\index\controller\blog@read', 'id=10', 'html')); } public function testBuildRoute() @@ -97,10 +97,10 @@ class urlTest extends \PHPUnit_Framework_TestCase { Route::get('blog/:id', 'index/blog'); Config::set('url_html_suffix', 'shtml'); - $this->assertEquals('/blog/10.shtml#detail', Url::build('/blog/10#detail')); + $this->assertEquals('/blog/10.shtml#detail', Url::build('index/blog#detail', 'id=10')); Config::set('url_common_param', true); - $this->assertEquals('/blog/10.shtml?foo=bar#detail', Url::build('/blog/10#detail', "foo=bar")); + $this->assertEquals('/blog/10.shtml?foo=bar#detail', Url::build('index/blog#detail', "id=10&foo=bar")); } public function testBuildDomain() -- Gitee From 4554f99451d333910f0d6ce2080e1ef9c02b7026 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 15 Oct 2016 11:09:34 +0800 Subject: [PATCH 0046/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/library/think/Request.php b/library/think/Request.php index d9286298..35803e3f 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -210,8 +210,6 @@ class Request unset($server['HTTPS']); $server['SERVER_PORT'] = 80; } - } else { - $info['scheme'] = 'http'; } if (isset($info['port'])) { $server['SERVER_PORT'] = $info['port']; @@ -250,7 +248,7 @@ class Request $options['baseUrl'] = $info['path']; $options['pathinfo'] = '/' == $info['path'] ? '/' : ltrim($info['path'], '/'); $options['method'] = $server['REQUEST_METHOD']; - $options['domain'] = $info['scheme'] . '://' . $server['HTTP_HOST']; + $options['domain'] = isset($info['scheme']) ? $info['scheme'] . '://' . $server['HTTP_HOST'] : ''; $options['content'] = $content; self::$instance = new self($options); return self::$instance; -- Gitee From c37f1fc39b8f5d95d172aeef30091b14a92ad4fd Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 15 Oct 2016 11:17:26 +0800 Subject: [PATCH 0047/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/thinkphp/library/think/requestTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/thinkphp/library/think/requestTest.php b/tests/thinkphp/library/think/requestTest.php index 1b5afa34..ef5f8e98 100644 --- a/tests/thinkphp/library/think/requestTest.php +++ b/tests/thinkphp/library/think/requestTest.php @@ -103,13 +103,13 @@ class requestTest extends \PHPUnit_Framework_TestCase { $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'DELETE'; - $request = Request::create(''); + $request = Request::create('', ''); $this->assertEquals('DELETE', $request->method()); $this->assertEquals('GET', $request->method(true)); Config::set('var_method', '_method'); $_POST['_method'] = 'POST'; - $request = Request::create(''); + $request = Request::create('', ''); $this->assertEquals('POST', $request->method()); $this->assertEquals('GET', $request->method(true)); $this->assertTrue($request->isPost()); -- Gitee From 99300f8d4ddae384fffb1b61fae19bb30c265026 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 16 Oct 2016 19:26:04 +0800 Subject: [PATCH 0048/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Query=E7=B1=BBsetIn?= =?UTF-8?q?c=E5=92=8CsetDec=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 5c3e0f0e..52b0d18c 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -578,8 +578,6 @@ class Query // 清空查询条件 $this->options = []; return true; - } else { - return $this->setField($field, $step); } } return $this->setField($field, ['exp', $field . '+' . $step]); @@ -609,8 +607,6 @@ class Query // 清空查询条件 $this->options = []; return true; - } else { - return $this->setField($field, $step); } } return $this->setField($field, ['exp', $field . '-' . $step]); -- Gitee From f2e51604f4019811aa19e94ffaef26b0a42d37fe Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 17 Oct 2016 12:09:13 +0800 Subject: [PATCH 0049/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=95=B4=E5=9E=8B?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E7=9A=84=E5=8F=82=E6=95=B0=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E5=86=99=E5=85=A5=20=E9=BB=98=E8=AE=A4=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Connection.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index f405f9b9..f39ca341 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -421,6 +421,8 @@ abstract class Connection $type = is_array($val) ? $val[1] : PDO::PARAM_STR; if (PDO::PARAM_STR == $type) { $value = $this->quote($value); + } elseif (PDO::PARAM_INT == $type && '' === $value) { + $value = 0; } // 判断占位符 $sql = is_numeric($key) ? @@ -449,6 +451,9 @@ abstract class Connection // 占位符 $param = is_numeric($key) ? $key + 1 : ':' . $key; if (is_array($val)) { + if (PDO::PARAM_INT == $val[1] && '' === $val[0]) { + $val[0] = 0; + } $result = $this->PDOStatement->bindValue($param, $val[0], $val[1]); } else { $result = $this->PDOStatement->bindValue($param, $val); -- Gitee From d9be9ddf6fd7228862967b03de1f7c038be7ca4f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 17 Oct 2016 13:53:53 +0800 Subject: [PATCH 0050/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BLoader=E7=B1=BBmode?= =?UTF-8?q?l=E5=92=8Cvalidate=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Loader.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/library/think/Loader.php b/library/think/Loader.php index cfa0a217..9f54ad3a 100644 --- a/library/think/Loader.php +++ b/library/think/Loader.php @@ -365,8 +365,9 @@ class Loader */ public static function model($name = '', $layer = 'model', $appendSuffix = false, $common = 'common') { - if (isset(self::$instance[$name . $layer])) { - return self::$instance[$name . $layer]; + $guid = $name . $layer; + if (isset(self::$instance[$guid])) { + return self::$instance[$guid]; } if (strpos($name, '/')) { list($module, $name) = explode('/', $name, 2); @@ -384,7 +385,7 @@ class Loader throw new ClassNotFoundException('class not exists:' . $class, $class); } } - self::$instance[$name . $layer] = $model; + self::$instance[$guid] = $model; return $model; } @@ -427,9 +428,9 @@ class Loader if (empty($name)) { return new Validate; } - - if (isset(self::$instance[$name . $layer])) { - return self::$instance[$name . $layer]; + $guid = $name . $layer; + if (isset(self::$instance[$guid])) { + return self::$instance[$guid]; } if (strpos($name, '/')) { list($module, $name) = explode('/', $name); @@ -447,7 +448,7 @@ class Loader throw new ClassNotFoundException('class not exists:' . $class, $class); } } - self::$instance[$name . $layer] = $validate; + self::$instance[$guid] = $validate; return $validate; } -- Gitee From 63d6f49a1bd8710b76ee1a6e0f1d4c0a8da6cd03 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 17 Oct 2016 16:35:26 +0800 Subject: [PATCH 0051/1170] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convention.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/convention.php b/convention.php index f7486a48..206603b1 100644 --- a/convention.php +++ b/convention.php @@ -58,6 +58,8 @@ return [ 'default_validate' => '', // 默认的空控制器名 'empty_controller' => 'Error', + // 操作方法前缀 + 'use_action_prefix' => false, // 操作方法后缀 'action_suffix' => '', // 自动搜索控制器 -- Gitee From bb9e33e9a5fe07471daf4669832e9e430d49a89e Mon Sep 17 00:00:00 2001 From: yunwuxin <448901948@qq.com> Date: Mon, 17 Oct 2016 17:52:09 +0800 Subject: [PATCH 0052/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3json=5Fencode?= =?UTF-8?q?=E6=97=B6=20"Failed=20calling=20XXX::jsonSerialize()"=20?= =?UTF-8?q?=E7=9A=84=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/response/Json.php | 22 +++++++++++++++------- library/think/response/Jsonp.php | 30 +++++++++++++++++++----------- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/library/think/response/Json.php b/library/think/response/Json.php index a137f453..027aa2a3 100644 --- a/library/think/response/Json.php +++ b/library/think/response/Json.php @@ -27,17 +27,25 @@ class Json extends Response * @access protected * @param mixed $data 要处理的数据 * @return mixed + * @throws \Exception */ protected function output($data) { - // 返回JSON数据格式到客户端 包含状态信息 - $data = json_encode($data, $this->options['json_encode_param']); - - if ($data === false) { - throw new \InvalidArgumentException(json_last_error_msg()); + try { + // 返回JSON数据格式到客户端 包含状态信息 + $data = json_encode($data, $this->options['json_encode_param']); + + if ($data === false) { + throw new \InvalidArgumentException(json_last_error_msg()); + } + + return $data; + } catch (\Exception $e) { + if ($e->getPrevious()) { + throw $e->getPrevious(); + } + throw $e; } - - return $data; } } diff --git a/library/think/response/Jsonp.php b/library/think/response/Jsonp.php index fda1183a..b92aa9f6 100644 --- a/library/think/response/Jsonp.php +++ b/library/think/response/Jsonp.php @@ -30,21 +30,29 @@ class Jsonp extends Response * @access protected * @param mixed $data 要处理的数据 * @return mixed + * @throws \Exception */ protected function output($data) { - // 返回JSON数据格式到客户端 包含状态信息 [当url_common_param为false时是无法获取到$_GET的数据的,故使用Request来获取] - $var_jsonp_handler = Request::instance()->param($this->options['var_jsonp_handler'], ""); - $handler = !empty($var_jsonp_handler) ? $var_jsonp_handler : $this->options['default_jsonp_handler']; - - $data = json_encode($data, $this->options['json_encode_param']); - - if ($data === false) { - throw new \InvalidArgumentException(json_last_error_msg()); + try { + // 返回JSON数据格式到客户端 包含状态信息 [当url_common_param为false时是无法获取到$_GET的数据的,故使用Request来获取] + $var_jsonp_handler = Request::instance()->param($this->options['var_jsonp_handler'], ""); + $handler = !empty($var_jsonp_handler) ? $var_jsonp_handler : $this->options['default_jsonp_handler']; + + $data = json_encode($data, $this->options['json_encode_param']); + + if ($data === false) { + throw new \InvalidArgumentException(json_last_error_msg()); + } + + $data = $handler . '(' . $data . ');'; + return $data; + } catch (\Exception $e) { + if ($e->getPrevious()) { + throw $e->getPrevious(); + } + throw $e; } - - $data = $handler . '(' . $data . ');'; - return $data; } } -- Gitee From a449e236fac977666a8bab73a9d7c088c9471a65 Mon Sep 17 00:00:00 2001 From: lw78665806 <78665806@qq.com> Date: Tue, 18 Oct 2016 10:08:55 +0800 Subject: [PATCH 0053/1170] Update Validate.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复验证器规则无法获取多语言的问题 --- library/think/Validate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index 3c6e847a..ff7c9314 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -377,7 +377,7 @@ class Validate // 验证失败 返回错误信息 if (isset($msg[$i])) { $message = $msg[$i]; - if (is_string($message) && strpos($message, '{%')) { + if (is_string($message) && strpos($message, '{%') !== false) { $message = Lang::get(substr($message, 2, -1)); } } else { -- Gitee From 9e0b5da416b0177b0f187aa537d8c55f5bff77cb Mon Sep 17 00:00:00 2001 From: lw78665806 <78665806@qq.com> Date: Tue, 18 Oct 2016 10:14:37 +0800 Subject: [PATCH 0054/1170] Update Validate.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复验证器无法获取多语言的问题 --- library/think/Validate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index ff7c9314..ed12083c 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -377,7 +377,7 @@ class Validate // 验证失败 返回错误信息 if (isset($msg[$i])) { $message = $msg[$i]; - if (is_string($message) && strpos($message, '{%') !== false) { + if (is_string($message) && strpos($message, '{%') === 0) { $message = Lang::get(substr($message, 2, -1)); } } else { -- Gitee From cb9b2b5803370bdbfbfe1c0b27f85f8f41113dcd Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 18 Oct 2016 16:19:06 +0800 Subject: [PATCH 0055/1170] =?UTF-8?q?Cache=E7=B1=BB=E5=A2=9E=E5=8A=A0remem?= =?UTF-8?q?ber=E6=96=B9=E6=B3=95=20=E7=94=A8=E4=BA=8E=E5=BD=93=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E7=9A=84=E7=BC=93=E5=AD=98=E4=B8=8D=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=E8=87=AA=E5=8A=A8=E5=86=99=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/cache/Driver.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/library/think/cache/Driver.php b/library/think/cache/Driver.php index e0aeb7bc..a2a57795 100644 --- a/library/think/cache/Driver.php +++ b/library/think/cache/Driver.php @@ -109,6 +109,27 @@ abstract class Driver } } + /** + * 如果不存在则写入缓存 + * @access public + * @param string $name 缓存变量名 + * @param mixed $value 存储数据 + * @param int $expire 有效时间 0为永久 + * @return mixed + */ + public function remember($name, $value, $expire = null) + { + if (!$this->has($name)) { + if ($value instanceof \Closure) { + $value = call_user_func($value); + } + $this->set($name, $value, $expire); + } else { + $value = $this->get($name); + } + return $value; + } + /** * 缓存标签 * @access public -- Gitee From 3f654b6e5ef9516da17c414619dbf8bca1575b99 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 19 Oct 2016 11:22:35 +0800 Subject: [PATCH 0056/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=B3=A8=E5=85=A5=E6=9C=BA=E5=88=B6=20=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E4=BE=9D=E8=B5=96=E6=B3=A8=E5=85=A5=E7=9A=84=E7=B1=BB=E5=A6=82?= =?UTF-8?q?=E6=9E=9C=E5=AE=9A=E4=B9=89=E4=BA=86invoke=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E5=88=99=E8=87=AA=E5=8A=A8=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/library/think/App.php b/library/think/App.php index 67aac096..69833598 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -280,7 +280,14 @@ class App if ($bind instanceof $className) { $args[] = $bind; } else { - $args[] = method_exists($className, 'instance') ? $className::instance() : new $className(); + if (method_exists($className, 'invoke')) { + $method = new \ReflectionMethod($className, 'invoke'); + if ($method->isStatic()) { + $args[] = $className::invoke(); + continue; + } + } + $args[] = method_exists($className, 'instance') ? $className::instance() : new $className; } } elseif (1 == $type && !empty($vars)) { $args[] = array_shift($vars); -- Gitee From 53233db821a2a855777504106ccb5af1d2d34fc9 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 19 Oct 2016 12:27:43 +0800 Subject: [PATCH 0057/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BApp=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/App.php b/library/think/App.php index 69833598..d66e3438 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -282,7 +282,7 @@ class App } else { if (method_exists($className, 'invoke')) { $method = new \ReflectionMethod($className, 'invoke'); - if ($method->isStatic()) { + if ($method->isPublic() && $method->isStatic()) { $args[] = $className::invoke(); continue; } -- Gitee From a25b16b0cf283bad25477b7f960c10a40b871c62 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 19 Oct 2016 15:16:31 +0800 Subject: [PATCH 0058/1170] =?UTF-8?q?Session=E7=B1=BB=E5=A2=9E=E5=8A=A0fla?= =?UTF-8?q?sh=E6=96=B9=E6=B3=95=E7=94=A8=E4=BA=8E=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E4=B8=8B=E4=B8=80=E6=AC=A1=E8=AF=B7=E6=B1=82=E6=9C=89=E6=95=88?= =?UTF-8?q?=E7=9A=84=E5=80=BC=20flush=E6=96=B9=E6=B3=95=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E6=B8=85=E7=A9=BA=E5=BD=93=E5=89=8D=E8=AF=B7=E6=B1=82=E6=9C=89?= =?UTF-8?q?=E6=95=88=E7=9A=84=E5=80=BC=20=E5=A2=9E=E5=8A=A0push=E6=96=B9?= =?UTF-8?q?=E6=B3=95=20Redirect=20response=E7=B1=BB=E7=9A=84with=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E6=94=B9=E4=B8=BA=E8=B0=83=E7=94=A8session=E7=B1=BB?= =?UTF-8?q?=E7=9A=84flash=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Response.php | 3 ++ library/think/Session.php | 58 ++++++++++++++++++++++++++++- library/think/response/Redirect.php | 4 +- 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/library/think/Response.php b/library/think/Response.php index 8b62e419..a202ce76 100644 --- a/library/think/Response.php +++ b/library/think/Response.php @@ -130,6 +130,9 @@ class Response // 监听response_end Hook::listen('response_end', $this); + + // 清空当次请求有效的数据 + Session::flush(); } /** diff --git a/library/think/Session.php b/library/think/Session.php index e8f56fd9..822f0453 100644 --- a/library/think/Session.php +++ b/library/think/Session.php @@ -196,8 +196,42 @@ class Session } /** - * 删除session数据 + * session设置 下一次请求有效 * @param string $name session名称 + * @param mixed $value session值 + * @param string|null $prefix 作用域(前缀) + * @return void + */ + public static function flash($name, $value) + { + self::set($name, $value); + if (!self::has('__flash__.__time__')) { + self::set('__flash__.__time__', $_SERVER['REQUEST_TIME_FLOAT']); + } + self::push('__flash__', $name); + } + + /** + * 清空当前请求的session数据 + * @return void + */ + public static function flush() + { + $item = self::get('__flash__'); + + if (!empty($item)) { + $time = $item['__time__']; + if ($_SERVER['REQUEST_TIME_FLOAT'] > $time) { + unset($item['__time__']); + self::delete($item); + self::set('__flash__', []); + } + } + } + + /** + * 删除session数据 + * @param string|array $name session名称 * @param string|null $prefix 作用域(前缀) * @return void */ @@ -205,7 +239,11 @@ class Session { empty(self::$init) && self::boot(); $prefix = !is_null($prefix) ? $prefix : self::$prefix; - if (strpos($name, '.')) { + if (is_array($name)) { + foreach ($name as $key) { + self::delete($key, $prefix); + } + } elseif (strpos($name, '.')) { list($name1, $name2) = explode('.', $name); if ($prefix) { unset($_SESSION[$prefix][$name1][$name2]); @@ -256,6 +294,22 @@ class Session } } + /** + * 添加数据到一个session数组 + * @param string $key + * @param mixed $value + * @return void + */ + public static function push($key, $value) + { + $array = self::get($key); + if (is_null($array)) { + $array = []; + } + $array[] = $value; + self::set($key, $array); + } + /** * 启动session * @return void diff --git a/library/think/response/Redirect.php b/library/think/response/Redirect.php index 82a5fe32..0d65e5e3 100644 --- a/library/think/response/Redirect.php +++ b/library/think/response/Redirect.php @@ -53,10 +53,10 @@ class Redirect extends Response { if (is_array($name)) { foreach ($name as $key => $val) { - Session::set($key, $val); + Session::flash($key, $val); } } else { - Session::set($name, $value); + Session::flash($name, $value); } return $this; } -- Gitee From 4ceee7c5b2f7fde094ea61c39acc6c95fe553431 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 19 Oct 2016 17:12:11 +0800 Subject: [PATCH 0059/1170] =?UTF-8?q?invoke=E8=87=AA=E5=8A=A8=E6=B3=A8?= =?UTF-8?q?=E5=85=A5=E6=96=B9=E6=B3=95=E4=BC=A0=E5=85=A5=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/App.php b/library/think/App.php index d66e3438..98a58d71 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -283,7 +283,7 @@ class App if (method_exists($className, 'invoke')) { $method = new \ReflectionMethod($className, 'invoke'); if ($method->isPublic() && $method->isStatic()) { - $args[] = $className::invoke(); + $args[] = $className::invoke(Request::instance()); continue; } } -- Gitee From d0cc9a7146629c454d8d6084a76c4fbd16712a2b Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 19 Oct 2016 17:23:34 +0800 Subject: [PATCH 0060/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BModel=E7=B1=BB?= =?UTF-8?q?=E7=9A=84save=E6=96=B9=E6=B3=95=20=E6=96=B0=E5=A2=9E=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=9A=84=E6=97=B6=E5=80=99=E6=B7=BB=E5=8A=A0=E4=B8=8D?= =?UTF-8?q?=E6=98=AF=E8=87=AA=E5=A2=9E=E4=B8=BB=E9=94=AE=E7=9A=84=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index a96c7d6e..561792aa 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -649,7 +649,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess if (false === $this->trigger('before_write', $this)) { return false; } - + $pk = $this->getPk(); if ($this->isUpdate) { // 自动更新 $this->autoCompleteData($this->update); @@ -680,7 +680,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $where = $this->updateWhere; } - $pk = $this->getPk(); if (is_string($pk) && isset($data[$pk])) { if (!isset($where[$pk])) { unset($where); @@ -710,10 +709,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $result = $this->db()->insert($this->data); // 获取自动增长主键 - if ($result) { + if ($result && is_string($pk) && !isset($this->data[$pk])) { $insertId = $this->db()->getLastInsID($sequence); - $pk = $this->getPk(); - if (is_string($pk) && $insertId) { + if ($insertId) { $this->data[$pk] = $insertId; } } -- Gitee From cbd4c2c98c5ae31dc9dcf350ca78132949bb6625 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 19 Oct 2016 22:51:09 +0800 Subject: [PATCH 0061/1170] =?UTF-8?q?=E8=B7=AF=E7=94=B1=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E8=A7=84=E5=88=99=E6=94=AF=E6=8C=81=E9=97=AD=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index 8ecbcb7e..c97f0cb5 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1285,9 +1285,16 @@ class Route if (!$optional && !isset($m1[$key])) { return false; } - if (isset($m1[$key]) && isset($pattern[$name]) && !preg_match('/^' . $pattern[$name] . '$/', $m1[$key])) { + if (isset($m1[$key]) && isset($pattern[$name])) { // 检查变量规则 - return false; + if ($pattern[$name] instanceof \Closure) { + $result = call_user_func_array($pattern[$name], [$m1[$key]]); + if (false === $result) { + return false; + } + } elseif (!preg_match('/^' . $pattern[$name] . '$/', $m1[$key])) { + return false; + } } $var[$name] = isset($m1[$key]) ? $m1[$key] : ''; } elseif (!isset($m1[$key]) || 0 !== strcasecmp($val, $m1[$key])) { -- Gitee From 0117543df0241fb57cbd56301ce63abcaa4ea1b4 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 20 Oct 2016 10:59:28 +0800 Subject: [PATCH 0062/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BSession=E7=B1=BB?= =?UTF-8?q?=E7=9A=84flush=E6=96=B9=E6=B3=95=20=E5=88=A4=E6=96=AD=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=BC=80=E5=90=AFsession?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Session.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/library/think/Session.php b/library/think/Session.php index 822f0453..626c8c11 100644 --- a/library/think/Session.php +++ b/library/think/Session.php @@ -217,14 +217,16 @@ class Session */ public static function flush() { - $item = self::get('__flash__'); + if (self::$init) { + $item = self::get('__flash__'); - if (!empty($item)) { - $time = $item['__time__']; - if ($_SERVER['REQUEST_TIME_FLOAT'] > $time) { - unset($item['__time__']); - self::delete($item); - self::set('__flash__', []); + if (!empty($item)) { + $time = $item['__time__']; + if ($_SERVER['REQUEST_TIME_FLOAT'] > $time) { + unset($item['__time__']); + self::delete($item); + self::set('__flash__', []); + } } } } -- Gitee From 3be17ea06b23aab8d5436f026b4a9d5769444da3 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 20 Oct 2016 23:38:14 +0800 Subject: [PATCH 0063/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=9D=99=E6=80=81?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index c97f0cb5..660b8d32 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -823,14 +823,15 @@ class Route if ('|' != $url) { $url = rtrim($url, '|'); } - if (isset($rules[$url])) { + $item = str_replace('|', '/', $url); + if (isset($rules[$item])) { // 静态路由规则检测 - $rule = $rules[$url]; + $rule = $rules[$item]; if (true === $rule) { - $rule = self::getRouteExpress($url); + $rule = self::getRouteExpress($item); } if (!empty($rule['route']) && self::checkOption($rule['option'], $request)) { - return self::parseRule($url, $rule['route'], $url, $rule['option']); + return self::parseRule($item, $rule['route'], $url, $rule['option']); } } -- Gitee From c64a33588429553da4ceb0a645bfccaec8a826ed Mon Sep 17 00:00:00 2001 From: HyperQing <469379004@qq.com> Date: Fri, 21 Oct 2016 11:36:55 +0800 Subject: [PATCH 0064/1170] =?UTF-8?q?=E4=B8=BARequest=E7=B1=BB=E7=9A=84?= =?UTF-8?q?=E5=87=A0=E4=B8=AA=E6=96=B9=E6=B3=95=E5=AE=8C=E5=96=84=E6=B3=A8?= =?UTF-8?q?=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在phpstorm2016.2.1中,使用下列语句会提示警告: >Method __toString is not implemented for '\think\Request' less... (Ctrl+F1) This inspection detects attempts to convert objects without __toString() method implementation to string, since PHP 5.2.0, it would cause E_RECOVERABLE_ERROR. "Check __toString exists for each expression type": if the option is on, the inspection will check all possible types of the expression and report if at least one ot them doesn't contain __toString() method implementation. ``` $request = Request::instance(); echo "当前模块名称是" . $request->module();// 这句会被IDE提示警告 echo "当前控制器名称是" . $request->controller();// 这句会被IDE提示警告 echo "当前操作名称是" . $request->action();// 这句就不会 ``` 后来发现是注释引起的问题,注释中有@return string|$this。而action()方法却写成@return string。个人认为应该统一写成@return string|Request 比较合适。学识短浅,仅供参考 ``` /** * 设置或者获取当前的模块名 * @access public * @param string $module 模块名 * @return string|$this */ public function module($module = null) ``` --- library/think/Request.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/think/Request.php b/library/think/Request.php index 35803e3f..bc43eb2f 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -1370,7 +1370,7 @@ class Request * 设置或者获取当前的模块名 * @access public * @param string $module 模块名 - * @return string|$this + * @return string|Request */ public function module($module = null) { @@ -1386,7 +1386,7 @@ class Request * 设置或者获取当前的控制器名 * @access public * @param string $controller 控制器名 - * @return string|$this + * @return string|Request */ public function controller($controller = null) { @@ -1402,7 +1402,7 @@ class Request * 设置或者获取当前的操作名 * @access public * @param string $action 操作名 - * @return string + * @return string|Request */ public function action($action = null) { @@ -1418,7 +1418,7 @@ class Request * 设置或者获取当前的语言 * @access public * @param string $lang 语言名 - * @return string + * @return string|Request */ public function langset($lang = null) { -- Gitee From 367242113dd43c99bd724f6f29ed2892ee6bb205 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 21 Oct 2016 12:02:29 +0800 Subject: [PATCH 0065/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E5=99=A8=E8=87=AA=E5=8A=A8=E6=90=9C=E7=B4=A2=E5=90=8E=E7=9A=84?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=99=A8=E5=90=8D=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index 660b8d32..d045ec95 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1176,15 +1176,22 @@ class Route $dir = APP_PATH . ($module ? $module . DS : '') . Config::get('url_controller_layer'); $suffix = App::$suffix || Config::get('controller_suffix') ? ucfirst(Config::get('url_controller_layer')) : ''; $item = []; + $find = false; foreach ($path as $val) { - $item[] = array_shift($path); - if (is_file($dir . DS . $val . $suffix . EXT)) { + $item[] = $val; + if (is_file($dir . DS . str_replace('.', DS, $val) . $suffix . EXT)) { + $find = true; break; } else { $dir .= DS . $val; } } - $controller = implode('.', $item); + if ($find) { + $controller = implode('.', $item); + $path = array_slice($path, count($item)); + } else { + $controller = array_shift($path); + } } else { // 解析控制器 $controller = !empty($path) ? array_shift($path) : null; -- Gitee From afa1376941d8692c8c0a0b191b4055392b353f47 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 21 Oct 2016 17:21:09 +0800 Subject: [PATCH 0066/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E9=AA=8C=E8=AF=81=E8=A7=84=E5=88=99=E7=9A=84=E4=BD=BF?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index ed12083c..d40a0f63 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -348,16 +348,21 @@ class Validate $result = call_user_func_array($rule, [$value, $data]); } else { // 判断验证类型 - if (is_numeric($key) && strpos($rule, ':')) { - list($type, $rule) = explode(':', $rule, 2); - if (isset($this->alias[$type])) { - // 判断别名 - $type = $this->alias[$type]; + if (is_numeric($key)) { + if (strpos($rule, ':')) { + list($type, $rule) = explode(':', $rule, 2); + if (isset($this->alias[$type])) { + // 判断别名 + $type = $this->alias[$type]; + } + $info = $type; + } elseif (method_exists($this, $rule)) { + $type = $rule; + $info = $rule; + } else { + $type = 'is'; + $info = $rule; } - $info = $type; - } elseif (is_numeric($key)) { - $type = 'is'; - $info = $rule; } else { $info = $type = $key; } -- Gitee From 5a417480a142dd6068147d3b8bdb9153b52e9775 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 21 Oct 2016 17:36:09 +0800 Subject: [PATCH 0067/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=B1=BB=E7=9A=84activeUrl=E6=96=B9=E6=B3=95=20=E6=94=B9?= =?UTF-8?q?=E8=BF=9BQuery=E7=B1=BB=E5=88=86=E9=A1=B5=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E7=9A=84=E5=8F=82=E6=95=B0=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 3 +++ library/think/db/Query.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index d40a0f63..f16fee1b 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -612,6 +612,9 @@ class Validate */ protected function activeUrl($value, $rule) { + if (!in_array($rule, ['A', 'MX', 'NS', 'SOA', 'PTR', 'CNAME', 'AAAA', 'A6', 'SRV', 'NAPTR', 'TXT', 'ANY'])) { + $rule = 'MX'; + } return checkdnsrr($value, $rule); } diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 52b0d18c..8a8617ff 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -989,8 +989,8 @@ class Query if (!isset($total) && !$simple) { $options = $this->getOptions(); - $total = $this->count(); $bind = $this->bind; + $total = $this->count(); $results = $this->options($options)->bind($bind)->page($page, $listRows)->select(); } elseif ($simple) { $results = $this->limit(($page - 1) * $listRows, $listRows + 1)->select(); -- Gitee From 294a49b8b1f65ab865a20d10cd54e6f3e72e587b Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 21 Oct 2016 17:51:19 +0800 Subject: [PATCH 0068/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=B1=BB=E7=9A=84image=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index f16fee1b..0986c836 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -723,19 +723,24 @@ class Validate if (!($file instanceof File)) { return false; } - $rule = explode(',', $rule); - list($width, $height, $type) = getimagesize($file->getRealPath()); - if (isset($rule[2])) { - $imageType = strtolower($rule[2]); - if ('jpeg' == $imageType) { - $imageType = 'jpg'; - } - if (image_type_to_extension($type, false) != $imageType) { - return false; + if ($rule) { + $rule = explode(',', $rule); + list($width, $height, $type) = getimagesize($file->getRealPath()); + if (isset($rule[2])) { + $imageType = strtolower($rule[2]); + if ('jpeg' == $imageType) { + $imageType = 'jpg'; + } + if (image_type_to_extension($type, false) != $imageType) { + return false; + } } + + list($w, $h) = $rule; + return $w == $width && $h == $height; + } else { + return in_array($this->getImageType($file->getRealPath()), [1, 2, 3, 6]); } - list($w, $h) = $rule; - return $w == $width && $h == $height; } /** -- Gitee From d33ed07d00a520c7780e9ef58383129dd2022687 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 21 Oct 2016 18:03:47 +0800 Subject: [PATCH 0069/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=B1=BB=E4=B8=80=E5=A4=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 1 + 1 file changed, 1 insertion(+) diff --git a/library/think/Validate.php b/library/think/Validate.php index 0986c836..fc38d89a 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -359,6 +359,7 @@ class Validate } elseif (method_exists($this, $rule)) { $type = $rule; $info = $rule; + $rule = ''; } else { $type = 'is'; $info = $rule; -- Gitee From a83af519032dec4ef83c5f44beb799111f2091e2 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 21 Oct 2016 23:05:33 +0800 Subject: [PATCH 0070/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BB?= =?UTF-8?q?=E7=9A=84view=E6=96=B9=E6=B3=95=E5=92=8Cjoin=E6=96=B9=E6=B3=95?= =?UTF-8?q?=20=E6=94=AF=E6=8C=81=E4=BD=BF=E7=94=A8=E4=B8=8D=E5=B8=A6?= =?UTF-8?q?=E5=89=8D=E7=BC=80=E7=9A=84=E8=A1=A8=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 8a8617ff..e5c9b978 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -669,7 +669,11 @@ class Query $table = array_shift($join); } } else { - $table = trim($join); + $prefix = $this->prefix; + $table = trim($join); + if ($prefix && false === strpos($table, '(') && false === strpos($table, '.') && 0 !== strpos($table, $prefix) && 0 !== strpos($table, '__')) { + $table = $this->getTable($table); + } if (strpos($table, ' ') && !strpos($table, ')')) { list($table, $alias) = explode(' ', $table); $table = [$table => $alias]; @@ -763,13 +767,17 @@ class Query } } else { $fields = []; + $prefix = $this->prefix; if (is_array($join)) { // 支持数据表别名 - list($join, $alias, $table) = array_pad($join, 3, ''); + list($table, $alias) = ecch($join); + } elseif ($prefix && 0 !== strpos($join, $prefix) && 0 !== strpos($join, '__')) { + $table = $this->getTable($join); + $alias = $join; } else { $alias = $join; } - $table = !empty($table) ? $table : $this->getTable($join); + $table = isset($table) ? [$table => $alias] : $alias; if (true === $field) { $fields = $alias . '.*'; } else { @@ -793,9 +801,9 @@ class Query } $this->field($fields); if ($on) { - $this->join($table . ' ' . $alias, $on, $type); + $this->join($table, $on, $type); } else { - $this->table($table . ' ' . $alias); + $this->table($table); } } return $this; -- Gitee From 2c15118f6075bf0d27c65fb5b444c09ffb6292ff Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 21 Oct 2016 23:18:29 +0800 Subject: [PATCH 0071/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BB?= =?UTF-8?q?=E7=9A=84join=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index e5c9b978..57a1fc50 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -670,14 +670,17 @@ class Query } } else { $prefix = $this->prefix; - $table = trim($join); - if ($prefix && false === strpos($table, '(') && false === strpos($table, '.') && 0 !== strpos($table, $prefix) && 0 !== strpos($table, '__')) { - $table = $this->getTable($table); - } - if (strpos($table, ' ') && !strpos($table, ')')) { - list($table, $alias) = explode(' ', $table); + $join = trim($join); + if ($prefix && false === strpos($join, '(') && false === strpos($join, '.') && 0 !== strpos($join, $prefix) && 0 !== strpos($join, '__')) { + $table = $this->getTable($join); + $table = [$table => $join]; + $this->alias($table); + } elseif (strpos($join, ' ') && !strpos($join, ')')) { + list($table, $alias) = explode(' ', $join); $table = [$table => $alias]; $this->alias($table); + } else { + $table = $join; } } $this->options['join'][] = [$table, strtoupper($type), $condition]; -- Gitee From 463dda9d0166a5aa498175e7b1cc9f181f0671bc Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 22 Oct 2016 12:58:05 +0800 Subject: [PATCH 0072/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E5=9F=9F=E5=90=8D=E7=BB=91=E5=AE=9A=E5=90=8E=E7=9A=84url?= =?UTF-8?q?=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 2 +- library/think/Url.php | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index d045ec95..315d6667 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1203,7 +1203,7 @@ class Route // 封装路由 $route = [$module, $controller, $action]; if (isset(self::$rules['name'][implode($depr, $route)])) { - throw new HttpException(404, 'invalid request:' . $url); + throw new HttpException(404, 'invalid request:' . str_replace('|', $depr, $url)); } } return ['type' => 'module', 'module' => $route]; diff --git a/library/think/Url.php b/library/think/Url.php index 24087fc4..18b42c46 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -157,7 +157,7 @@ class Url } // 直接解析URL地址 - protected static function parseUrl($url, $domain) + protected static function parseUrl($url, &$domain) { $request = Request::instance(); if (0 === strpos($url, '/')) { @@ -171,16 +171,25 @@ class Url $url = substr($url, 1); } else { // 解析到 模块/控制器/操作 - $module = $request->module(); - $domains = Route::rules('domain'); - if (isset($domains[$domain]['[bind]'][0])) { - $bindModule = $domains[$domain]['[bind]'][0]; - if ($bindModule && !in_array($bindModule[0], ['\\', '@'])) { - $module = ''; + $module = $request->module(); + if (true === $domain) { + $domains = Route::rules('domain'); + foreach ($domains as $key => $item) { + if (isset($item['[bind]']) && 0 === strpos($url, $item['[bind]'][0])) { + $url = substr($url, strlen($item['[bind]'][0]) + 1); + $domain = $key; + $module = ''; + } + } + } elseif ($domain) { + if (isset($domains[$domain]['[bind]'][0])) { + $bindModule = $domains[$domain]['[bind]'][0]; + if ($bindModule && !in_array($bindModule[0], ['\\', '@'])) { + $module = ''; + } } - } else { - $module = $module ? $module . '/' : ''; } + $module = $module ? $module . '/' : ''; $controller = Loader::parseName($request->controller()); if ('' == $url) { -- Gitee From 04149e3ccede2c17236cacbe7a06682222d03905 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 22 Oct 2016 13:15:14 +0800 Subject: [PATCH 0073/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9Bsession=E5=8A=A9?= =?UTF-8?q?=E6=89=8B=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helper.php b/helper.php index 6ab2cb34..bcb52ea3 100644 --- a/helper.php +++ b/helper.php @@ -298,7 +298,7 @@ if (!function_exists('session')) { Session::init($name); } elseif (is_null($name)) { // 清除 - Session::clear($value); + Session::clear('' === $value ? null : $value); } elseif ('' === $value) { // 判断或获取 return 0 === strpos($name, '?') ? Session::has(substr($name, 1), $prefix) : Session::get($name, $prefix); -- Gitee From eb103a63a5c44e4268922897f0ff144bac9dfb2b Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 22 Oct 2016 13:21:49 +0800 Subject: [PATCH 0074/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BRequest=E7=B1=BBip?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/library/think/Request.php b/library/think/Request.php index bc43eb2f..c6f1198a 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -1241,8 +1241,7 @@ class Request if (false !== $pos) { unset($arr[$pos]); } - - $ip = trim($arr[0]); + $ip = trim(current($arr)); } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (isset($_SERVER['REMOTE_ADDR'])) { -- Gitee From 11f750071c6c339125fb7969ab1dbc70a1d230bb Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 22 Oct 2016 13:25:31 +0800 Subject: [PATCH 0075/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Query=E7=B1=BB?= =?UTF-8?q?=E4=B8=80=E5=A4=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 57a1fc50..cf580b20 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -773,7 +773,7 @@ class Query $prefix = $this->prefix; if (is_array($join)) { // 支持数据表别名 - list($table, $alias) = ecch($join); + list($table, $alias) = each($join); } elseif ($prefix && 0 !== strpos($join, $prefix) && 0 !== strpos($join, '__')) { $table = $this->getTable($join); $alias = $join; -- Gitee From a6f72f9ce2eff95ea85a1fb6da400d608d3e8a0e Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 22 Oct 2016 15:02:10 +0800 Subject: [PATCH 0076/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BApp=E7=B1=BB?= =?UTF-8?q?=E7=9A=84=E5=8F=8D=E5=B0=84=E5=BC=82=E5=B8=B8=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=8D=95=E8=8E=B7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/library/think/App.php b/library/think/App.php index 98a58d71..ce7fd37a 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -369,33 +369,28 @@ class App // 监听module_init Hook::listen('module_init', $request); - try { - $instance = Loader::controller($controller, $config['url_controller_layer'], $config['controller_suffix'], $config['empty_controller']); - if (is_null($instance)) { - throw new HttpException(404, 'controller not exists:' . Loader::parseName($controller, 1)); - } - // 获取当前操作名 - $action = $actionName . $config['action_suffix']; - if (!preg_match('/^[A-Za-z](\w)*$/', $action)) { - // 非法操作 - throw new \ReflectionException('illegal action name:' . $actionName); - } + $instance = Loader::controller($controller, $config['url_controller_layer'], $config['controller_suffix'], $config['empty_controller']); + if (is_null($instance)) { + throw new HttpException(404, 'controller not exists:' . Loader::parseName($controller, 1)); + } + // 获取当前操作名 + $action = $actionName . $config['action_suffix']; + if (is_callable([$instance, $action])) { // 执行操作方法 $call = [$instance, $action]; - Hook::listen('action_begin', $call); - - $data = self::invokeMethod($call); - } catch (\ReflectionException $e) { + } elseif (is_callable([$instance, '_empty'])) { + // 空操作 + $call = [$instance, '_empty']; + } else { // 操作不存在 - if (method_exists($instance, '_empty')) { - $reflect = new \ReflectionMethod($instance, '_empty'); - $data = $reflect->invokeArgs($instance, [$action]); - self::$debug && Log::record('[ RUN ] ' . $reflect->__toString(), 'info'); - } else { - throw new HttpException(404, 'method not exists:' . (new \ReflectionClass($instance))->getName() . '->' . $action); - } + throw new HttpException(404, 'method not exists:' . get_class($instance) . '->' . $action . '()'); } + + Hook::listen('action_begin', $call); + + $data = self::invokeMethod($call); + return $data; } -- Gitee From 9c57100d676e4617a160a38d599646e0f8d0874a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 22 Oct 2016 19:42:55 +0800 Subject: [PATCH 0077/1170] =?UTF-8?q?=E8=B7=AF=E7=94=B1=E6=A0=87=E8=AF=86?= =?UTF-8?q?=E4=B8=8D=E5=8C=BA=E5=88=86=E5=A4=A7=E5=B0=8F=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index 315d6667..5553a0fb 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -306,7 +306,7 @@ class Route $vars = self::parseVar($rule); if (isset($name)) { $key = $group ? $group . '/' . $rule : $rule; - self::name($name, [$key, $vars, self::$domain]); + self::name(strtolower($name), [$key, $vars, self::$domain]); } if ($group) { if ('*' != $type) { @@ -1202,7 +1202,7 @@ class Route self::parseUrlParams(empty($path) ? '' : implode('|', $path)); // 封装路由 $route = [$module, $controller, $action]; - if (isset(self::$rules['name'][implode($depr, $route)])) { + if (isset(self::$rules['name'][strtolower(implode($depr, $route))])) { throw new HttpException(404, 'invalid request:' . str_replace('|', $depr, $url)); } } -- Gitee From 79d640f3a9280e9f23f108c21790348d473b2628 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 22 Oct 2016 19:53:48 +0800 Subject: [PATCH 0078/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Route=E7=B1=BBname?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 1 + 1 file changed, 1 insertion(+) diff --git a/library/think/Route.php b/library/think/Route.php index 5553a0fb..29116167 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -150,6 +150,7 @@ class Route } elseif (!is_null($value)) { self::$rules['name'][$name][] = $value; } else { + $name = strtolower($name); return isset(self::$rules['name'][$name]) ? self::$rules['name'][$name] : null; } } -- Gitee From d961dd976542c52c3b7b0bd56cd81c5efba0f8e0 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 22 Oct 2016 20:05:51 +0800 Subject: [PATCH 0079/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E7=B1=BB=E7=9A=84parseUrl=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Route.php b/library/think/Route.php index 29116167..df1b62b9 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1203,7 +1203,7 @@ class Route self::parseUrlParams(empty($path) ? '' : implode('|', $path)); // 封装路由 $route = [$module, $controller, $action]; - if (isset(self::$rules['name'][strtolower(implode($depr, $route))])) { + if (isset(self::$rules['name'][strtolower($module . '/' . Loader::parseName($controller, 1) . '/' . $action)])) { throw new HttpException(404, 'invalid request:' . str_replace('|', $depr, $url)); } } -- Gitee From b5b5390832e7c509c8af2aa81c0fdfec3a0f5c33 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 22 Oct 2016 20:24:55 +0800 Subject: [PATCH 0080/1170] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E6=83=85=E5=86=B5=E4=B8=8B=20=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E6=A0=87=E8=AF=86=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/library/think/Route.php b/library/think/Route.php index df1b62b9..c07bf5e5 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1203,7 +1203,14 @@ class Route self::parseUrlParams(empty($path) ? '' : implode('|', $path)); // 封装路由 $route = [$module, $controller, $action]; - if (isset(self::$rules['name'][strtolower($module . '/' . Loader::parseName($controller, 1) . '/' . $action)])) { + // 检查地址是否被定义过路由 + $name = strtolower($module . '/' . Loader::parseName($controller, 1) . '/' . $action); + $name2 = ''; + if (isset(self::$bind['module']) && $module == self::$bind['module']) { + $name2 = strtolower(Loader::parseName($controller, 1) . '/' . $action); + } + + if (isset(self::$rules['name'][$name]) || isset(self::$rules['name'][$name2])) { throw new HttpException(404, 'invalid request:' . str_replace('|', $depr, $url)); } } -- Gitee From 70e534f2fb1f0400555a180a339b58e71575ea5a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 22 Oct 2016 21:02:04 +0800 Subject: [PATCH 0081/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BRoute=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Route.php b/library/think/Route.php index c07bf5e5..24549d1a 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1206,7 +1206,7 @@ class Route // 检查地址是否被定义过路由 $name = strtolower($module . '/' . Loader::parseName($controller, 1) . '/' . $action); $name2 = ''; - if (isset(self::$bind['module']) && $module == self::$bind['module']) { + if (empty($module) || isset(self::$bind['module']) && $module == self::$bind['module']) { $name2 = strtolower(Loader::parseName($controller, 1) . '/' . $action); } -- Gitee From ae7a9a08a7c7882b756148e0bb55715d25dcaede Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 23 Oct 2016 13:22:40 +0800 Subject: [PATCH 0082/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BRoute=E7=B1=BBrules?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Route.php b/library/think/Route.php index 24549d1a..406c088e 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -683,7 +683,7 @@ class Route if (is_array($rules)) { self::$rules = $rules; } elseif ($rules) { - return true === $rules ? self::$rules : self::$rules[$rules]; + return true === $rules ? self::$rules : self::$rules[strtolower($rules)]; } else { $rules = self::$rules; unset($rules['pattern'], $rules['alias'], $rules['domain'], $rules['name']); -- Gitee From 747b7fe7fa59c504660005f0448868cedf71158f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 23 Oct 2016 21:53:10 +0800 Subject: [PATCH 0083/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=BB=91=E5=AE=9A=E5=88=B0=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E5=99=A8=E5=88=86=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/think/Route.php b/library/think/Route.php index 406c088e..be24c7c4 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1163,8 +1163,9 @@ class Route { if (isset(self::$bind['module'])) { + $bind = str_replace('/', $depr, self::$bind['module']); // 如果有模块/控制器绑定 - $url = self::$bind['module'] . '/' . ltrim($url, '/'); + $url = $bind . ('.' != substr($bind, -1) ? $depr : '') . ltrim($url, $depr); } $url = str_replace($depr, '|', $url); list($path, $var) = self::parseUrlPath($url); -- Gitee From 4865355dfc3ec4aa9c217ee36bb45489d1cb7a4e Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 23 Oct 2016 22:10:53 +0800 Subject: [PATCH 0084/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BRoute=E7=B1=BBparse?= =?UTF-8?q?Url=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Route.php b/library/think/Route.php index be24c7c4..f3da8139 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1207,7 +1207,7 @@ class Route // 检查地址是否被定义过路由 $name = strtolower($module . '/' . Loader::parseName($controller, 1) . '/' . $action); $name2 = ''; - if (empty($module) || isset(self::$bind['module']) && $module == self::$bind['module']) { + if (empty($module) || isset($bind) && $module == $bind) { $name2 = strtolower(Loader::parseName($controller, 1) . '/' . $action); } -- Gitee From 8f6cee67eda98af26e553ab447f3a0346d37dcf7 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 23 Oct 2016 22:29:11 +0800 Subject: [PATCH 0085/1170] =?UTF-8?q?=E8=B7=AF=E7=94=B1=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E6=94=B9=E4=B8=BA=E5=B0=8F=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 53 +++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index f3da8139..ca98d88f 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -24,13 +24,13 @@ class Route { // 路由规则 private static $rules = [ - 'GET' => [], - 'POST' => [], - 'PUT' => [], - 'DELETE' => [], - 'PATCH' => [], - 'HEAD' => [], - 'OPTIONS' => [], + 'get' => [], + 'post' => [], + 'put' => [], + 'delete' => [], + 'patch' => [], + 'head' => [], + 'options' => [], '*' => [], 'alias' => [], 'domain' => [], @@ -40,21 +40,22 @@ class Route // REST路由操作方法定义 private static $rest = [ - 'index' => ['GET', '', 'index'], - 'create' => ['GET', '/create', 'create'], - 'edit' => ['GET', '/:id/edit', 'edit'], - 'read' => ['GET', '/:id', 'read'], - 'save' => ['POST', '', 'save'], - 'update' => ['PUT', '/:id', 'update'], - 'delete' => ['DELETE', '/:id', 'delete'], + 'index' => ['get', '', 'index'], + 'create' => ['get', '/create', 'create'], + 'edit' => ['get', '/:id/edit', 'edit'], + 'read' => ['get', '/:id', 'read'], + 'save' => ['post', '', 'save'], + 'update' => ['put', '/:id', 'update'], + 'delete' => ['delete', '/:id', 'delete'], ]; // 不同请求类型的方法前缀 private static $methodPrefix = [ - 'GET' => 'get', - 'POST' => 'post', - 'PUT' => 'put', - 'DELETE' => 'delete', + 'get' => 'get', + 'post' => 'post', + 'put' => 'put', + 'delete' => 'delete', + 'patch' => 'patch', ]; // 子域名 @@ -199,7 +200,7 @@ class Route unset($rule['__rest__']); } - self::registerRules($rule, strtoupper($type)); + self::registerRules($rule, strtolower($type)); } // 批量注册路由 @@ -242,7 +243,7 @@ class Route $pattern = array_merge(self::getGroup('pattern'), $pattern); } - $type = strtoupper($type); + $type = strtolower($type); if (strpos($type, '|')) { $option['method'] = $type; @@ -329,7 +330,7 @@ class Route } if ('*' == $type) { // 注册路由快捷方式 - foreach (['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'] as $method) { + foreach (['get', 'post', 'put', 'delete', 'patch', 'head', 'options'] as $method) { if (self::$domain) { self::$rules['domain'][self::$domain][$method][$rule] = true; } else { @@ -432,7 +433,7 @@ class Route self::$rules['*'][$name] = ['rule' => $item, 'route' => '', 'var' => [], 'option' => $option, 'pattern' => $pattern]; } - foreach (['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'] as $method) { + foreach (['get', 'post', 'put', 'delete', 'patch', 'head', 'options'] as $method) { if (!isset(self::$rules[$method][$name])) { self::$rules[$method][$name] = true; } elseif (is_array(self::$rules[$method][$name])) { @@ -626,9 +627,9 @@ class Route public static function setMethodPrefix($method, $prefix = '') { if (is_array($method)) { - self::$methodPrefix = array_merge(self::$methodPrefix, array_change_key_case($method, CASE_UPPER)); + self::$methodPrefix = array_merge(self::$methodPrefix, array_change_key_case($method)); } else { - self::$methodPrefix[strtoupper($method)] = $prefix; + self::$methodPrefix[strtolower($method)] = $prefix; } } @@ -699,7 +700,7 @@ class Route * @param string $method 请求类型 * @return void */ - public static function checkDomain($request, &$currentRules, $method = 'GET') + public static function checkDomain($request, &$currentRules, $method = 'get') { // 域名规则 $rules = self::$rules['domain']; @@ -809,7 +810,7 @@ class Route return $result; } } - $method = $request->method(); + $method = strtolower($request->method()); // 获取当前请求类型的路由规则 $rules = self::$rules[$method]; // 检测域名部署 -- Gitee From aca32d1da34ddef7ad3c423c3dc46c77115e7157 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 23 Oct 2016 23:40:36 +0800 Subject: [PATCH 0086/1170] =?UTF-8?q?=E8=B7=AF=E7=94=B1=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0ajax=E5=92=8Cpjax?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base.php | 2 +- library/think/Route.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/base.php b/base.php index 1184dc51..b668120e 100644 --- a/base.php +++ b/base.php @@ -9,7 +9,7 @@ // | Author: liu21st // +---------------------------------------------------------------------- -define('THINK_VERSION', '5.0.2dev'); +define('THINK_VERSION', '5.0.2'); define('THINK_START_TIME', microtime(true)); define('THINK_START_MEM', memory_get_usage()); define('EXT', '.php'); diff --git a/library/think/Route.php b/library/think/Route.php index ca98d88f..2db507ed 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1093,7 +1093,9 @@ class Route { // 请求类型检测 if ((isset($option['method']) && is_string($option['method']) && false === stripos($option['method'], $request->method())) - || (isset($option['ext']) && false === stripos($option['ext'], $request->ext())) // 伪静态后缀检测 + || (!empty($option['ajax']) && !$request->isAjax()) // Ajax检测 + || (!empty($option['pjax']) && !$request->isPjax()) // Pjax检测 + || (isset($option['ext']) && false === stripos($option['ext'], $request->ext())) // 伪静态后缀检测 || (isset($option['deny_ext']) && false !== stripos($option['deny_ext'], $request->ext())) || (isset($option['domain']) && !in_array($option['domain'], [$_SERVER['HTTP_HOST'], self::$subDomain])) // 域名检测 || (!empty($option['https']) && !$request->isSsl()) // https检测 -- Gitee From fa2bc7343d9dc012c7554ba05e702a88dcfea4a6 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 24 Oct 2016 07:11:16 +0800 Subject: [PATCH 0087/1170] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convention.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/convention.php b/convention.php index 206603b1..2ef29dcd 100644 --- a/convention.php +++ b/convention.php @@ -85,6 +85,8 @@ return [ 'url_route_on' => true, // 路由配置文件(支持配置多个) 'route_config_file' => ['route'], + // 路由使用完整匹配 + 'route_complete_match' => false, // 是否强制使用路由 'url_route_must' => false, // 域名部署 -- Gitee From 4e8467b83030cb82fee7dd3f442efd9f80c4e5ab Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 24 Oct 2016 11:12:02 +0800 Subject: [PATCH 0088/1170] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20=E6=96=B0?= =?UTF-8?q?=E7=9A=84RouteNotFoundException=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 3 ++- .../exception/RouteNotFoundException.php | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 library/think/exception/RouteNotFoundException.php diff --git a/library/think/App.php b/library/think/App.php index ce7fd37a..ddb147f3 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -16,6 +16,7 @@ use think\Env; use think\Exception; use think\exception\HttpException; use think\exception\HttpResponseException; +use think\exception\RouteNotFoundException; use think\Hook; use think\Lang; use think\Loader; @@ -547,7 +548,7 @@ class App $must = !is_null(self::$routeMust) ? self::$routeMust : $config['url_route_must']; if ($must && false === $result) { // 路由无效 - throw new HttpException(404, 'Route Not Found'); + throw new RouteNotFoundException(); } } if (false === $result) { diff --git a/library/think/exception/RouteNotFoundException.php b/library/think/exception/RouteNotFoundException.php new file mode 100644 index 00000000..6ee2f7b6 --- /dev/null +++ b/library/think/exception/RouteNotFoundException.php @@ -0,0 +1,24 @@ + +// +---------------------------------------------------------------------- + +namespace think\exception; + +use think\exception\HttpException; + +class RouteNotFoundException extends HttpException +{ + + public function __construct() + { + parent::__construct(404); + } + +} -- Gitee From 0674c774981517e48911eafc0f1102a8fe56a022 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 24 Oct 2016 14:15:09 +0800 Subject: [PATCH 0089/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BB?= =?UTF-8?q?=E7=9A=84view=E5=92=8Cjoin=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index cf580b20..c78b17c1 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -671,7 +671,7 @@ class Query } else { $prefix = $this->prefix; $join = trim($join); - if ($prefix && false === strpos($join, '(') && false === strpos($join, '.') && 0 !== strpos($join, $prefix) && 0 !== strpos($join, '__')) { + if ($prefix && false === strpos($join, ' ') && false === strpos($join, '(') && false === strpos($join, '.') && 0 !== strpos($join, $prefix) && 0 !== strpos($join, '__')) { $table = $this->getTable($join); $table = [$table => $join]; $this->alias($table); @@ -774,9 +774,11 @@ class Query if (is_array($join)) { // 支持数据表别名 list($table, $alias) = each($join); - } elseif ($prefix && 0 !== strpos($join, $prefix) && 0 !== strpos($join, '__')) { + } elseif ($prefix && false === strpos($join, ' ') && 0 !== strpos($join, $prefix) && 0 !== strpos($join, '__')) { $table = $this->getTable($join); $alias = $join; + } elseif (strpos($join, ' ')) { + list($table, $alias) = explode(' ', $join); } else { $alias = $join; } -- Gitee From 6e5d83d513dbfd9044a3dc7ca4cc9e3cf3c11e0f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 24 Oct 2016 18:13:35 +0800 Subject: [PATCH 0090/1170] =?UTF-8?q?=E8=B5=84=E6=BA=90=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=B3=A8=E5=86=8C=E7=9A=84=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E8=A7=84=E5=88=99=20=E8=AE=B0=E5=BD=95=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9A=84=20=E8=B5=84=E6=BA=90=E6=A0=87?= =?UTF-8?q?=E8=AF=86=20=E4=BD=BF=E7=94=A8=20=E8=B7=AF=E7=94=B1=E5=8F=82?= =?UTF-8?q?=E6=95=B0=20=20rest=20=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index 2db507ed..c353c721 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -578,7 +578,8 @@ class Route } elseif (strpos($val[1], ':id') && isset($option['var'][$rule])) { $val[1] = str_replace(':id', ':' . $option['var'][$rule], $val[1]); } - $item = ltrim($rule . $val[1], '/'); + $item = ltrim($rule . $val[1], '/'); + $option['rest'] = $key; self::rule($item . '$', $route . '/' . $val[2], $val[0], $option, $pattern); } } @@ -637,7 +638,7 @@ class Route * rest方法定义和修改 * @access public * @param string $name 方法名称 - * @param array $resourece 资源 + * @param array $resource 资源 * @return void */ public static function rest($name, $resource = []) -- Gitee From 2477345218b0d69ff1dd0bb6b913909c7feeb13f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 25 Oct 2016 14:46:02 +0800 Subject: [PATCH 0091/1170] =?UTF-8?q?=E4=BC=98=E5=8C=96Connection=E7=B1=BB?= =?UTF-8?q?=E7=9A=84getRealSql=E6=96=B9=E6=B3=95=E7=94=9F=E6=88=90?= =?UTF-8?q?=E7=9A=84sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 4 +--- library/think/db/Connection.php | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/library/think/App.php b/library/think/App.php index ddb147f3..40c726c8 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -390,9 +390,7 @@ class App Hook::listen('action_begin', $call); - $data = self::invokeMethod($call); - - return $data; + return self::invokeMethod($call); } /** diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index f39ca341..9806b827 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -433,7 +433,7 @@ abstract class Connection $sql . ' '); } } - return $sql; + return rtrim($sql); } /** -- Gitee From 535e17b1a03085ed73fdc1e57f555e1abee08fd1 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 25 Oct 2016 20:42:21 +0800 Subject: [PATCH 0092/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=BD=AF=E5=88=A0?= =?UTF-8?q?=E9=99=A4withTrashed=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/traits/model/SoftDelete.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/traits/model/SoftDelete.php b/library/traits/model/SoftDelete.php index 4bb072dc..e110ff25 100644 --- a/library/traits/model/SoftDelete.php +++ b/library/traits/model/SoftDelete.php @@ -27,7 +27,7 @@ trait SoftDelete public static function withTrashed() { $model = new static(); - return $model->db(); + return $model->db(false); } /** @@ -39,7 +39,7 @@ trait SoftDelete { $model = new static(); $field = $model->getDeleteTimeField(); - return $model->db()->where($field, 'exp', 'is not null'); + return $model->db(false)->where($field, 'exp', 'is not null'); } /** -- Gitee From a3f80621b556995789870b03df3e7fd8d8017c2c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 25 Oct 2016 22:54:40 +0800 Subject: [PATCH 0093/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BB?= =?UTF-8?q?=E7=9A=84paginate=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index c78b17c1..796dd769 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1002,6 +1002,9 @@ class Query if (!isset($total) && !$simple) { $options = $this->getOptions(); + if (isset($options['order'])) { + unset($this->options['order']); + } $bind = $this->bind; $total = $this->count(); $results = $this->options($options)->bind($bind)->page($page, $listRows)->select(); -- Gitee From d8c25a7970f74bb13e14223c5ae117d12d7094c1 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 25 Oct 2016 23:15:41 +0800 Subject: [PATCH 0094/1170] =?UTF-8?q?cache=E5=8A=A9=E6=89=8B=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E6=94=AF=E6=8C=81=20remember=E6=96=B9=E6=B3=95=20?= =?UTF-8?q?=EF=BC=8C=E7=94=A8=E6=B3=95=E4=B8=BA=EF=BC=9A=20cache('=3Fname'?= =?UTF-8?q?,function(){=20=20=20=20return=20'value';=20});=20=E6=88=96?= =?UTF-8?q?=E8=80=85=20cache('=3Fname','value);?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/helper.php b/helper.php index bcb52ea3..e0cc719e 100644 --- a/helper.php +++ b/helper.php @@ -365,6 +365,9 @@ if (!function_exists('cache')) { } elseif (is_null($value)) { // 删除缓存 return Cache::rm($name); + } elseif (0 === strpos($name, '?') && '' !== $value) { + $expire = is_numeric($options) ? $options : null; + return Cache::remember(substr($name, 1), $value, $expire); } else { // 缓存数据 if (is_array($options)) { -- Gitee From d96a037e490b4fb8221263dc30fb0f25071b1d4b Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 25 Oct 2016 23:56:17 +0800 Subject: [PATCH 0095/1170] =?UTF-8?q?=E8=A7=86=E5=9B=BE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E6=94=AF=E6=8C=81=E9=9B=86=E4=B8=AD=E5=BC=8F?= =?UTF-8?q?=E5=AD=98=E6=94=BE=20=E4=B8=8D=E6=94=BE=E5=85=A5=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/view/driver/Think.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/library/think/view/driver/Think.php b/library/think/view/driver/Think.php index 33729b44..db1d9816 100644 --- a/library/think/view/driver/Think.php +++ b/library/think/view/driver/Think.php @@ -24,6 +24,8 @@ class Think private $template; // 模板引擎参数 protected $config = [ + // 视图基础目录(集中式) + 'view_base' => '', // 模板起始路径 'view_path' => '', // 模板文件后缀 @@ -103,18 +105,21 @@ class Think */ private function parseTemplate($template) { + // 分析模板文件规则 + $request = Request::instance(); // 获取视图根目录 if (strpos($template, '@')) { // 跨模块调用 list($module, $template) = explode('@', $template); - $path = APP_PATH . $module . DS . 'view' . DS; + } + if ($this->config['view_base']) { + // 基础视图目录 + $module = isset($module) ? $module : $request->module(); + $path = $this->config['view_base'] . ($module ? $module . DS : ''); } else { - // 当前视图目录 - $path = $this->config['view_path']; + $path = isset($module) ? APP_PATH . $module . DS . 'view' . DS : $this->config['view_path']; } - // 分析模板文件规则 - $request = Request::instance(); $controller = Loader::parseName($request->controller()); if ($controller && 0 !== strpos($template, '/')) { $depr = $this->config['view_depr']; -- Gitee From 97fbbbc0e392933dc4c6564c8a7e58a4c6f2738d Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 26 Oct 2016 08:29:25 +0800 Subject: [PATCH 0096/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Url=E7=B1=BB?= =?UTF-8?q?=E5=9F=9F=E5=90=8D=E9=83=A8=E7=BD=B2=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Url.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/library/think/Url.php b/library/think/Url.php index 18b42c46..663c5de6 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -29,7 +29,7 @@ class Url * @param boolean|string $domain 是否显示域名 或者直接传入域名 * @return string */ - public static function build($url = '', $vars = '', $suffix = true, $domain = false) + public static function build($url = '', $vars = '', $suffix = true, $domain = null) { if (false === $domain && Config::get('url_domain_deploy')) { $domain = true; @@ -172,13 +172,14 @@ class Url } else { // 解析到 模块/控制器/操作 $module = $request->module(); - if (true === $domain) { + if (true === $domain && 2 == substr_count($url, '/')) { $domains = Route::rules('domain'); foreach ($domains as $key => $item) { if (isset($item['[bind]']) && 0 === strpos($url, $item['[bind]'][0])) { $url = substr($url, strlen($item['[bind]'][0]) + 1); $domain = $key; $module = ''; + break; } } } elseif ($domain) { -- Gitee From 31aae17f55b4f69580696a881f6e783e44e4c636 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 26 Oct 2016 08:45:25 +0800 Subject: [PATCH 0097/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BApp=E7=B1=BB?= =?UTF-8?q?=E7=9A=84=E7=A9=BA=E6=93=8D=E4=BD=9C=E6=96=B9=E6=B3=95=E8=B0=83?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/think/App.php b/library/think/App.php index 40c726c8..7feff2fe 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -377,12 +377,14 @@ class App // 获取当前操作名 $action = $actionName . $config['action_suffix']; + $vars = []; if (is_callable([$instance, $action])) { // 执行操作方法 $call = [$instance, $action]; } elseif (is_callable([$instance, '_empty'])) { // 空操作 $call = [$instance, '_empty']; + $vars = [$action]; } else { // 操作不存在 throw new HttpException(404, 'method not exists:' . get_class($instance) . '->' . $action . '()'); @@ -390,7 +392,7 @@ class App Hook::listen('action_begin', $call); - return self::invokeMethod($call); + return self::invokeMethod($call, $vars); } /** -- Gitee From 39cbbc0a38ce3fc7d5319f1fa9e571ca84f20ef4 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 26 Oct 2016 11:09:49 +0800 Subject: [PATCH 0098/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BUrl=E7=B1=BB=20?= =?UTF-8?q?=E5=9F=9F=E5=90=8D=E9=83=A8=E7=BD=B2url=E7=94=9F=E6=88=90=20URL?= =?UTF-8?q?=E7=94=9F=E6=88=90=E4=B8=8D=E4=BE=9D=E8=B5=96=20url=5Fdomain=5F?= =?UTF-8?q?deploy=20=E9=85=8D=E7=BD=AE=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper.php | 2 +- library/think/Url.php | 67 ++++++++++++++++++++++++++----------------- 2 files changed, 42 insertions(+), 27 deletions(-) diff --git a/helper.php b/helper.php index e0cc719e..007c76cd 100644 --- a/helper.php +++ b/helper.php @@ -277,7 +277,7 @@ if (!function_exists('url')) { * @param bool|string $domain 域名 * @return string */ - function url($url = '', $vars = '', $suffix = true, $domain = false) + function url($url = '', $vars = '', $suffix = true, $domain = true) { return Url::build($url, $vars, $suffix, $domain); } diff --git a/library/think/Url.php b/library/think/Url.php index 663c5de6..87a79ed0 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -20,6 +20,7 @@ class Url { // 生成URL地址的root protected static $root; + protected static $bindCheck; /** * URL生成 支持路由反射 @@ -29,11 +30,8 @@ class Url * @param boolean|string $domain 是否显示域名 或者直接传入域名 * @return string */ - public static function build($url = '', $vars = '', $suffix = true, $domain = null) + public static function build($url = '', $vars = '', $suffix = true, $domain = true) { - if (false === $domain && Config::get('url_domain_deploy')) { - $domain = true; - } // 解析URL if (0 === strpos($url, '[') && $pos = strpos($url, ']')) { // [name] 表示使用路由命名标识生成URL @@ -112,11 +110,13 @@ class Url } // 检测URL绑定 - $type = Route::getBind('type'); - if ($type) { - $bind = Route::getBind($type); - if (0 === strpos($url, $bind)) { - $url = substr($url, strlen($bind) + 1); + if (!self::$bindCheck) { + $type = Route::getBind('type'); + if ($type) { + $bind = Route::getBind($type); + if (0 === strpos($url, $bind)) { + $url = substr($url, strlen($bind) + 1); + } } } // 还原URL分隔符 @@ -173,15 +173,28 @@ class Url // 解析到 模块/控制器/操作 $module = $request->module(); if (true === $domain && 2 == substr_count($url, '/')) { + $current = $request->host(); $domains = Route::rules('domain'); + $match = []; + $pos = []; foreach ($domains as $key => $item) { if (isset($item['[bind]']) && 0 === strpos($url, $item['[bind]'][0])) { - $url = substr($url, strlen($item['[bind]'][0]) + 1); - $domain = $key; - $module = ''; - break; + $pos[$key] = strlen($item['[bind]'][0]) + 1; + $match[] = $key; + $module = ''; + } + } + if ($match) { + $domain = current($match); + foreach ($match as $item) { + if (0 === strpos($current, $item)) { + $domain = $item; + } } + self::$bindCheck = true; + $url = substr($url, $pos[$domain]); } + } elseif ($domain) { if (isset($domains[$domain]['[bind]'][0])) { $bindModule = $domains[$domain]['[bind]'][0]; @@ -213,15 +226,15 @@ class Url if (!$domain) { return ''; } - $request = Request::instance(); + $request = Request::instance(); + $rootDomain = Config::get('url_domain_root'); if (true === $domain) { // 自动判断域名 $domain = $request->host(); - if (Config::get('url_domain_deploy')) { - // 根域名 - $urlDomainRoot = Config::get('url_domain_root'); - $domains = Route::rules('domain'); - $route_domain = array_keys($domains); + + $domains = Route::rules('domain'); + if ($domains) { + $route_domain = array_keys($domains); foreach ($route_domain as $domain_prefix) { if (0 === strpos($domain_prefix, '*.') && strpos($domain, ltrim($domain_prefix, '*.')) !== false) { foreach ($domains as $key => $rule) { @@ -230,13 +243,13 @@ class Url $url = ltrim($url, $rule); $domain = $key; // 生成对应子域名 - if (!empty($urlDomainRoot)) { - $domain .= $urlDomainRoot; + if (!empty($rootDomain)) { + $domain .= $rootDomain; } break; } else if (false !== strpos($key, '*')) { - if (!empty($urlDomainRoot)) { - $domain .= $urlDomainRoot; + if (!empty($rootDomain)) { + $domain .= $rootDomain; } break; } @@ -244,13 +257,15 @@ class Url } } } - } elseif (!strpos($domain, '.')) { - $rootDomain = Config::get('url_domain_root'); + + } else { if (empty($rootDomain)) { $host = $request->host(); $rootDomain = substr_count($host, '.') > 1 ? substr(strstr($host, '.'), 1) : $host; } - $domain .= '.' . $rootDomain; + if (!strpos($domain, $rootDomain)) { + $domain .= '.' . $rootDomain; + } } return ($request->isSsl() ? 'https://' : 'http://') . $domain; } -- Gitee From 087e968b806846a985e66ccc57624ea8328f5a51 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 26 Oct 2016 11:34:36 +0800 Subject: [PATCH 0099/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BBwhere?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 796dd769..0c9d8ef7 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -906,13 +906,9 @@ class Query if (is_array($field)) { // 数组批量查询 $where = $field; - } elseif ($field) { + } elseif ($field && is_string($field)) { // 字符串查询 - if (is_numeric($field)) { - $where[] = ['exp', $field]; - } else { - $where[$field] = ['null', '']; - } + $where[$field] = ['null', '']; } } elseif (is_array($op)) { $where[$field] = $param; -- Gitee From 82b94b555f36805faf7dffcfb2d00ca1945cff9a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 26 Oct 2016 12:10:35 +0800 Subject: [PATCH 0100/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper.php | 2 +- library/think/Url.php | 6 ++++-- tests/thinkphp/library/think/urlTest.php | 14 +++++++------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/helper.php b/helper.php index 007c76cd..e0cc719e 100644 --- a/helper.php +++ b/helper.php @@ -277,7 +277,7 @@ if (!function_exists('url')) { * @param bool|string $domain 域名 * @return string */ - function url($url = '', $vars = '', $suffix = true, $domain = true) + function url($url = '', $vars = '', $suffix = true, $domain = false) { return Url::build($url, $vars, $suffix, $domain); } diff --git a/library/think/Url.php b/library/think/Url.php index 87a79ed0..b4ae0aac 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -30,8 +30,11 @@ class Url * @param boolean|string $domain 是否显示域名 或者直接传入域名 * @return string */ - public static function build($url = '', $vars = '', $suffix = true, $domain = true) + public static function build($url = '', $vars = '', $suffix = true, $domain = false) { + if (false === $domain && Route::rules('domain')) { + $domain = true; + } // 解析URL if (0 === strpos($url, '[') && $pos = strpos($url, ']')) { // [name] 表示使用路由命名标识生成URL @@ -194,7 +197,6 @@ class Url self::$bindCheck = true; $url = substr($url, $pos[$domain]); } - } elseif ($domain) { if (isset($domains[$domain]['[bind]'][0])) { $bindModule = $domains[$domain]['[bind]'][0]; diff --git a/tests/thinkphp/library/think/urlTest.php b/tests/thinkphp/library/think/urlTest.php index ced519d7..acb43365 100644 --- a/tests/thinkphp/library/think/urlTest.php +++ b/tests/thinkphp/library/think/urlTest.php @@ -25,13 +25,13 @@ class urlTest extends \PHPUnit_Framework_TestCase public function setUp() { - Route::rules(['GET' => [], - 'POST' => [], - 'PUT' => [], - 'DELETE' => [], - 'PATCH' => [], - 'HEAD' => [], - 'OPTIONS' => [], + Route::rules(['get' => [], + 'post' => [], + 'put' => [], + 'delete' => [], + 'patch' => [], + 'head' => [], + 'options' => [], '*' => [], 'alias' => [], 'domain' => [], -- Gitee From 9062808a0540158cd5651087abffbf7f04339d42 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 26 Oct 2016 17:44:15 +0800 Subject: [PATCH 0101/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=88=86=E7=BB=84?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E7=9A=84url=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index c353c721..1d4e0e7b 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -307,7 +307,8 @@ class Route } $vars = self::parseVar($rule); if (isset($name)) { - $key = $group ? $group . '/' . $rule : $rule; + $rule = ltrim($rule, '/'); + $key = $group ? $group . ($rule ? '/' . $rule : '') : $rule; self::name(strtolower($name), [$key, $vars, self::$domain]); } if ($group) { @@ -428,7 +429,8 @@ class Route $vars = self::parseVar($key); $item[] = ['rule' => $key, 'route' => $route, 'var' => $vars, 'option' => $options, 'pattern' => $patterns]; // 设置路由标识 - self::name($route, [$name . '/' . $key, $vars, self::$domain]); + $key = ltrim($key, '/'); + self::name($route, [$name . ($key ? '/' . $key : ''), $vars, self::$domain]); } self::$rules['*'][$name] = ['rule' => $item, 'route' => '', 'var' => [], 'option' => $option, 'pattern' => $pattern]; } -- Gitee From c977af79210ce566ba43cca09d7396a929a9e63e Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 26 Oct 2016 18:11:38 +0800 Subject: [PATCH 0102/1170] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E5=88=86=E7=BB=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index 1d4e0e7b..83442cba 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -302,13 +302,12 @@ class Route $rule = substr($rule, 0, -1); } - if ('/' != $rule) { + if ('/' != $rule || $group) { $rule = trim($rule, '/'); } $vars = self::parseVar($rule); if (isset($name)) { - $rule = ltrim($rule, '/'); - $key = $group ? $group . ($rule ? '/' . $rule : '') : $rule; + $key = $group ? $group . ($rule ? '/' . $rule : '') : $rule; self::name(strtolower($name), [$key, $vars, self::$domain]); } if ($group) { @@ -426,10 +425,10 @@ class Route $options['complete_match'] = true; $key = substr($key, 0, -1); } + $key = trim($key, '/'); $vars = self::parseVar($key); $item[] = ['rule' => $key, 'route' => $route, 'var' => $vars, 'option' => $options, 'pattern' => $patterns]; // 设置路由标识 - $key = ltrim($key, '/'); self::name($route, [$name . ($key ? '/' . $key : ''), $vars, self::$domain]); } self::$rules['*'][$name] = ['rule' => $item, 'route' => '', 'var' => [], 'option' => $option, 'pattern' => $pattern]; -- Gitee From 4ca0e81d31a4cad93aab2898c835a82cda6f80a9 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 26 Oct 2016 20:05:04 +0800 Subject: [PATCH 0103/1170] =?UTF-8?q?File=E7=B1=BB=20=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E6=80=A7=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/File.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/File.php b/library/think/File.php index 43f38575..60a16417 100644 --- a/library/think/File.php +++ b/library/think/File.php @@ -39,7 +39,7 @@ class File extends SplFileObject public function __construct($filename, $mode = 'r') { parent::__construct($filename, $mode); - $this->filename = $this->getRealPath(); + $this->filename = $this->getRealPath() ?: $this->getPathname(); } /** -- Gitee From 741ef90a3d6a769a283c173c150dac16508d5877 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 27 Oct 2016 10:38:43 +0800 Subject: [PATCH 0104/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BUrl=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Url.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/think/Url.php b/library/think/Url.php index b4ae0aac..cc68e720 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -174,10 +174,10 @@ class Url $url = substr($url, 1); } else { // 解析到 模块/控制器/操作 - $module = $request->module(); + $module = $request->module(); + $domains = Route::rules('domain'); if (true === $domain && 2 == substr_count($url, '/')) { $current = $request->host(); - $domains = Route::rules('domain'); $match = []; $pos = []; foreach ($domains as $key => $item) { -- Gitee From b2e2d440ed306f24f355d8237b96131e7fcd987c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 27 Oct 2016 10:42:50 +0800 Subject: [PATCH 0105/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Url=E5=A4=9A?= =?UTF-8?q?=E6=AC=A1=E7=94=9F=E6=88=90=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Url.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/think/Url.php b/library/think/Url.php index cc68e720..642e48f1 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -155,7 +155,8 @@ class Url // 检测域名 $domain = self::parseDomain($url, $domain); // URL组装 - $url = $domain . (self::$root ?: Request::instance()->root()) . '/' . ltrim($url, '/'); + $url = $domain . (self::$root ?: Request::instance()->root()) . '/' . ltrim($url, '/'); + self::$bindCheck = false; return $url; } -- Gitee From 40dd37e37417029166c3be71b2838d8a9171deb1 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 27 Oct 2016 14:10:25 +0800 Subject: [PATCH 0106/1170] =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=8F=B7=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E4=B8=BA5.0.3beta?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base.php b/base.php index b668120e..4d0b703c 100644 --- a/base.php +++ b/base.php @@ -9,7 +9,7 @@ // | Author: liu21st // +---------------------------------------------------------------------- -define('THINK_VERSION', '5.0.2'); +define('THINK_VERSION', '5.0.3beta'); define('THINK_START_TIME', microtime(true)); define('THINK_START_MEM', memory_get_usage()); define('EXT', '.php'); -- Gitee From eed8bfb12dc9ab1163c2708faa972d64807a83ad Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 27 Oct 2016 14:18:44 +0800 Subject: [PATCH 0107/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BConfig=E7=B1=BBload?= =?UTF-8?q?=E6=96=B9=E6=B3=95=20=E4=B8=80=E7=BA=A7=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E5=BC=BA=E5=88=B6=E8=BD=AC=E4=B8=BA=E5=B0=8F?= =?UTF-8?q?=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Config.php | 1 + 1 file changed, 1 insertion(+) diff --git a/library/think/Config.php b/library/think/Config.php index d7c3dc56..fb5340d8 100644 --- a/library/think/Config.php +++ b/library/think/Config.php @@ -59,6 +59,7 @@ class Config self::$config[$range] = []; } if (is_file($file)) { + $name = strtolower($name); $type = pathinfo($file, PATHINFO_EXTENSION); if ('php' == $type) { return self::set(include $file, $name, $range); -- Gitee From 756992ef2ee6faa740debb985069186c3c52bce0 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 27 Oct 2016 14:39:26 +0800 Subject: [PATCH 0108/1170] =?UTF-8?q?cache=E5=8A=A9=E6=89=8B=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E6=94=AF=E6=8C=81=E6=B8=85=E7=A9=BA=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=20cache(null)=20=E6=88=96=E8=80=85=20cache(null,'tagName');?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/helper.php b/helper.php index e0cc719e..ba9f46ad 100644 --- a/helper.php +++ b/helper.php @@ -359,7 +359,9 @@ if (!function_exists('cache')) { // 缓存初始化 return Cache::connect($name); } - if ('' === $value) { + if (is_null($name)) { + return Cache::clear($value); + } elseif ('' === $value) { // 获取缓存 return 0 === strpos($name, '?') ? Cache::has(substr($name, 1)) : Cache::get($name); } elseif (is_null($value)) { -- Gitee From 796921a4b06b921e3564cbfc422f10437f361d1c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 28 Oct 2016 10:46:44 +0800 Subject: [PATCH 0109/1170] =?UTF-8?q?Route=E7=B1=BB=E5=A2=9E=E5=8A=A0setOp?= =?UTF-8?q?tion=E5=92=8CgetOption=E6=96=B9=E6=B3=95=20=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=BD=93=E5=89=8D=E8=B7=AF=E7=94=B1=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E8=BF=87=E7=A8=8B=E4=B8=AD=E7=9A=84=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/library/think/Route.php b/library/think/Route.php index 83442cba..b22f91ef 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -69,6 +69,8 @@ class Route private static $domainRule; // 当前域名 private static $domain; + // 当前路由执行过程中的参数 + private static $option = []; /** * 注册变量规则 @@ -341,6 +343,27 @@ class Route } } + /** + * 设置当前执行的参数信息 + * @access public + * @param array $options 参数信息 + * @return mixed + */ + protected static function setOption($options = []) + { + self::$option[] = $options; + } + + /** + * 获取当前执行的所有参数信息 + * @access public + * @return array + */ + public static function getOption() + { + return self::$option; + } + /** * 获取当前的分组信息 * @access public @@ -898,7 +921,7 @@ class Route if (is_string($str) && $str && 0 !== strpos(str_replace('|', '/', $url), $str)) { continue; } - + self::setOption($option); $result = self::checkRoute($request, $rule, $url, $depr, $key, $option); if (false !== $result) { return $result; @@ -913,6 +936,8 @@ class Route if ($group) { $rule = $group . ($rule ? '/' . ltrim($rule, '/') : ''); } + + self::setOption($option); if (isset($options['bind_model']) && isset($option['bind_model'])) { $option['bind_model'] = array_merge($options['bind_model'], $option['bind_model']); } -- Gitee From e2de014dd1a2bbc581619900d091e2c4230ac65a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 28 Oct 2016 11:19:44 +0800 Subject: [PATCH 0110/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 1 + 1 file changed, 1 insertion(+) diff --git a/library/think/Route.php b/library/think/Route.php index b22f91ef..395b07cc 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -858,6 +858,7 @@ class Route $rule = self::getRouteExpress($item); } if (!empty($rule['route']) && self::checkOption($rule['option'], $request)) { + self::setOption($rule['option']); return self::parseRule($item, $rule['route'], $url, $rule['option']); } } -- Gitee From dba952b608768c42682502546820bfaeb57f0505 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 28 Oct 2016 14:58:25 +0800 Subject: [PATCH 0111/1170] =?UTF-8?q?=E8=B7=AF=E7=94=B1=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=A7=92=E8=89=B2=E5=8F=82=E6=95=B0=20=E5=A2=9E=E5=8A=A0getRol?= =?UTF-8?q?e=E6=96=B9=E6=B3=95=E8=8E=B7=E5=8F=96=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E7=9A=84=E8=A7=92=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index 395b07cc..c6e52267 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -234,9 +234,10 @@ class Route * @param string $type 请求类型 * @param array $option 路由参数 * @param array $pattern 变量规则 + * @param mixed $role 角色信息 * @return void */ - public static function rule($rule, $route = '', $type = '*', $option = [], $pattern = []) + public static function rule($rule, $route = '', $type = '*', $option = [], $pattern = [], $role = null) { $group = self::getGroup('name'); if (!is_null($group)) { @@ -260,12 +261,16 @@ class Route $route = $val[0]; $option1 = array_merge($option, $val[1]); $pattern1 = array_merge($pattern, isset($val[2]) ? $val[2] : []); + if (isset($val[3])) { + self::setRole($key, $val[3]); + } } else { $route = $val; } self::setRule($key, $route, $type, isset($option1) ? $option1 : $option, isset($pattern1) ? $pattern1 : $pattern, $group); } } else { + self::setRole($rule, $role); self::setRule($rule, $route, $type, $option, $pattern, $group); } @@ -346,12 +351,15 @@ class Route /** * 设置当前执行的参数信息 * @access public - * @param array $options 参数信息 + * @param string $name 分组名或者路由规则 + * @param mixed $role 角色信息 * @return mixed */ - protected static function setOption($options = []) + protected static function setRole($name, $role) { - self::$option[] = $options; + if ($role) { + self::$role[$name] = $role; + } } /** @@ -359,9 +367,9 @@ class Route * @access public * @return array */ - public static function getOption() + public static function getRole() { - return self::$option; + return self::$role; } /** @@ -401,9 +409,10 @@ class Route * @param array|\Closure $routes 路由地址 * @param array $option 路由参数 * @param array $pattern 变量规则 + * @param mixed $role 角色信息 * @return void */ - public static function group($name, $routes, $option = [], $pattern = []) + public static function group($name, $routes, $option = [], $pattern = [], $role = null) { if (is_array($name)) { $option = $name; @@ -427,6 +436,7 @@ class Route self::$rules['*'][$name]['option'] = $option; self::$rules['*'][$name]['pattern'] = $pattern; } + self::setRole($name, $role); } else { $item = []; foreach ($routes as $key => $val) { @@ -437,6 +447,9 @@ class Route $route = $val[0]; $option1 = array_merge($option, isset($val[1]) ? $val[1] : []); $pattern1 = array_merge($pattern, isset($val[2]) ? $val[2] : []); + if (isset($val[3])) { + self::setRole($name, $val[3]); + } } else { $route = $val; } @@ -474,7 +487,7 @@ class Route self::setGroup($currentGroup, $currentOption, $currentPattern); } else { // 批量注册路由 - self::rule($routes, '', '*', $option, $pattern); + self::rule($routes, '', '*', $option, $pattern, $role); } } @@ -858,7 +871,6 @@ class Route $rule = self::getRouteExpress($item); } if (!empty($rule['route']) && self::checkOption($rule['option'], $request)) { - self::setOption($rule['option']); return self::parseRule($item, $rule['route'], $url, $rule['option']); } } @@ -922,7 +934,7 @@ class Route if (is_string($str) && $str && 0 !== strpos(str_replace('|', '/', $url), $str)) { continue; } - self::setOption($option); + $result = self::checkRoute($request, $rule, $url, $depr, $key, $option); if (false !== $result) { return $result; @@ -938,7 +950,6 @@ class Route $rule = $group . ($rule ? '/' . ltrim($rule, '/') : ''); } - self::setOption($option); if (isset($options['bind_model']) && isset($option['bind_model'])) { $option['bind_model'] = array_merge($options['bind_model'], $option['bind_model']); } -- Gitee From d392d310e354337bc2c32315242071494cbf8fd1 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 28 Oct 2016 15:07:45 +0800 Subject: [PATCH 0112/1170] =?UTF-8?q?=E7=89=88=E6=9C=AC=E8=BF=98=E5=8E=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index c6e52267..395b07cc 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -234,10 +234,9 @@ class Route * @param string $type 请求类型 * @param array $option 路由参数 * @param array $pattern 变量规则 - * @param mixed $role 角色信息 * @return void */ - public static function rule($rule, $route = '', $type = '*', $option = [], $pattern = [], $role = null) + public static function rule($rule, $route = '', $type = '*', $option = [], $pattern = []) { $group = self::getGroup('name'); if (!is_null($group)) { @@ -261,16 +260,12 @@ class Route $route = $val[0]; $option1 = array_merge($option, $val[1]); $pattern1 = array_merge($pattern, isset($val[2]) ? $val[2] : []); - if (isset($val[3])) { - self::setRole($key, $val[3]); - } } else { $route = $val; } self::setRule($key, $route, $type, isset($option1) ? $option1 : $option, isset($pattern1) ? $pattern1 : $pattern, $group); } } else { - self::setRole($rule, $role); self::setRule($rule, $route, $type, $option, $pattern, $group); } @@ -351,15 +346,12 @@ class Route /** * 设置当前执行的参数信息 * @access public - * @param string $name 分组名或者路由规则 - * @param mixed $role 角色信息 + * @param array $options 参数信息 * @return mixed */ - protected static function setRole($name, $role) + protected static function setOption($options = []) { - if ($role) { - self::$role[$name] = $role; - } + self::$option[] = $options; } /** @@ -367,9 +359,9 @@ class Route * @access public * @return array */ - public static function getRole() + public static function getOption() { - return self::$role; + return self::$option; } /** @@ -409,10 +401,9 @@ class Route * @param array|\Closure $routes 路由地址 * @param array $option 路由参数 * @param array $pattern 变量规则 - * @param mixed $role 角色信息 * @return void */ - public static function group($name, $routes, $option = [], $pattern = [], $role = null) + public static function group($name, $routes, $option = [], $pattern = []) { if (is_array($name)) { $option = $name; @@ -436,7 +427,6 @@ class Route self::$rules['*'][$name]['option'] = $option; self::$rules['*'][$name]['pattern'] = $pattern; } - self::setRole($name, $role); } else { $item = []; foreach ($routes as $key => $val) { @@ -447,9 +437,6 @@ class Route $route = $val[0]; $option1 = array_merge($option, isset($val[1]) ? $val[1] : []); $pattern1 = array_merge($pattern, isset($val[2]) ? $val[2] : []); - if (isset($val[3])) { - self::setRole($name, $val[3]); - } } else { $route = $val; } @@ -487,7 +474,7 @@ class Route self::setGroup($currentGroup, $currentOption, $currentPattern); } else { // 批量注册路由 - self::rule($routes, '', '*', $option, $pattern, $role); + self::rule($routes, '', '*', $option, $pattern); } } @@ -871,6 +858,7 @@ class Route $rule = self::getRouteExpress($item); } if (!empty($rule['route']) && self::checkOption($rule['option'], $request)) { + self::setOption($rule['option']); return self::parseRule($item, $rule['route'], $url, $rule['option']); } } @@ -934,7 +922,7 @@ class Route if (is_string($str) && $str && 0 !== strpos(str_replace('|', '/', $url), $str)) { continue; } - + self::setOption($option); $result = self::checkRoute($request, $rule, $url, $depr, $key, $option); if (false !== $result) { return $result; @@ -950,6 +938,7 @@ class Route $rule = $group . ($rule ? '/' . ltrim($rule, '/') : ''); } + self::setOption($option); if (isset($options['bind_model']) && isset($option['bind_model'])) { $option['bind_model'] = array_merge($options['bind_model'], $option['bind_model']); } -- Gitee From 05e341a80d300dc809d009393d975bca41e48c10 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 29 Oct 2016 09:24:34 +0800 Subject: [PATCH 0113/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BB?= =?UTF-8?q?=E7=9A=84join=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 0c9d8ef7..0cc522d5 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -677,7 +677,10 @@ class Query $this->alias($table); } elseif (strpos($join, ' ') && !strpos($join, ')')) { list($table, $alias) = explode(' ', $join); - $table = [$table => $alias]; + if (false === strpos($table, '.') && 0 !== strpos($table, $prefix) && 0 !== strpos($join, '__')) { + $table = $this->getTable($table); + } + $table = [$table => $alias]; $this->alias($table); } else { $table = $join; -- Gitee From a4ec5cafa00d318002e95d70ba9a957156ae5510 Mon Sep 17 00:00:00 2001 From: HyperQing <469379004@qq.com> Date: Sat, 29 Oct 2016 09:26:02 +0800 Subject: [PATCH 0114/1170] =?UTF-8?q?Db=E7=B1=BB=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Db.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/think/Db.php b/library/think/Db.php index b00aee61..c67cba6f 100644 --- a/library/think/Db.php +++ b/library/think/Db.php @@ -42,6 +42,9 @@ use think\paginator\Collection as PaginatorCollection; * @method integer execute(string $sql, array $bind = [], boolean $fetch = false, boolean $getLastInsID = false, string $sequence = null) static SQL执行 * @method PaginatorCollection paginate(integer $listRows = 15, mixed $simple = false, array $config = []) static 分页查询 * @method mixed transaction(callable $callback) static 执行数据库事务 + * @method void startTrans() static 启动事务 + * @method void commit() static 用于非自动提交状态下面的查询提交 + * @method void rollback() static 事务回滚 * @method boolean batchQuery(array $sqlArray) static 批处理执行SQL语句 */ class Db -- Gitee From 223a48b6b898e3469ed16deff73d36cb3c46c121 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 30 Oct 2016 10:11:12 +0800 Subject: [PATCH 0115/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BBjoin?= =?UTF-8?q?=E5=92=8Cview=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 74 ++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 0cc522d5..785571db 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -659,36 +659,51 @@ class Query } } } else { - // 传入的表名为数组 - if (is_array($join)) { - if (0 !== $key = key($join)) { - // 设置了键名则键名为表名,键值作为表的别名 - $table = [$key => array_shift($join)]; - $this->alias($table); - } else { - $table = array_shift($join); - } + $table = $this->getJoinTable($join); + + $this->options['join'][] = [$table, strtoupper($type), $condition]; + } + return $this; + } + + /** + * 获取Join表名及别名 支持 + * ['prefix_table或者子查询'=>'alias'] 'prefix_table alias' 'table alias' + * @access public + * @param array|string $join + * @return array|string + */ + protected function getJoinTable($join, &$alias = null) + { + // 传入的表名为数组 + if (is_array($join)) { + list($table, $alias) = each($join); + } else { + $join = trim($join); + if (false !== strpos($join, '(')) { + // 使用子查询 + $table = $join; } else { $prefix = $this->prefix; - $join = trim($join); - if ($prefix && false === strpos($join, ' ') && false === strpos($join, '(') && false === strpos($join, '.') && 0 !== strpos($join, $prefix) && 0 !== strpos($join, '__')) { - $table = $this->getTable($join); - $table = [$table => $join]; - $this->alias($table); - } elseif (strpos($join, ' ') && !strpos($join, ')')) { + if (strpos($join, ' ')) { + // 使用别名 list($table, $alias) = explode(' ', $join); - if (false === strpos($table, '.') && 0 !== strpos($table, $prefix) && 0 !== strpos($join, '__')) { - $table = $this->getTable($table); - } - $table = [$table => $alias]; - $this->alias($table); } else { $table = $join; + if (false === strpos($join, '.') && 0 !== strpos($join, '__')) { + $alias = $join; + } + } + if (false === strpos($table, '.') && 0 !== strpos($table, $prefix) && 0 !== strpos($table, '__')) { + $table = $this->getTable($table); } } - $this->options['join'][] = [$table, strtoupper($type), $condition]; } - return $this; + if (isset($alias)) { + $table = [$table => $alias]; + $this->alias($table); + } + return $table; } /** @@ -773,19 +788,8 @@ class Query } } else { $fields = []; - $prefix = $this->prefix; - if (is_array($join)) { - // 支持数据表别名 - list($table, $alias) = each($join); - } elseif ($prefix && false === strpos($join, ' ') && 0 !== strpos($join, $prefix) && 0 !== strpos($join, '__')) { - $table = $this->getTable($join); - $alias = $join; - } elseif (strpos($join, ' ')) { - list($table, $alias) = explode(' ', $join); - } else { - $alias = $join; - } - $table = isset($table) ? [$table => $alias] : $alias; + $table = $this->getJoinTable($join, $alias); + if (true === $field) { $fields = $alias . '.*'; } else { -- Gitee From 650eff72323cfaddb0bac3c60852b320faa6f690 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 30 Oct 2016 22:08:32 +0800 Subject: [PATCH 0116/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3input=E5=8A=A9?= =?UTF-8?q?=E6=89=8B=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/helper.php b/helper.php index ba9f46ad..451d3344 100644 --- a/helper.php +++ b/helper.php @@ -125,10 +125,9 @@ if (!function_exists('input')) { } if ($pos = strpos($key, '.')) { // 指定参数来源 - $method = substr($key, 0, $pos); - if (in_array($method, ['get', 'post', 'put', 'patch', 'delete', 'param', 'request', 'session', 'cookie', 'server', 'env', 'path', 'file'])) { - $key = substr($key, $pos + 1); - } else { + list($method, $key) = explode('.', $key); + if (!in_array($method, ['get', 'post', 'put', 'patch', 'delete', 'param', 'request', 'session', 'cookie', 'server', 'env', 'path', 'file'])) { + $key = $method . '.' . $key; $method = 'param'; } } else { -- Gitee From f11c53db7c511888f6098e995b23a741be71222d Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 31 Oct 2016 08:13:15 +0800 Subject: [PATCH 0117/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E5=99=A8=E8=87=AA=E5=8A=A8=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/think/Route.php b/library/think/Route.php index 395b07cc..ccadee80 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1212,7 +1212,9 @@ class Route $find = false; foreach ($path as $val) { $item[] = $val; - if (is_file($dir . DS . str_replace('.', DS, $val) . $suffix . EXT)) { + $file = $dir . DS . str_replace('.', DS, $val) . $suffix . EXT; + $file = pathinfo($file, PATHINFO_DIRNAME) . DS . Loader::parseName(pathinfo($file, PATHINFO_FILENAME), 1) . EXT; + if (is_file($file)) { $find = true; break; } else { -- Gitee From e8b05a76422612cf0b52dfa66beffa799813fb06 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 31 Oct 2016 16:25:30 +0800 Subject: [PATCH 0118/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BRoute=E7=B1=BB?= =?UTF-8?q?=E7=9A=84parseRule=E6=96=B9=E6=B3=95=20=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E4=B8=AD=E7=9A=84=E5=8F=98=E9=87=8F=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E4=B8=8D=E8=87=AA=E5=8A=A8=E5=8E=BB=E9=99=A4=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 1 - 1 file changed, 1 deletion(-) diff --git a/library/think/Route.php b/library/think/Route.php index ccadee80..7c6d18ce 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1400,7 +1400,6 @@ class Route foreach ($matches as $key => $val) { if (false !== strpos($route, ':' . $key)) { $route = str_replace(':' . $key, $val, $route); - unset($matches[$key]); } } } -- Gitee From 594d263ea222ebafcb62ed533494c4e23ca9d53f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 31 Oct 2016 18:07:06 +0800 Subject: [PATCH 0119/1170] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/think/Request.php b/library/think/Request.php index c6f1198a..634746c9 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -1471,11 +1471,11 @@ class Request } /** - * 读取或者设置缓存 + * 设置当前地址的请求缓存 * @access public * @param string $key 缓存标识,支持变量规则 ,例如 item/:name/:id * @param mixed $expire 缓存有效期 - * @return mixed + * @return void */ public function cache($key, $expire = null) { @@ -1514,7 +1514,7 @@ class Request } /** - * 读取缓存设置 + * 读取请求缓存设置 * @access public * @return array */ -- Gitee From fd670ce955f22cdf068f95d389f1de34c56f43dd Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 1 Nov 2016 10:53:41 +0800 Subject: [PATCH 0120/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=E5=88=B0=E5=91=BD=E5=90=8D=E7=A9=BA=E9=97=B4?= =?UTF-8?q?=E5=90=8E=E7=9A=84=E7=B1=BB=E8=87=AA=E5=8A=A8=E5=AE=9A=E4=BD=8D?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Route.php b/library/think/Route.php index 7c6d18ce..fb9eeff2 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1064,7 +1064,7 @@ class Route { $url = str_replace($depr, '|', $url); $array = explode('|', $url, 3); - $class = !empty($array[0]) ? $array[0] : Config::get('default_controller'); + $class = Loader::parseName(!empty($array[0]) ? $array[0] : Config::get('default_controller'), 1); $method = !empty($array[1]) ? $array[1] : Config::get('default_action'); if (!empty($array[2])) { self::parseUrlParams($array[2]); -- Gitee From 64317fcec46b7ce271a5aa2a41b84d713e98e14a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 1 Nov 2016 11:00:46 +0800 Subject: [PATCH 0121/1170] =?UTF-8?q?readme=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ee0676a0..65db2b9e 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ThinkPHP 5.0 [![Latest Unstable Version](https://poser.pugx.org/topthink/framework/v/unstable)](https://packagist.org/packages/topthink/framework) [![License](https://poser.pugx.org/topthink/framework/license)](https://packagist.org/packages/topthink/framework) -ThinkPHP5在保持快速开发和大道至简的核心理念不变的同时,PHP版本要求提升到5.4,对已有的CBD模式做了更深的强化,优化核心,减少依赖,基于全新的架构思想和命名空间实现,是ThinkPHP突破原有框架思路的颠覆之作,其主要特性包括: +ThinkPHP5在保持快速开发和大道至简的核心理念不变的同时,PHP版本要求提升到5.4,优化核心,减少依赖,基于全新的架构思想和命名空间实现,是ThinkPHP突破原有框架思路的颠覆之作,其主要特性包括: + 基于命名空间和众多PHP新特性 + 核心功能组件化 -- Gitee From 17d146d0d9492203d6dfc91d74b53eb45882fc56 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 1 Nov 2016 11:41:27 +0800 Subject: [PATCH 0122/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=E5=88=B0=E5=91=BD=E5=90=8D=E7=A9=BA=E9=97=B4?= =?UTF-8?q?=E5=90=8E=20=E7=B1=BB=E7=9A=84=E8=87=AA=E5=8A=A8=E5=AE=9A?= =?UTF-8?q?=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index fb9eeff2..8e0a6cca 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1064,12 +1064,12 @@ class Route { $url = str_replace($depr, '|', $url); $array = explode('|', $url, 3); - $class = Loader::parseName(!empty($array[0]) ? $array[0] : Config::get('default_controller'), 1); + $class = !empty($array[0]) ? $array[0] : Config::get('default_controller'); $method = !empty($array[1]) ? $array[1] : Config::get('default_action'); if (!empty($array[2])) { self::parseUrlParams($array[2]); } - return ['type' => 'method', 'method' => [$namespace . '\\' . $class, $method]]; + return ['type' => 'method', 'method' => [$namespace . '\\' . Loader::parseName($class, 1), $method]]; } /** -- Gitee From 4a609c7254fa00431fc32fcf34693a36067e8319 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 1 Nov 2016 11:43:50 +0800 Subject: [PATCH 0123/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BFile=E7=B1=BBcheckI?= =?UTF-8?q?mg=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/File.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/think/File.php b/library/think/File.php index 60a16417..0d04bec1 100644 --- a/library/think/File.php +++ b/library/think/File.php @@ -230,10 +230,10 @@ class File extends SplFileObject { $extension = strtolower(pathinfo($this->getInfo('name'), PATHINFO_EXTENSION)); /* 对图像文件进行严格检测 */ - if (in_array($extension, ['gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf']) && !in_array($this->getImageType($this->filename), [1, 2, 3, 4, 6])) { - return false; + if (in_array($extension, ['gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf']) && in_array($this->getImageType($this->filename), [1, 2, 3, 4, 6])) { + return true; } - return true; + return false; } // 判断图像类型 -- Gitee From 98baf43cf85352561d0bccffc66a5716797ef9c1 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 1 Nov 2016 11:46:12 +0800 Subject: [PATCH 0124/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/thinkphp/library/think/routeTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/thinkphp/library/think/routeTest.php b/tests/thinkphp/library/think/routeTest.php index d6790347..a86c21e1 100644 --- a/tests/thinkphp/library/think/routeTest.php +++ b/tests/thinkphp/library/think/routeTest.php @@ -257,10 +257,10 @@ class routeTest extends \PHPUnit_Framework_TestCase $this->assertEquals(['index', 'blog', 'test'], $result['module']); Route::bind('\app\index\controller', 'namespace'); - $this->assertEquals(['type' => 'method', 'method' => ['\app\index\controller\blog', 'read']], Route::check($request, 'blog/read')); + $this->assertEquals(['type' => 'method', 'method' => ['\app\index\controller\Blog', 'read']], Route::check($request, 'blog/read')); - Route::bind('\app\index\controller\blog', 'class'); - $this->assertEquals(['type' => 'method', 'method' => ['\app\index\controller\blog', 'read']], Route::check($request, 'read')); + Route::bind('\app\index\controller\Blog', 'class'); + $this->assertEquals(['type' => 'method', 'method' => ['\app\index\controller\Blog', 'read']], Route::check($request, 'read')); } public function testDomain() -- Gitee From 7a0d53d071d3454058a1f5c7cd06ea071971b9d6 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 1 Nov 2016 12:00:50 +0800 Subject: [PATCH 0125/1170] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/think/Route.php b/library/think/Route.php index 8e0a6cca..6e5bd27d 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -129,7 +129,7 @@ class Route * 设置路由绑定 * @access public * @param mixed $bind 绑定信息 - * @param string $type 绑定类型 默认为module 支持 namespace class + * @param string $type 绑定类型 默认为module 支持 namespace class controller * @return mixed */ public static function bind($bind, $type = 'module') @@ -1025,6 +1025,9 @@ class Route case 'class': // 绑定到类 return self::bindToClass($url, $bind, $depr); + case 'controller': + // 绑定到控制器类 + return self::bindToController($url, $bind, $depr); case 'namespace': // 绑定到命名空间 return self::bindToNamespace($url, $bind, $depr); -- Gitee From 57f206b75744464778dcc76de00756591b6dc3fb Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 1 Nov 2016 17:51:38 +0800 Subject: [PATCH 0126/1170] =?UTF-8?q?=E5=A2=9E=E5=BC=BA=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E5=8A=9F=E8=83=BD=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=85=A8=E5=B1=80=E9=85=8D=E7=BD=AE=20=E5=A2=9E=E5=8A=A0reques?= =?UTF-8?q?t=5Fcache=E9=85=8D=E7=BD=AE=E5=8F=82=E6=95=B0=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=89=B9=E6=AE=8A=E7=BC=93=E5=AD=98=E8=A7=84=E5=88=99?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=20=E5=A6=82=E6=9E=9C=E5=90=8C=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E8=AF=B7=E6=B1=82=E5=AD=98=E5=9C=A8=E5=A4=9A=E6=AC=A1?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E7=BC=93=E5=AD=98=E8=B0=83=E7=94=A8=20?= =?UTF-8?q?=E5=88=99=E7=AC=AC=E4=B8=80=E6=AC=A1=E6=9C=89=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convention.php | 2 ++ library/think/App.php | 2 ++ library/think/Request.php | 26 ++++++++++++++++++++++---- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/convention.php b/convention.php index 2ef29dcd..23408722 100644 --- a/convention.php +++ b/convention.php @@ -103,6 +103,8 @@ return [ 'var_ajax' => '_ajax', // 表单pjax伪装变量 'var_pjax' => '_pjax', + // 是否开启请求缓存 true自动缓存 支持设置请求缓存规则 + 'request_cache' => false, // +---------------------------------------------------------------------- // | 模板设置 diff --git a/library/think/App.php b/library/think/App.php index 7feff2fe..aed3327e 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -115,6 +115,8 @@ class App // 进行URL路由检测 $dispatch = self::routeCheck($request, $config); } + // 请求缓存检查 + $request->cache($config['request_cache']); // 记录当前调度信息 $request->dispatch($dispatch); diff --git a/library/think/Request.php b/library/think/Request.php index 634746c9..b55db39c 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -121,6 +121,8 @@ class Request protected $input; // 请求缓存 protected $cache; + // 缓存是否检查 + protected $isCheckCache; /** * 架构函数 @@ -1479,7 +1481,20 @@ class Request */ public function cache($key, $expire = null) { - if ($this->isGet()) { + if (false !== $key && $this->isGet() && !$this->isCheckCache) { + if ($key instanceof \Closure) { + $key = call_user_func_array($key, [$this]); + } elseif (true === $key) { + // 自动缓存功能 + $key = '__URL__'; + } elseif (strpos($key, '|')) { + list($key, $fun) = explode('|', $key); + } + // 特殊规则替换 + if (false !== strpos($key, '__')) { + $key = str_replace(['__MODULE__', '__CONTROLLER__', '__ACTION__', '__URL__'], [$this->module, $this->controller, $this->action, md5($this->url())], $key); + } + if (false !== strpos($key, ':')) { $param = $this->param(); foreach ($param as $item => $val) { @@ -1487,9 +1502,6 @@ class Request $key = str_replace(':' . $item, $val, $key); } } - } elseif ('__URL__' == $key) { - // 当前URL地址作为缓存标识 - $key = md5($this->url()); } elseif (strpos($key, ']')) { if ('[' . $this->ext() . ']' == $key) { // 缓存某个后缀的请求 @@ -1498,6 +1510,12 @@ class Request return; } } + if (isset($fun)) { + $key = $fun($key); + } + + // 标记请求缓存检查 + $this->isCheckCache = true; if (strtotime($this->server('HTTP_IF_MODIFIED_SINCE')) + $expire > $_SERVER['REQUEST_TIME']) { // 读取缓存 -- Gitee From bef0eebaedc791c566f09766c3f877e28fb3f732 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 1 Nov 2016 17:57:06 +0800 Subject: [PATCH 0127/1170] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E8=87=AA=E5=8A=A8=E6=A3=80=E6=9F=A5=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/think/App.php b/library/think/App.php index aed3327e..93d9ef6f 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -115,8 +115,6 @@ class App // 进行URL路由检测 $dispatch = self::routeCheck($request, $config); } - // 请求缓存检查 - $request->cache($config['request_cache']); // 记录当前调度信息 $request->dispatch($dispatch); @@ -129,6 +127,8 @@ class App // 监听app_begin Hook::listen('app_begin', $dispatch); + // 请求缓存检查 + $request->cache($config['request_cache']); switch ($dispatch['type']) { case 'redirect': -- Gitee From 12b9dad4956f69defff09b628cb2d6199f69b142 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 1 Nov 2016 18:06:58 +0800 Subject: [PATCH 0128/1170] =?UTF-8?q?=E5=A2=9E=E5=8A=A0request=5Fcache=5Fe?= =?UTF-8?q?xpire=E9=85=8D=E7=BD=AE=E5=8F=82=E6=95=B0=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=85=A8=E5=B1=80=E7=9A=84=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E6=9C=89=E6=95=88=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convention.php | 2 ++ library/think/App.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/convention.php b/convention.php index 23408722..8eb30f43 100644 --- a/convention.php +++ b/convention.php @@ -105,6 +105,8 @@ return [ 'var_pjax' => '_pjax', // 是否开启请求缓存 true自动缓存 支持设置请求缓存规则 'request_cache' => false, + // 请求缓存有效期 + 'request_cache_expire' => null, // +---------------------------------------------------------------------- // | 模板设置 diff --git a/library/think/App.php b/library/think/App.php index 93d9ef6f..4eddc7cd 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -128,7 +128,7 @@ class App // 监听app_begin Hook::listen('app_begin', $dispatch); // 请求缓存检查 - $request->cache($config['request_cache']); + $request->cache($config['request_cache'], $config['request_cache_expire']); switch ($dispatch['type']) { case 'redirect': -- Gitee From 1d30c47de3bd695a657c6439188c459815881b51 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 1 Nov 2016 18:17:37 +0800 Subject: [PATCH 0129/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BB?= =?UTF-8?q?=E7=9A=84alias=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 785571db..91af4997 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1189,6 +1189,9 @@ class Query } else { if (isset($this->options['table'])) { $table = is_array($this->options['table']) ? key($this->options['table']) : $this->options['table']; + if (false !== strpos($table, '__')) { + $table = $this->parseSqlTable($table); + } } else { $table = $this->getTable(); } -- Gitee From 3a1cf0bb9a5c7ffd6521a737d7e18195fa323b3f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 2 Nov 2016 10:32:26 +0800 Subject: [PATCH 0130/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Query=E7=B1=BBgetJo?= =?UTF-8?q?inTable=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 91af4997..b238610d 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -694,7 +694,7 @@ class Query $alias = $join; } } - if (false === strpos($table, '.') && 0 !== strpos($table, $prefix) && 0 !== strpos($table, '__')) { + if ($prefix && false === strpos($table, '.') && 0 !== strpos($table, $prefix) && 0 !== strpos($table, '__')) { $table = $this->getTable($table); } } -- Gitee From e3db097287c5e022b4c53982db154cb3166807cc Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 2 Nov 2016 16:53:00 +0800 Subject: [PATCH 0131/1170] =?UTF-8?q?=E8=B7=AF=E7=94=B1=E7=9A=84ajax=20pja?= =?UTF-8?q?x=20https=20=E6=A3=80=E6=B5=8B=E5=8F=82=E6=95=B0=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20=E9=9D=9E=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index 6e5bd27d..63cbe9c4 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1122,14 +1122,16 @@ class Route */ private static function checkOption($option, $request) { - // 请求类型检测 if ((isset($option['method']) && is_string($option['method']) && false === stripos($option['method'], $request->method())) - || (!empty($option['ajax']) && !$request->isAjax()) // Ajax检测 - || (!empty($option['pjax']) && !$request->isPjax()) // Pjax检测 + || (isset($option['ajax']) && $option['ajax'] && !$request->isAjax()) // Ajax检测 + || (isset($option['ajax']) && !$option['ajax'] && $request->isAjax()) // 非Ajax检测 + || (isset($option['pjax']) && $option['pjax'] && !$request->isPjax()) // Pjax检测 + || (isset($option['pjax']) && !$option['pjax'] && $request->isPjax()) // 非Pjax检测 || (isset($option['ext']) && false === stripos($option['ext'], $request->ext())) // 伪静态后缀检测 || (isset($option['deny_ext']) && false !== stripos($option['deny_ext'], $request->ext())) || (isset($option['domain']) && !in_array($option['domain'], [$_SERVER['HTTP_HOST'], self::$subDomain])) // 域名检测 - || (!empty($option['https']) && !$request->isSsl()) // https检测 + || (isset($option['https']) && $option['https'] && !$request->isSsl()) // https检测 + || (isset($option['https']) && !$option['https'] && $request->isSsl()) // https检测 || (!empty($option['before_behavior']) && false === Hook::exec($option['before_behavior'])) // 行为检测 || (!empty($option['callback']) && is_callable($option['callback']) && false === call_user_func($option['callback'])) // 自定义检测 ) { -- Gitee From 82a8c2170a3800e84ae2e207c09b9a1d1a849efd Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 2 Nov 2016 19:09:48 +0800 Subject: [PATCH 0132/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Model=E7=B1=BB?= =?UTF-8?q?=E7=9A=84saveall=E6=96=B9=E6=B3=95=E7=9A=84=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 561792aa..4354a077 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -741,7 +741,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess // 数据批量验证 $validate = $this->validate; foreach ($dataSet as $data) { - if (!$this->validate($validate)->validateData($data)) { + if (!$this->validateData($data, $validate)) { return false; } } @@ -885,12 +885,13 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * 自动验证数据 * @access protected * @param array $data 验证数据 + * @param mixed $rule 验证规则 * @return bool */ - protected function validateData($data) + protected function validateData($data, $rule = null) { - if (!empty($this->validate)) { - $info = $this->validate; + $info = is_null($rule) ? $this->validate : $rule; + if (!empty($info)) { if (is_array($info)) { $validate = Loader::validate(); $validate->rule($info['rule']); -- Gitee From f0eafc1ea8c6a25097a2749a681d233d0ddae8e3 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 2 Nov 2016 19:24:15 +0800 Subject: [PATCH 0133/1170] =?UTF-8?q?Model=E7=B1=BB=E7=9A=84validate?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E6=94=AF=E6=8C=81=E7=AC=AC=E4=B8=89=E4=B8=AA?= =?UTF-8?q?=E5=8F=82=E6=95=B0=20=E4=BD=BF=E7=94=A8=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 4354a077..9dedf482 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -101,6 +101,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess protected $failException = false; // 全局查询范围 protected $useGlobalScope = true; + protected $batchValidate = false; /** * 初始化过的模型. @@ -854,9 +855,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @access public * @param array|string|bool $rule 验证规则 true表示自动读取验证器类 * @param array $msg 提示信息 + * @param bool $batch 批量验证 * @return $this */ - public function validate($rule = true, $msg = []) + public function validate($rule = true, $msg = [], $batch = false) { if (is_array($rule)) { $this->validate = [ @@ -866,6 +868,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess } else { $this->validate = true === $rule ? $this->name : $rule; } + $this->batchValidate = $batch; return $this; } @@ -891,6 +894,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess protected function validateData($data, $rule = null) { $info = is_null($rule) ? $this->validate : $rule; + if (!empty($info)) { if (is_array($info)) { $validate = Loader::validate(); @@ -906,7 +910,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $validate->scene($scene); } } - if (!$validate->check($data)) { + $batch = $this->batchValidate; + + if (!$validate->batch($batch)->check($data)) { $this->error = $validate->getError(); if ($this->failException) { throw new ValidateException($this->error); -- Gitee From dafca59498baeedc98021e5a67355937d0ff88a2 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 2 Nov 2016 19:30:36 +0800 Subject: [PATCH 0134/1170] =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/think/Model.php b/library/think/Model.php index 9dedf482..ff6c1142 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -101,7 +101,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess protected $failException = false; // 全局查询范围 protected $useGlobalScope = true; - protected $batchValidate = false; + // 是否采用批量验证 + protected $batchValidate = false; /** * 初始化过的模型. -- Gitee From 1a23e337e803ec8595864d722b68e21f8ac6dcdf Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 4 Nov 2016 16:04:38 +0800 Subject: [PATCH 0135/1170] =?UTF-8?q?=E5=9B=A0=E4=B8=BA=E5=8E=9F=E6=9D=A5?= =?UTF-8?q?=E7=94=A8=E6=B3=95=E4=BC=9A=E5=AF=BC=E8=87=B4=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E8=AF=BB=E5=8F=96=E9=A1=BA=E5=BA=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8C=E8=B7=AF=E7=94=B1=E5=8F=AF=E9=80=89=E5=88=86?= =?UTF-8?q?=E9=9A=94=E7=AC=A6=E7=9A=84=E7=94=A8=E6=B3=95=20=E5=8E=9F?= =?UTF-8?q?=E6=9D=A5=E7=9A=84=20hello/(-=3F)=20=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=EF=BC=9A=20hello/-=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Url.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Url.php b/library/think/Url.php index 642e48f1..d8730743 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -81,7 +81,7 @@ class Url // 匹配路由命名标识 $url = $match[0]; // 替换可选分隔符 - $url = preg_replace(['/\((\W)\?\)$/', '/\((\W)\?\)/'], ['', '\1'], $url); + $url = preg_replace(['/(\W)\?$/', '/(\W)\?/'], ['', '\1'], $url); if (!empty($match[1])) { $domain = $match[1]; } -- Gitee From 909f494af73287ce8658c0a4c6b10e897fbc13bf Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 4 Nov 2016 19:26:01 +0800 Subject: [PATCH 0136/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3File=E7=B1=BBcheckI?= =?UTF-8?q?mg=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/File.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/think/File.php b/library/think/File.php index 0d04bec1..60a16417 100644 --- a/library/think/File.php +++ b/library/think/File.php @@ -230,10 +230,10 @@ class File extends SplFileObject { $extension = strtolower(pathinfo($this->getInfo('name'), PATHINFO_EXTENSION)); /* 对图像文件进行严格检测 */ - if (in_array($extension, ['gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf']) && in_array($this->getImageType($this->filename), [1, 2, 3, 4, 6])) { - return true; + if (in_array($extension, ['gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf']) && !in_array($this->getImageType($this->filename), [1, 2, 3, 4, 6])) { + return false; } - return false; + return true; } // 判断图像类型 -- Gitee From 46b8b5e8e768024a75fabb78c05617fdc89168aa Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 7 Nov 2016 11:14:02 +0800 Subject: [PATCH 0137/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BB?= =?UTF-8?q?=E7=9A=84min=E5=92=8Cmax=E6=96=B9=E6=B3=95=20=E5=AF=B9=20?= =?UTF-8?q?=E6=97=A5=E6=9C=9F=E7=B1=BB=E5=9E=8B=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index b238610d..4636377b 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -507,22 +507,24 @@ class Query * MIN查询 * @access public * @param string $field 字段名 - * @return float|int + * @return mixed */ public function min($field = '*') { - return $this->value('MIN(' . $field . ') AS tp_min', 0) + 0; + $value = $this->value('MIN(' . $field . ') AS tp_min', 0); + return is_numeric($value) ? $value + 0 : $value; } /** * MAX查询 * @access public * @param string $field 字段名 - * @return float|int + * @return mixed */ public function max($field = '*') { - return $this->value('MAX(' . $field . ') AS tp_max', 0) + 0; + $value = $this->value('MAX(' . $field . ') AS tp_max', 0); + return is_numeric($value) ? $value + 0 : $value; } /** -- Gitee From cb9fb04cad7ce6d60ad8c895db87f4591574badc Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 7 Nov 2016 14:36:30 +0800 Subject: [PATCH 0138/1170] =?UTF-8?q?Model=E7=B1=BB=E7=9A=84validateData?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=A2=9E=E5=8A=A0batch=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index ff6c1142..8073ca06 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -890,9 +890,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @access protected * @param array $data 验证数据 * @param mixed $rule 验证规则 + * @param bool $batch 批量验证 * @return bool */ - protected function validateData($data, $rule = null) + protected function validateData($data, $rule = null, $batch = null) { $info = is_null($rule) ? $this->validate : $rule; @@ -911,7 +912,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $validate->scene($scene); } } - $batch = $this->batchValidate; + $batch = is_null($batch) ? $this->batchValidate : $batch; if (!$validate->batch($batch)->check($data)) { $this->error = $validate->getError(); -- Gitee From 53329b79b6d46d43888221a3206dfd08c8fc6407 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 9 Nov 2016 12:17:42 +0800 Subject: [PATCH 0139/1170] =?UTF-8?q?Requesst=E7=B1=BB=E7=9A=84Input?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=92=8Cinput=E5=8A=A9=E6=89=8B=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E7=9A=84filter=E5=8F=82=E6=95=B0=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=BC=A0=E5=85=A5null=20=E8=A1=A8=E7=A4=BA=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E4=B8=8D=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper.php | 2 +- library/think/Request.php | 40 +++++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/helper.php b/helper.php index 451d3344..b81970c7 100644 --- a/helper.php +++ b/helper.php @@ -117,7 +117,7 @@ if (!function_exists('input')) { * @param string $filter 过滤方法 * @return mixed */ - function input($key = '', $default = null, $filter = null) + function input($key = '', $default = null, $filter = '') { if (0 === strpos($key, '?')) { $key = substr($key, 1); diff --git a/library/think/Request.php b/library/think/Request.php index b55db39c..8a354633 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -609,7 +609,7 @@ class Request * @param string|array $filter 过滤方法 * @return mixed */ - public function param($name = '', $default = null, $filter = null) + public function param($name = '', $default = null, $filter = '') { if (empty($this->param)) { $method = $this->method(true); @@ -646,7 +646,7 @@ class Request * @param string|array $filter 过滤方法 * @return mixed */ - public function route($name = '', $default = null, $filter = null) + public function route($name = '', $default = null, $filter = '') { if (is_array($name)) { $this->param = []; @@ -663,7 +663,7 @@ class Request * @param string|array $filter 过滤方法 * @return mixed */ - public function get($name = '', $default = null, $filter = null) + public function get($name = '', $default = null, $filter = '') { if (empty($this->get)) { $this->get = $_GET; @@ -683,7 +683,7 @@ class Request * @param string|array $filter 过滤方法 * @return mixed */ - public function post($name = '', $default = null, $filter = null) + public function post($name = '', $default = null, $filter = '') { if (empty($this->post)) { $this->post = $_POST; @@ -703,7 +703,7 @@ class Request * @param string|array $filter 过滤方法 * @return mixed */ - public function put($name = '', $default = null, $filter = null) + public function put($name = '', $default = null, $filter = '') { if (is_null($this->put)) { $content = $this->input; @@ -729,7 +729,7 @@ class Request * @param string|array $filter 过滤方法 * @return mixed */ - public function delete($name = '', $default = null, $filter = null) + public function delete($name = '', $default = null, $filter = '') { return $this->put($name, $default, $filter); } @@ -742,7 +742,7 @@ class Request * @param string|array $filter 过滤方法 * @return mixed */ - public function patch($name = '', $default = null, $filter = null) + public function patch($name = '', $default = null, $filter = '') { return $this->put($name, $default, $filter); } @@ -754,7 +754,7 @@ class Request * @param string|array $filter 过滤方法 * @return mixed */ - public function request($name = '', $default = null, $filter = null) + public function request($name = '', $default = null, $filter = '') { if (empty($this->request)) { $this->request = $_REQUEST; @@ -774,7 +774,7 @@ class Request * @param string|array $filter 过滤方法 * @return mixed */ - public function session($name = '', $default = null, $filter = null) + public function session($name = '', $default = null, $filter = '') { if (empty($this->session)) { $this->session = Session::get(); @@ -793,7 +793,7 @@ class Request * @param string|array $filter 过滤方法 * @return mixed */ - public function cookie($name = '', $default = null, $filter = null) + public function cookie($name = '', $default = null, $filter = '') { if (empty($this->cookie)) { $this->cookie = $_COOKIE; @@ -812,7 +812,7 @@ class Request * @param string|array $filter 过滤方法 * @return mixed */ - public function server($name = '', $default = null, $filter = null) + public function server($name = '', $default = null, $filter = '') { if (empty($this->server)) { $this->server = $_SERVER; @@ -890,7 +890,7 @@ class Request * @param string|array $filter 过滤方法 * @return mixed */ - public function env($name = '', $default = null, $filter = null) + public function env($name = '', $default = null, $filter = '') { if (empty($this->env)) { $this->env = $_ENV; @@ -949,7 +949,7 @@ class Request * @param string|array $filter 过滤函数 * @return mixed */ - public function input($data = [], $name = '', $default = null, $filter = null) + public function input($data = [], $name = '', $default = null, $filter = '') { if (false === $name) { // 获取原始数据 @@ -978,13 +978,17 @@ class Request } // 解析过滤器 - $filter = $filter ?: $this->filter; - - if (is_string($filter)) { - $filter = explode(',', $filter); + if (is_null($filter)) { + $filter = []; } else { - $filter = (array) $filter; + $filter = $filter ?: $this->filter; + if (is_string($filter)) { + $filter = explode(',', $filter); + } else { + $filter = (array) $filter; + } } + $filter[] = $default; if (is_array($data)) { array_walk_recursive($data, [$this, 'filterValue'], $filter); -- Gitee From 7eaf95de9b86965efa385669551712ffbce82522 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 9 Nov 2016 13:53:36 +0800 Subject: [PATCH 0140/1170] =?UTF-8?q?=E8=AF=B7=E6=B1=82=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E7=9A=84=E6=9C=89=E6=95=88=E6=9C=9F=E5=A6=82=E6=9E=9C=E4=BC=A0?= =?UTF-8?q?=E5=85=A5false=E8=A1=A8=E7=A4=BA=E4=B8=8D=E7=BC=93=E5=AD=98=20?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E8=A7=84=E5=88=99=E7=9A=84cache=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E4=BC=A0=E5=85=A5false=E4=B9=9F=E5=90=8C=E6=A0=B7?= =?UTF-8?q?=E8=A1=A8=E7=A4=BA=E4=B8=8D=E7=BC=93=E5=AD=98=20=E5=8D=B3?= =?UTF-8?q?=E4=BD=BF=E5=BC=80=E5=90=AF=E4=BA=86=E5=85=A8=E5=B1=80=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 9 ++++++--- library/think/Route.php | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/library/think/Request.php b/library/think/Request.php index 8a354633..45b65423 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -1486,6 +1486,12 @@ class Request public function cache($key, $expire = null) { if (false !== $key && $this->isGet() && !$this->isCheckCache) { + // 标记请求缓存检查 + $this->isCheckCache = true; + if (false === $expire) { + // 关闭当前缓存 + return; + } if ($key instanceof \Closure) { $key = call_user_func_array($key, [$this]); } elseif (true === $key) { @@ -1518,9 +1524,6 @@ class Request $key = $fun($key); } - // 标记请求缓存检查 - $this->isCheckCache = true; - if (strtotime($this->server('HTTP_IF_MODIFIED_SINCE')) + $expire > $_SERVER['REQUEST_TIME']) { // 读取缓存 $response = Response::create()->code(304); diff --git a/library/think/Route.php b/library/think/Route.php index 63cbe9c4..c8eb24e6 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1491,7 +1491,7 @@ class Route $result = self::parseModule($route); } // 开启请求缓存 - if ($request->isGet() && !empty($option['cache'])) { + if ($request->isGet() && isset($option['cache'])) { $cache = $option['cache']; if (is_array($cache)) { list($key, $expire) = $cache; -- Gitee From ec59e7f8afcebf29a3bf3488dfc97aedaa49e77d Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 9 Nov 2016 14:57:05 +0800 Subject: [PATCH 0141/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=BD=AF=E5=88=A0?= =?UTF-8?q?=E9=99=A4onlyTrashed=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/traits/model/SoftDelete.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/traits/model/SoftDelete.php b/library/traits/model/SoftDelete.php index e110ff25..9f7cedce 100644 --- a/library/traits/model/SoftDelete.php +++ b/library/traits/model/SoftDelete.php @@ -38,7 +38,7 @@ trait SoftDelete public static function onlyTrashed() { $model = new static(); - $field = $model->getDeleteTimeField(); + $field = $model->getDeleteTimeField(true); return $model->db(false)->where($field, 'exp', 'is not null'); } -- Gitee From 3935ed59157570965b5fe5e4308f52f9db0ca5b6 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 9 Nov 2016 16:01:59 +0800 Subject: [PATCH 0142/1170] =?UTF-8?q?=E5=85=B3=E8=81=94=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=9C=A8=E5=85=B3=E8=81=94=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=B8=AD=E4=BD=BF=E7=94=A8field=E8=8E=B7=E5=8F=96=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E6=9F=A5=E8=AF=A2=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 2 ++ library/think/model/Relation.php | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 4636377b..99ae42a4 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1615,6 +1615,8 @@ class Query $field = $this->options['with_field']; unset($this->options['with_field']); } + } elseif (isset($info['option']['field'])) { + $field = $info['option']['field']; } $this->field($field, false, $joinTable, $joinAlias, $relation . '__'); $i++; diff --git a/library/think/model/Relation.php b/library/think/model/Relation.php index 22670bdd..f9675c14 100644 --- a/library/think/model/Relation.php +++ b/library/think/model/Relation.php @@ -47,7 +47,8 @@ class Relation protected $query; // 关联查询条件 protected $where; - + // 关联查询参数 + protected $option; /** * 架构函数 * @access public @@ -74,6 +75,7 @@ class Relation 'localKey' => $this->localKey, 'alias' => $this->alias, 'joinType' => $this->joinType, + 'option' => $this->option, ]; return $name ? $info[$name] : $info; } @@ -689,8 +691,10 @@ class Relation } $result = call_user_func_array([$this->query, $method], $args); if ($result instanceof \think\db\Query) { + $this->option = $result->getOptions(); return $this; } else { + $this->option = []; return $result; } } else { -- Gitee From 9b2524d3a1d97b787bc589d5b7974920c9c4aca3 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 9 Nov 2016 16:25:06 +0800 Subject: [PATCH 0143/1170] =?UTF-8?q?=E8=81=9A=E5=90=88=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E6=94=AF=E6=8C=81=20field=E5=AE=9A=E4=B9=89=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E7=9A=84=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/Merge.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/library/think/model/Merge.php b/library/think/model/Merge.php index c28d0fd7..de8d9e1a 100644 --- a/library/think/model/Merge.php +++ b/library/think/model/Merge.php @@ -61,14 +61,14 @@ class Merge extends Model { $class = new static(); $master = $class->name; - $fields = self::getModelField($query, $master, '', $class->mapFields); + $fields = self::getModelField($query, $master, '', $class->mapFields, $class->field); $query->alias($master)->field($fields); foreach ($class->relationModel as $key => $model) { $name = is_int($key) ? $model : $key; $table = is_int($key) ? $query->getTable($name) : $model; $query->join($table . ' ' . $name, $name . '.' . $class->fk . '=' . $master . '.' . $class->getPk()); - $fields = self::getModelField($query, $name, $table, $class->mapFields); + $fields = self::getModelField($query, $name, $table, $class->mapFields, $class->field); $query->field($fields); } return $query; @@ -81,12 +81,13 @@ class Merge extends Model * @param string $name 模型名称 * @param string $table 关联表名称 * @param array $map 字段映射 + * @param array $fields 查询字段 * @return array */ - protected static function getModelField($query, $name, $table = '', $map = []) + protected static function getModelField($query, $name, $table = '', $map = [], $fields = []) { // 获取模型的字段信息 - $fields = $query->getTableInfo($table, 'fields'); + $fields = $fields ?: $query->getTableInfo($table, 'fields'); $array = []; foreach ($fields as $field) { if ($key = array_search($name . '.' . $field, $map)) { -- Gitee From 6f51dd0e47fe9cb8157b40aadeb4f9175bfacae3 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 10 Nov 2016 11:36:32 +0800 Subject: [PATCH 0144/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=BD=AF=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E7=9A=84withTrashed=E6=96=B9=E6=B3=95=20Query?= =?UTF-8?q?=E7=B1=BB=E5=A2=9E=E5=8A=A0removeWhereField=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 16 ++++++++++++++++ library/traits/model/SoftDelete.php | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 99ae42a4..3f4d5fd0 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -938,6 +938,22 @@ class Query } } + /** + * 去除某个查询条件 + * @access public + * @param string $field 查询字段 + * @param string $logic 查询逻辑 and or xor + * @return $this + */ + public function removeWhereField($field, $logic = 'AND') + { + $logic = strtoupper($logic); + if (isset($this->options['where'][$logic][$field])) { + unset($this->options['where'][$logic][$field]); + } + return $this; + } + /** * 指定查询数量 * @access public diff --git a/library/traits/model/SoftDelete.php b/library/traits/model/SoftDelete.php index 9f7cedce..8ecf35de 100644 --- a/library/traits/model/SoftDelete.php +++ b/library/traits/model/SoftDelete.php @@ -27,7 +27,8 @@ trait SoftDelete public static function withTrashed() { $model = new static(); - return $model->db(false); + $field = $model->getDeleteTimeField(true); + return $model->db(false)->removeWhereField($field); } /** -- Gitee From 3ea09822e059ab3bed46a8e8ef81f6c37ea8e411 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 11 Nov 2016 11:37:15 +0800 Subject: [PATCH 0145/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=BD=AF=E5=88=A0?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/traits/model/SoftDelete.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/traits/model/SoftDelete.php b/library/traits/model/SoftDelete.php index 8ecf35de..9d855c76 100644 --- a/library/traits/model/SoftDelete.php +++ b/library/traits/model/SoftDelete.php @@ -139,7 +139,8 @@ trait SoftDelete $field = $this->db(false)->getTable() . '.' . $field; } if (!$read && strpos($field, '.')) { - list($alias, $field) = explode('.', $field); + $array = explode('.', $field); + $field = array_pop($array); } return $field; } -- Gitee From af97ea582107fe46ccc993e69799c5d072cd8953 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 11 Nov 2016 11:54:37 +0800 Subject: [PATCH 0146/1170] =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base.php b/base.php index 4d0b703c..5bd1b405 100644 --- a/base.php +++ b/base.php @@ -9,7 +9,7 @@ // | Author: liu21st // +---------------------------------------------------------------------- -define('THINK_VERSION', '5.0.3beta'); +define('THINK_VERSION', '5.0.3'); define('THINK_START_TIME', microtime(true)); define('THINK_START_MEM', memory_get_usage()); define('EXT', '.php'); -- Gitee From fd30f090e40dc25a758d99029fa07f669f575580 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 11 Nov 2016 17:22:23 +0800 Subject: [PATCH 0147/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BModel=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 8073ca06..aed24f7a 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -1365,19 +1365,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess public static function __callStatic($method, $params) { - $query = self::getDb(); + $query = (new static())->db(); return call_user_func_array([$query, $method], $params); } - protected static function getDb() - { - $model = get_called_class(); - if (!isset(self::$links[$model])) { - self::$links[$model] = (new static())->db(); - } - return self::$links[$model]; - } - /** * 修改器 设置数据对象的值 * @access public -- Gitee From a924186ce6f58f5ab140362a92ede82b898cb211 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 12 Nov 2016 10:38:19 +0800 Subject: [PATCH 0148/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3count=20avg?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E4=BD=BF=E7=94=A8fetchsql=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E8=BF=94=E5=9B=9Esql=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 3f4d5fd0..fdf9d623 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -378,7 +378,7 @@ class Query public function value($field, $default = null) { $result = false; - if (!empty($this->options['cache'])) { + if (empty($options['fetch_sql']) && !empty($this->options['cache'])) { // 判断查询缓存 $cache = $this->options['cache']; if (empty($this->options['table'])) { @@ -422,7 +422,7 @@ class Query public function column($field, $key = '') { $result = false; - if (!empty($this->options['cache'])) { + if (empty($options['fetch_sql']) && !empty($this->options['cache'])) { // 判断查询缓存 $cache = $this->options['cache']; if (empty($this->options['table'])) { @@ -489,7 +489,8 @@ class Query */ public function count($field = '*') { - return (int) $this->value('COUNT(' . $field . ') AS tp_count', 0); + $value = $this->value('COUNT(' . $field . ') AS tp_count', 0); + return is_numeric($value) ? (int) $value : $value; } /** @@ -500,7 +501,8 @@ class Query */ public function sum($field = '*') { - return $this->value('SUM(' . $field . ') AS tp_sum', 0) + 0; + $value = $this->value('SUM(' . $field . ') AS tp_sum', 0); + return is_numeric($value) ? $value + 0 : $value; } /** @@ -535,7 +537,8 @@ class Query */ public function avg($field = '*') { - return $this->value('AVG(' . $field . ') AS tp_avg', 0) + 0; + $value = $this->value('AVG(' . $field . ') AS tp_avg', 0); + return is_numeric($value) ? $value + 0 : $value; } /** -- Gitee From 310775471a00f762bcf0ba6c2f92dd073dbb92cc Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 12 Nov 2016 11:11:18 +0800 Subject: [PATCH 0149/1170] =?UTF-8?q?table=E6=96=B9=E6=B3=95=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=96=B9=E5=BC=8F=E7=9A=84?= =?UTF-8?q?=E5=AD=90=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index fdf9d623..5e7bf07d 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1050,7 +1050,10 @@ class Query public function table($table) { if (is_string($table)) { - if (strpos($table, ',')) { + if (strpos($table, ')')) { + // 子查询 + $table = $table; + } elseif (strpos($table, ',')) { $tables = explode(',', $table); $table = []; foreach ($tables as $item) { -- Gitee From 72209e80353a5f34b2ad9d5863fd9d85e98dfc19 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 12 Nov 2016 23:55:17 +0800 Subject: [PATCH 0150/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BB?= =?UTF-8?q?=E7=9A=84=E8=81=9A=E5=90=88=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 5e7bf07d..5a5597e1 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -373,9 +373,10 @@ class Query * @access public * @param string $field 字段名 * @param mixed $default 默认值 + * @param bool $force 强制转为数字类型 * @return mixed */ - public function value($field, $default = null) + public function value($field, $default = null, $force = false) { $result = false; if (empty($options['fetch_sql']) && !empty($this->options['cache'])) { @@ -397,6 +398,9 @@ class Query return $pdo; } $result = $pdo->fetchColumn(); + if ($force) { + $result = is_numeric($result) ? $result + 0 : $result; + } if (isset($cache)) { // 缓存数据 if (isset($cache['tag'])) { @@ -489,8 +493,7 @@ class Query */ public function count($field = '*') { - $value = $this->value('COUNT(' . $field . ') AS tp_count', 0); - return is_numeric($value) ? (int) $value : $value; + return $this->value('COUNT(' . $field . ') AS tp_count', 0, true); } /** @@ -501,8 +504,7 @@ class Query */ public function sum($field = '*') { - $value = $this->value('SUM(' . $field . ') AS tp_sum', 0); - return is_numeric($value) ? $value + 0 : $value; + return $this->value('SUM(' . $field . ') AS tp_sum', 0, true); } /** @@ -513,8 +515,7 @@ class Query */ public function min($field = '*') { - $value = $this->value('MIN(' . $field . ') AS tp_min', 0); - return is_numeric($value) ? $value + 0 : $value; + return $this->value('MIN(' . $field . ') AS tp_min', 0, true); } /** @@ -525,8 +526,7 @@ class Query */ public function max($field = '*') { - $value = $this->value('MAX(' . $field . ') AS tp_max', 0); - return is_numeric($value) ? $value + 0 : $value; + return $this->value('MAX(' . $field . ') AS tp_max', 0, true); } /** @@ -537,8 +537,7 @@ class Query */ public function avg($field = '*') { - $value = $this->value('AVG(' . $field . ') AS tp_avg', 0); - return is_numeric($value) ? $value + 0 : $value; + return $this->value('AVG(' . $field . ') AS tp_avg', 0, true); } /** -- Gitee From b7ef4c6f33d465bcb9c4ab3c6e32d2f8fdf41d29 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 14 Nov 2016 11:27:00 +0800 Subject: [PATCH 0151/1170] =?UTF-8?q?Cache=E7=B1=BB=E5=A2=9E=E5=8A=A0pull?= =?UTF-8?q?=E5=92=8Cremember=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Cache.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/library/think/Cache.php b/library/think/Cache.php index a5ac0b32..208190be 100644 --- a/library/think/Cache.php +++ b/library/think/Cache.php @@ -185,6 +185,35 @@ class Cache return self::$handler->clear($tag); } + /** + * 读取缓存并删除 + * @access public + * @param string $name 缓存变量名 + * @return mixed + */ + public static function pull($name) + { + self::init(); + self::$readTimes++; + self::$writeTimes++; + return self::$handler->pull($name); + } + + /** + * 如果不存在则写入缓存 + * @access public + * @param string $name 缓存变量名 + * @param mixed $value 存储数据 + * @param int $expire 有效时间 0为永久 + * @return mixed + */ + public static function remember($name, $value, $expire = null) + { + self::init(); + self::$readTimes++; + return self::$handler->remember($name, $value, $expire); + } + /** * 缓存标签 * @access public -- Gitee From 8d65e16047aed71459bfc8a6328e4b7bf968db1b Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 14 Nov 2016 22:44:18 +0800 Subject: [PATCH 0152/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9Binput=E5=8A=A9?= =?UTF-8?q?=E6=89=8B=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helper.php b/helper.php index b81970c7..02d8761a 100644 --- a/helper.php +++ b/helper.php @@ -125,7 +125,7 @@ if (!function_exists('input')) { } if ($pos = strpos($key, '.')) { // 指定参数来源 - list($method, $key) = explode('.', $key); + list($method, $key) = explode('.', $key, 2); if (!in_array($method, ['get', 'post', 'put', 'patch', 'delete', 'param', 'request', 'session', 'cookie', 'server', 'env', 'path', 'file'])) { $key = $method . '.' . $key; $method = 'param'; -- Gitee From e643514af815123399424be3cdc9404b25c5d364 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 15 Nov 2016 18:53:56 +0800 Subject: [PATCH 0153/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=85=B3=E8=81=94?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E7=9A=84=E6=97=B6=E5=80=99=20whereTime?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Builder.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index 69484ffe..c963a704 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -397,7 +397,15 @@ abstract class Builder protected function parseDateTime($value, $key, $options = [], $bindName = null, $bindType = null) { // 获取时间字段类型 - $type = $this->query->getFieldsType($options); + if (strpos($key, '.')) { + list($table, $key) = explode('.', $key); + if (isset($options['alias']) && $pos = array_search($table, $options['alias'])) { + $table = $pos; + } + } else { + $table = $options['table']; + } + $type = $this->query->getTableInfo($table, 'type'); if (isset($type[$key])) { $info = $type[$key]; } -- Gitee From 3d587c75c52fb1ce31210fb4362026ca36d921ab Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 15 Nov 2016 19:09:31 +0800 Subject: [PATCH 0154/1170] =?UTF-8?q?model=E7=B1=BB=E7=9A=84saveall?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E6=94=AF=E6=8C=81=E8=B0=83=E7=94=A8allowFiel?= =?UTF-8?q?d=E6=96=B9=E6=B3=95=E8=BF=9B=E8=A1=8C=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index aed24f7a..181ed8e9 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -759,9 +759,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess } foreach ($dataSet as $key => $data) { if (!empty($auto) && isset($data[$pk])) { - $result[$key] = self::update($data); + $result[$key] = self::update($data, [], $this->field); } else { - $result[$key] = self::create($data); + $result[$key] = self::create($data, $this->field); } } $db->commit(); @@ -979,12 +979,16 @@ abstract class Model implements \JsonSerializable, \ArrayAccess /** * 写入数据 * @access public - * @param array $data 数据数组 + * @param array $data 数据数组 + * @param array|true $field 允许字段 * @return $this */ - public static function create($data = []) + public static function create($data = [], $field = null) { $model = new static(); + if (!empty($field)) { + $model->allowField($field); + } $model->isUpdate(false)->save($data, []); return $model; } @@ -992,13 +996,17 @@ abstract class Model implements \JsonSerializable, \ArrayAccess /** * 更新数据 * @access public - * @param array $data 数据数组 - * @param array $where 更新条件 + * @param array $data 数据数组 + * @param array $where 更新条件 + * @param array|true $field 允许字段 * @return $this */ - public static function update($data = [], $where = []) + public static function update($data = [], $where = [], $field = null) { - $model = new static(); + $model = new static(); + if (!empty($field)) { + $model->allowField($field); + } $result = $model->isUpdate(true)->save($data, $where); return $model; } -- Gitee From 81a8da68783552ef7993b3b51dc04d36b78c3684 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 15 Nov 2016 23:01:11 +0800 Subject: [PATCH 0155/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BRoute=E7=B1=BBname?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index c8eb24e6..96e47895 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -151,7 +151,7 @@ class Route } elseif ('' === $name) { return self::$rules['name']; } elseif (!is_null($value)) { - self::$rules['name'][$name][] = $value; + self::$rules['name'][strtolower($name)][] = $value; } else { $name = strtolower($name); return isset(self::$rules['name'][$name]) ? self::$rules['name'][$name] : null; @@ -310,7 +310,7 @@ class Route $vars = self::parseVar($rule); if (isset($name)) { $key = $group ? $group . ($rule ? '/' . $rule : '') : $rule; - self::name(strtolower($name), [$key, $vars, self::$domain]); + self::name($name, [$key, $vars, self::$domain]); } if ($group) { if ('*' != $type) { -- Gitee From 665b2c3ab9800f423536de38826a887e7e65891d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E5=88=9D=E7=9A=84=E6=A2=A6=E6=83=B3?= <381296986@qq.com> Date: Wed, 16 Nov 2016 10:10:15 +0800 Subject: [PATCH 0156/1170] =?UTF-8?q?=E5=9C=A8=E6=8E=A7=E5=88=B6=E5=99=A8?= =?UTF-8?q?=E4=B8=AD=E8=B0=83=E7=94=A8request=E5=92=8Cview=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=B1=BB=E5=9E=8B=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在控制器中调用request和view属性增加类型提示 --- library/think/Controller.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/library/think/Controller.php b/library/think/Controller.php index a889e4d9..fe4efae2 100644 --- a/library/think/Controller.php +++ b/library/think/Controller.php @@ -20,9 +20,13 @@ class Controller { use \traits\controller\Jump; - // 视图类实例 + /** + * @var \think\View 视图类实例 + */ protected $view; - // Request实例 + /** + * @var \think\Request Request实例 + */ protected $request; // 验证失败是否抛出异常 protected $failException = false; -- Gitee From 45f260d11ae67f0e33fc88279e377b3c0a38c7e2 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 17 Nov 2016 22:24:45 +0800 Subject: [PATCH 0157/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BB?= =?UTF-8?q?=E7=9A=84getTableInfo=E6=96=B9=E6=B3=95=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 5a5597e1..6020b527 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1416,9 +1416,10 @@ class Query } list($guid) = explode(' ', $tableName); - if (!isset(self::$info[$guid])) { + $db = $this->getConfig('database'); + if (!isset(self::$info[$db . '.' . $guid])) { if (!strpos($guid, '.')) { - $schema = $this->getConfig('database') . '.' . $guid; + $schema = $db . '.' . $guid; } else { $schema = $guid; } @@ -1444,9 +1445,9 @@ class Query } else { $pk = null; } - self::$info[$guid] = ['fields' => $fields, 'type' => $type, 'bind' => $bind, 'pk' => $pk]; + self::$info[$db . '.' . $guid] = ['fields' => $fields, 'type' => $type, 'bind' => $bind, 'pk' => $pk]; } - return $fetch ? self::$info[$guid][$fetch] : self::$info[$guid]; + return $fetch ? self::$info[$db . '.' . $guid][$fetch] : self::$info[$db . '.' . $guid]; } /** -- Gitee From 78dffc5b4e10055e202d7b83bb564668975c9037 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 18 Nov 2016 12:30:19 +0800 Subject: [PATCH 0158/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E7=9A=84=E8=AF=B7=E6=B1=82=E7=BC=93=E5=AD=98=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Route.php b/library/think/Route.php index 96e47895..2cc4a333 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1496,7 +1496,7 @@ class Route if (is_array($cache)) { list($key, $expire) = $cache; } else { - $key = $pathinfo; + $key = str_replace('|', '/', $pathinfo); $expire = $cache; } $request->cache($key, $expire); -- Gitee From c469b9fb4d3a128ee0a87f01e7bf9e852a342b60 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 18 Nov 2016 14:29:23 +0800 Subject: [PATCH 0159/1170] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E7=9A=84=E5=BF=AB=E6=8D=B7=E4=BA=8B=E4=BB=B6=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/library/think/Model.php b/library/think/Model.php index 181ed8e9..c79d0cac 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -1472,4 +1472,47 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $this->initialize(); } + /** + * 模型事件快捷方法 + */ + protected static function beforeInsert($callback, $override = false) + { + self::event('before_insert', $callback, $override); + } + + protected static function afterInsert($callback, $override = false) + { + self::event('after_insert', $callback, $override); + } + + protected static function beforeUpdate($callback, $override = false) + { + self::event('before_update', $callback, $override); + } + + protected static function afterUpdate($callback, $override = false) + { + self::event('after_update', $callback, $override); + } + + protected static function beforeWrite($callback, $override = false) + { + self::event('before_write', $callback, $override); + } + + protected static function afterWrite($callback, $override = false) + { + self::event('after_write', $callback, $override); + } + + protected static function beforeDelete($callback, $override = false) + { + self::event('before_delete', $callback, $override); + } + + protected static function afterDelete($callback, $override = false) + { + self::event('after_delete', $callback, $override); + } + } -- Gitee From 0a9694123fc6b5fe59ff0da8520f98a0a4dac938 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 20 Nov 2016 13:12:01 +0800 Subject: [PATCH 0160/1170] =?UTF-8?q?=E7=A9=BA=E6=93=8D=E4=BD=9C=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E7=9A=84=E5=8F=82=E6=95=B0=E4=BC=A0=E5=85=A5=E5=8E=BB?= =?UTF-8?q?=E6=8E=89=E6=93=8D=E4=BD=9C=E6=96=B9=E6=B3=95=E5=90=8E=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/App.php b/library/think/App.php index 4eddc7cd..f8c3d29c 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -386,7 +386,7 @@ class App } elseif (is_callable([$instance, '_empty'])) { // 空操作 $call = [$instance, '_empty']; - $vars = [$action]; + $vars = [$$actionName]; } else { // 操作不存在 throw new HttpException(404, 'method not exists:' . get_class($instance) . '->' . $action . '()'); -- Gitee From a3a76b9bcf7da1e0be838ad481ec6ba5602c252e Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 21 Nov 2016 12:14:36 +0800 Subject: [PATCH 0161/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/App.php b/library/think/App.php index f8c3d29c..ba102162 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -386,7 +386,7 @@ class App } elseif (is_callable([$instance, '_empty'])) { // 空操作 $call = [$instance, '_empty']; - $vars = [$$actionName]; + $vars = [$actionName]; } else { // 操作不存在 throw new HttpException(404, 'method not exists:' . get_class($instance) . '->' . $action . '()'); -- Gitee From a10cc77e406d53eb730b27d6f1a5adc5ea56a7c8 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 21 Nov 2016 15:33:55 +0800 Subject: [PATCH 0162/1170] =?UTF-8?q?=E6=95=B0=E7=BB=84=E8=AF=AD=E6=B3=95?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Request.php b/library/think/Request.php index 45b65423..d77e4e77 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -1258,7 +1258,7 @@ class Request } // IP地址合法验证 $long = sprintf("%u", ip2long($ip)); - $ip = $long ? array($ip, $long) : array('0.0.0.0', 0); + $ip = $long ? [$ip, $long] : ['0.0.0.0', 0]; return $ip[$type]; } -- Gitee From 384ce564f95bf31ad5faec44c2053af3b2d0f1f7 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 22 Nov 2016 11:08:45 +0800 Subject: [PATCH 0163/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BB?= =?UTF-8?q?=E5=AF=B9=E6=95=B0=E6=8D=AE=E9=9B=86=E5=AF=B9=E8=B1=A1=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E5=85=B3=E8=81=94=E5=AD=97=E6=AE=B5=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 6020b527..a46bbed4 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -2139,19 +2139,30 @@ class Query $column = $column ?: $this->getPk($table); $bind = $this->bind; $resultSet = $this->limit($count)->order($column, 'asc')->select(); + if (strpos($column, '.')) { + list($alias, $key) = explode('.', $column); + } else { + $key = $column; + } + if ($resultSet instanceof Collection) { + $resultSet = $resultSet->all(); + } while (!empty($resultSet)) { if (false === call_user_func($callback, $resultSet)) { return false; } $end = end($resultSet); - $lastId = is_array($end) ? $end[$column] : $end->$column; + $lastId = is_array($end) ? $end[$key] : $end->$key; $resultSet = $this->options($options) ->limit($count) ->bind($bind) ->where($column, '>', $lastId) ->order($column, 'asc') ->select(); + if ($resultSet instanceof Collection) { + $resultSet = $resultSet->all(); + } } return true; } -- Gitee From 72cdb44de8b2954b247133b0e2c7c8825a9b288b Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 22 Nov 2016 14:32:22 +0800 Subject: [PATCH 0164/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9Bin=E5=92=8Cbetween?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=9D=A1=E4=BB=B6=E7=9A=84=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Builder.php | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index c963a704..e790cf34 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -333,8 +333,13 @@ abstract class Builder $bind = []; $array = []; foreach ($value as $k => $v) { - $bind[$bindName . '_in_' . $k] = [$v, $bindType]; - $array[] = ':' . $bindName . '_in_' . $k; + if ($this->query->isBind($bindName . '_in_' . $k)) { + $bindKey = $bindName . '_in_' . uniqid() . '_' . $k; + } else { + $bindKey = $bindName . '_in_' . $k; + } + $bind[$bindKey] = [$v, $bindType]; + $array[] = ':' . $bindKey; } $this->query->bind($bind); $zone = implode(',', $array); @@ -347,12 +352,19 @@ abstract class Builder // BETWEEN 查询 $data = is_array($value) ? $value : explode(',', $value); if (array_key_exists($field, $binds)) { + if ($this->query->isBind($bindName . '_between_1')) { + $bindKey1 = $bindName . '_between_1' . uniqid(); + $bindKey2 = $bindName . '_between_2' . uniqid(); + } else { + $bindKey1 = $bindName . '_between_1'; + $bindKey2 = $bindName . '_between_2'; + } $bind = [ - $bindName . '_between_1' => [$data[0], $bindType], - $bindName . '_between_2' => [$data[1], $bindType], + $bindKey1 => [$data[0], $bindType], + $bindKey2 => [$data[1], $bindType], ]; $this->query->bind($bind); - $between = ':' . $bindName . '_between_1' . ' AND :' . $bindName . '_between_2'; + $between = ':' . $bindKey1 . ' AND :' . $bindKey2; } else { $between = $this->parseValue($data[0], $field) . ' AND ' . $this->parseValue($data[1], $field); } @@ -410,7 +422,10 @@ abstract class Builder $info = $type[$key]; } if (isset($info)) { - $value = strtotime($value) ?: $value; + if (is_numeric($value) && strtotime($value)) { + $value = strtotime($value) ?: $value; + } + if (preg_match('/(datetime|timestamp)/is', $info)) { // 日期及时间戳类型 $value = date('Y-m-d H:i:s', $value); -- Gitee From 8ee455f96f82fb2a8178be8f775e0b3ae12b6ea5 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 22 Nov 2016 15:54:29 +0800 Subject: [PATCH 0165/1170] =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E7=B1=BB=E7=9A=84c?= =?UTF-8?q?onnection=E5=B1=9E=E6=80=A7=E5=92=8C=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E9=85=8D=E7=BD=AE=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/library/think/Model.php b/library/think/Model.php index c79d0cac..df3692ed 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -156,8 +156,14 @@ abstract class Model implements \JsonSerializable, \ArrayAccess { $model = $this->class; if (!isset(self::$links[$model])) { + // 合并数据库配置 + if (is_array($this->connection)) { + $connection = array_merge(Config::get('database'), $this->connection); + } else { + $connection = $this->connection; + } // 设置当前模型 确保查询返回模型对象 - $query = Db::connect($this->connection)->model($model, $this->query); + $query = Db::connect($connection)->model($model, $this->query); // 设置当前数据表和模型名 if (!empty($this->table)) { -- Gitee From bba063a3c9b265f09cab66662bc15eb741f2eb42 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 22 Nov 2016 15:58:38 +0800 Subject: [PATCH 0166/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E5=BC=95=E6=93=8E=E9=A9=B1=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/view/driver/Php.php | 6 ++++-- library/think/view/driver/Think.php | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/library/think/view/driver/Php.php b/library/think/view/driver/Php.php index 31fe7807..4f3d7e85 100644 --- a/library/think/view/driver/Php.php +++ b/library/think/view/driver/Php.php @@ -119,9 +119,11 @@ class Php // 分析模板文件规则 $request = Request::instance(); $controller = Loader::parseName($request->controller()); - if ($controller && 0 !== strpos($template, '/')) { - $depr = $this->config['view_depr']; + $depr = $this->config['view_depr']; + if (0 !== strpos($template, '/')) { $template = str_replace(['/', ':'], $depr, $template); + } + if ($controller) { if ('' == $template) { // 如果模板文件名为空 按照默认规则定位 $template = str_replace('.', DS, $controller) . $depr . $request->action(); diff --git a/library/think/view/driver/Think.php b/library/think/view/driver/Think.php index db1d9816..8e673fde 100644 --- a/library/think/view/driver/Think.php +++ b/library/think/view/driver/Think.php @@ -121,9 +121,11 @@ class Think } $controller = Loader::parseName($request->controller()); - if ($controller && 0 !== strpos($template, '/')) { - $depr = $this->config['view_depr']; + $depr = $this->config['view_depr']; + if (0 !== strpos($template, '/')) { $template = str_replace(['/', ':'], $depr, $template); + } + if ($controller) { if ('' == $template) { // 如果模板文件名为空 按照默认规则定位 $template = str_replace('.', DS, $controller) . $depr . $request->action(); -- Gitee From ada54290b771dedc76b7ed482ec9d86eef522a02 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 22 Nov 2016 16:09:14 +0800 Subject: [PATCH 0167/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index e790cf34..c60d139a 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -306,7 +306,7 @@ abstract class Builder if (is_scalar($value) && array_key_exists($field, $binds) && !in_array($exp, ['EXP', 'NOT NULL', 'NULL', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN']) && strpos($exp, 'TIME') === false) { if (strpos($value, ':') !== 0 || !$this->query->isBind(substr($value, 1))) { if ($this->query->isBind($bindName)) { - $bindName .= '_' . uniqid(); + $bindName .= '_' . str_replace('.', '_', uniqid('', true)); } $this->query->bind($bindName, $value, $bindType); $value = ':' . $bindName; -- Gitee From 1839123bcdb17586e54ac5c0bf6d60189ea83afb Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 22 Nov 2016 17:18:59 +0800 Subject: [PATCH 0168/1170] =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E7=9A=84all?= =?UTF-8?q?=E5=92=8Cselect=E6=96=B9=E6=B3=95=E6=94=AF=E6=8C=81=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index a46bbed4..7505b5be 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1966,9 +1966,9 @@ class Query // 生成模型对象 $model = $this->model; foreach ($resultSet as $key => $result) { - /** @var Model $result */ - $result = new $model($result); - $result->isUpdate(true); + $result = new $model; + // 支持获取器 + $result->data($result, true)->isUpdate(true); // 关联查询 if (!empty($options['relation'])) { $result->relationQuery($options['relation']); -- Gitee From ee5ef96aacb6d4917d7f2393ed09c140f5a8caeb Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 22 Nov 2016 17:22:45 +0800 Subject: [PATCH 0169/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 7505b5be..88c12e0d 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1966,14 +1966,14 @@ class Query // 生成模型对象 $model = $this->model; foreach ($resultSet as $key => $result) { - $result = new $model; + $obj = new $model; // 支持获取器 - $result->data($result, true)->isUpdate(true); + $obj->data($result, true)->isUpdate(true); // 关联查询 if (!empty($options['relation'])) { $result->relationQuery($options['relation']); } - $resultSet[$key] = $result; + $resultSet[$key] = $obj; } if (!empty($options['with']) && $result instanceof Model) { // 预载入 -- Gitee From f756bb804e2a8d3565b39a6fc8f769a6bd704391 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 22 Nov 2016 17:24:44 +0800 Subject: [PATCH 0170/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 88c12e0d..a46bbed4 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1966,14 +1966,14 @@ class Query // 生成模型对象 $model = $this->model; foreach ($resultSet as $key => $result) { - $obj = new $model; - // 支持获取器 - $obj->data($result, true)->isUpdate(true); + /** @var Model $result */ + $result = new $model($result); + $result->isUpdate(true); // 关联查询 if (!empty($options['relation'])) { $result->relationQuery($options['relation']); } - $resultSet[$key] = $obj; + $resultSet[$key] = $result; } if (!empty($options['with']) && $result instanceof Model) { // 预载入 -- Gitee From 9db261e601a6c4e73ec2d58f54768b438a8c29a5 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 24 Nov 2016 15:57:43 +0800 Subject: [PATCH 0171/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Response.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/library/think/Response.php b/library/think/Response.php index a202ce76..2b84ed17 100644 --- a/library/think/Response.php +++ b/library/think/Response.php @@ -103,6 +103,16 @@ class Response Debug::inject($this, $data); } + if (200 == $this->code) { + $cache = Request::instance()->getCache(); + if ($cache) { + $this->header['Cache-Control'] = 'max-age=' . $cache[1] . ',must-revalidate'; + $this->header['Last-Modified'] = gmdate('D, d M Y H:i:s') . ' GMT'; + $this->header['Expires'] = gmdate('D, d M Y H:i:s', $_SERVER['REQUEST_TIME'] + $cache[1]) . ' GMT'; + Cache::set($cache[0], [$data, $this->header], $cache[1]); + } + } + if (!headers_sent() && !empty($this->header)) { // 发送状态码 http_response_code($this->code); @@ -111,16 +121,7 @@ class Response header($name . ':' . $val); } } - if (200 == $this->code) { - $cache = Request::instance()->getCache(); - if ($cache) { - header('Cache-Control: max-age=' . $cache[1] . ',must-revalidate'); - header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT'); - header('Expires:' . gmdate('D, d M Y H:i:s', $_SERVER['REQUEST_TIME'] + $cache[1]) . ' GMT'); - $header['Content-Type'] = $this->header['Content-Type']; - Cache::set($cache[0], [$data, $header], $cache[1]); - } - } + echo $data; if (function_exists('fastcgi_finish_request')) { -- Gitee From e1ed00dce04b78107c0536832e1a5c175e8cea9e Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 24 Nov 2016 17:52:30 +0800 Subject: [PATCH 0172/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3redis=20session?= =?UTF-8?q?=E9=A9=B1=E5=8A=A8destroy=E6=96=B9=E6=B3=95=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/session/driver/Memcache.php | 3 +++ library/think/session/driver/Memcached.php | 3 +++ library/think/session/driver/Redis.php | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/library/think/session/driver/Memcache.php b/library/think/session/driver/Memcache.php index 2c040271..4ef044a4 100644 --- a/library/think/session/driver/Memcache.php +++ b/library/think/session/driver/Memcache.php @@ -87,6 +87,7 @@ class Memcache extends SessionHandler * @access public * @param string $sessID * @param String $sessData + * @return bool */ public function write($sessID, $sessData) { @@ -97,6 +98,7 @@ class Memcache extends SessionHandler * 删除Session * @access public * @param string $sessID + * @return bool */ public function destroy($sessID) { @@ -107,6 +109,7 @@ class Memcache extends SessionHandler * Session 垃圾回收 * @access public * @param string $sessMaxLifeTime + * @return true */ public function gc($sessMaxLifeTime) { diff --git a/library/think/session/driver/Memcached.php b/library/think/session/driver/Memcached.php index 4187204a..01d0f1e0 100644 --- a/library/think/session/driver/Memcached.php +++ b/library/think/session/driver/Memcached.php @@ -95,6 +95,7 @@ class Memcached extends SessionHandler * @access public * @param string $sessID * @param String $sessData + * @return bool */ public function write($sessID, $sessData) { @@ -105,6 +106,7 @@ class Memcached extends SessionHandler * 删除Session * @access public * @param string $sessID + * @return bool */ public function destroy($sessID) { @@ -115,6 +117,7 @@ class Memcached extends SessionHandler * Session 垃圾回收 * @access public * @param string $sessMaxLifeTime + * @return true */ public function gc($sessMaxLifeTime) { diff --git a/library/think/session/driver/Redis.php b/library/think/session/driver/Redis.php index e3dc9983..f360d1a6 100644 --- a/library/think/session/driver/Redis.php +++ b/library/think/session/driver/Redis.php @@ -108,11 +108,11 @@ class Redis extends SessionHandler * 删除Session * @access public * @param string $sessID - * @return bool|void + * @return bool */ public function destroy($sessID) { - $this->handler->delete($this->config['session_name'] . $sessID); + return $this->handler->delete($this->config['session_name'] . $sessID); } /** -- Gitee From 0665ffcc46b962b5f6d49efe3708b17cd0a709c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=97=A0=E5=BF=83?= <448901948@qq.com> Date: Fri, 25 Nov 2016 11:49:36 +0800 Subject: [PATCH 0173/1170] Update Redis.php --- library/think/session/driver/Redis.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/session/driver/Redis.php b/library/think/session/driver/Redis.php index f360d1a6..52f14ab7 100644 --- a/library/think/session/driver/Redis.php +++ b/library/think/session/driver/Redis.php @@ -112,7 +112,7 @@ class Redis extends SessionHandler */ public function destroy($sessID) { - return $this->handler->delete($this->config['session_name'] . $sessID); + return $this->handler->delete($this->config['session_name'] . $sessID) > 0; } /** -- Gitee From c6dcc7a76816604823a139ac7c07d72c0a6d022f Mon Sep 17 00:00:00 2001 From: birdy0815 Date: Fri, 25 Nov 2016 19:05:21 +0800 Subject: [PATCH 0174/1170] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8=E6=9F=90=E4=B8=AA?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E7=9A=84=E9=AA=8C=E8=AF=81=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在做验证通用操作功能封装的时候,可以根据需要,是否启用场景验证 --- library/think/Validate.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/library/think/Validate.php b/library/think/Validate.php index fc38d89a..17c6ae89 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -216,6 +216,17 @@ class Validate return $this; } + /** + * 判断是否存在某个验证场景 + * @access public + * @param string $name 场景名 + * @return bool + */ + public function hasScene($name) + { + return isset($this->scene[$name]); + } + /** * 设置批量验证 * @access public -- Gitee From 3ff97b4b1e604460b751a2d42c27d91daff15b5f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 25 Nov 2016 20:33:35 +0800 Subject: [PATCH 0175/1170] =?UTF-8?q?View=E7=B1=BB=E5=A2=9E=E5=8A=A0share?= =?UTF-8?q?=E9=9D=99=E6=80=81=E6=96=B9=E6=B3=95=20=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E9=9D=99=E6=80=81=E8=B5=8B=E5=80=BC=E6=A8=A1=E6=9D=BF=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/View.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/library/think/View.php b/library/think/View.php index da087036..5fb9a142 100644 --- a/library/think/View.php +++ b/library/think/View.php @@ -19,6 +19,8 @@ class View public $engine; // 模板变量 protected $data = []; + // 用于静态赋值的模板变量 + protected static $var = []; // 视图输出替换 protected $replace = []; @@ -50,6 +52,22 @@ class View return self::$instance; } + /** + * 模板变量静态赋值 + * @access public + * @param mixed $name 变量名 + * @param mixed $value 变量值 + * @return void + */ + public static function share($name, $value = '') + { + if (is_array($name)) { + self::$var = array_merge(self::$var, $name); + } else { + self::$var[$name] = $value; + } + } + /** * 模板变量赋值 * @access public @@ -116,7 +134,7 @@ class View public function fetch($template = '', $vars = [], $replace = [], $config = [], $renderContent = false) { // 模板变量 - $vars = array_merge($this->data, $vars); + $vars = array_merge(self::$var, $this->data, $vars); // 页面缓存 ob_start(); -- Gitee From 2f892770c258a2b792556be0e73f65c1c7b487d3 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 26 Nov 2016 23:14:34 +0800 Subject: [PATCH 0176/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9Bsql=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E7=9A=84sql=E8=AF=AD=E5=8F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Connection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index 9806b827..d9b7978f 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -421,8 +421,8 @@ abstract class Connection $type = is_array($val) ? $val[1] : PDO::PARAM_STR; if (PDO::PARAM_STR == $type) { $value = $this->quote($value); - } elseif (PDO::PARAM_INT == $type && '' === $value) { - $value = 0; + } elseif (PDO::PARAM_INT == $type) { + $value = (float) $value; } // 判断占位符 $sql = is_numeric($key) ? -- Gitee From 1999bf947a99752f5ced1359aeab8635ad03b5be Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 27 Nov 2016 11:28:11 +0800 Subject: [PATCH 0177/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E5=99=A8=E8=87=AA=E5=8A=A8=E6=90=9C=E7=B4=A2=E7=9A=84=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Route.php b/library/think/Route.php index 2cc4a333..2fca9222 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1223,7 +1223,7 @@ class Route $find = true; break; } else { - $dir .= DS . $val; + $dir .= DS . Loader::parseName($val); } } if ($find) { -- Gitee From 5f7c75a2f57a469e3f8a63a619a5207d39ae70dd Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 28 Nov 2016 16:12:04 +0800 Subject: [PATCH 0178/1170] =?UTF-8?q?=E8=B7=AF=E7=94=B1=E5=88=B0=E7=B1=BB?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E6=B3=95=E5=92=8C=E6=8E=A7=E5=88=B6=E5=99=A8?= =?UTF-8?q?=E6=96=B9=E6=B3=95=20=E6=94=AF=E6=8C=81=E4=BC=A0=E5=85=A5?= =?UTF-8?q?=E9=A2=9D=E5=A4=96=E5=8F=82=E6=95=B0=EF=BC=8C=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E7=9A=84=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 4 ++-- library/think/Route.php | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/library/think/App.php b/library/think/App.php index ba102162..de96e1b4 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -141,11 +141,11 @@ class App break; case 'controller': // 执行控制器操作 - $data = Loader::action($dispatch['controller']); + $data = Loader::action($dispatch['controller'], $dispatch['var']); break; case 'method': // 执行回调方法 - $data = self::invokeMethod($dispatch['method']); + $data = self::invokeMethod($dispatch['method'], $dispatch['var']); break; case 'function': // 执行闭包 diff --git a/library/think/Route.php b/library/think/Route.php index 2fca9222..2060f134 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1480,12 +1480,15 @@ class Route $result = ['type' => 'redirect', 'url' => $route, 'status' => isset($option['status']) ? $option['status'] : 301]; } elseif (false !== strpos($route, '\\')) { // 路由到方法 - $route = str_replace('/', '@', $route); - $method = strpos($route, '@') ? explode('@', $route) : $route; - $result = ['type' => 'method', 'method' => $method]; + list($route, $var) = self::parseUrlPath($route); + $route = str_replace('/', '@', $route); + $method = strpos($route, '@') ? explode('@', $route) : $route; + $result = ['type' => 'method', 'method' => $method, 'var' => $var]; } elseif (0 === strpos($route, '@')) { // 路由到控制器 - $result = ['type' => 'controller', 'controller' => substr($route, 1)]; + $route = substr($route, 1); + list($route, $var) = self::parseUrlPath($route); + $result = ['type' => 'controller', 'controller' => $route, 'var' => $var]; } else { // 路由到模块/控制器/操作 $result = self::parseModule($route); -- Gitee From 357f1706e570f933bef7b51cf82dfc3b47b43f34 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 28 Nov 2016 16:26:29 +0800 Subject: [PATCH 0179/1170] =?UTF-8?q?=E8=B7=AF=E7=94=B1=E5=88=B0=E7=B1=BB?= =?UTF-8?q?=E5=92=8C=E6=8E=A7=E5=88=B6=E5=99=A8=E7=9A=84=E6=96=B9=E6=B3=95?= =?UTF-8?q?=20=E4=BC=A0=E5=85=A5=E7=9A=84=E9=A2=9D=E5=A4=96=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E4=BC=9A=E5=92=8C=E5=BD=93=E5=89=8D=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E5=90=88=E5=B9=B6=E4=BC=A0=E5=85=A5=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/think/App.php b/library/think/App.php index de96e1b4..2f0c57aa 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -141,11 +141,13 @@ class App break; case 'controller': // 执行控制器操作 - $data = Loader::action($dispatch['controller'], $dispatch['var']); + $vars = Request::instance()->param(); + $data = Loader::action($dispatch['controller'], array_merge($vars, $dispatch['var'])); break; case 'method': // 执行回调方法 - $data = self::invokeMethod($dispatch['method'], $dispatch['var']); + $vars = Request::instance()->param(); + $data = self::invokeMethod($dispatch['method'], array_merge($vars, $dispatch['var'])); break; case 'function': // 执行闭包 -- Gitee From 6e4898190ad53d02f4337023c56135986555ad2f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 28 Nov 2016 16:35:24 +0800 Subject: [PATCH 0180/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 10 +++++----- tests/thinkphp/library/think/routeTest.php | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index 2060f134..e2ebd655 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1480,15 +1480,15 @@ class Route $result = ['type' => 'redirect', 'url' => $route, 'status' => isset($option['status']) ? $option['status'] : 301]; } elseif (false !== strpos($route, '\\')) { // 路由到方法 - list($route, $var) = self::parseUrlPath($route); - $route = str_replace('/', '@', $route); - $method = strpos($route, '@') ? explode('@', $route) : $route; - $result = ['type' => 'method', 'method' => $method, 'var' => $var]; + list($path, $var) = self::parseUrlPath($route); + $route = str_replace('/', '@', implode('/', $path)); + $method = strpos($route, '@') ? explode('@', $route) : $route; + $result = ['type' => 'method', 'method' => $method, 'var' => $var]; } elseif (0 === strpos($route, '@')) { // 路由到控制器 $route = substr($route, 1); list($route, $var) = self::parseUrlPath($route); - $result = ['type' => 'controller', 'controller' => $route, 'var' => $var]; + $result = ['type' => 'controller', 'controller' => implode('/', $route), 'var' => $var]; } else { // 路由到模块/控制器/操作 $result = self::parseModule($route); diff --git a/tests/thinkphp/library/think/routeTest.php b/tests/thinkphp/library/think/routeTest.php index a86c21e1..b0215cee 100644 --- a/tests/thinkphp/library/think/routeTest.php +++ b/tests/thinkphp/library/think/routeTest.php @@ -227,7 +227,7 @@ class routeTest extends \PHPUnit_Framework_TestCase { $request = Request::instance(); Route::get('say/:name', '@index/hello'); - $this->assertEquals(['type' => 'controller', 'controller' => 'index/hello'], Route::check($request, 'say/thinkphp')); + $this->assertEquals(['type' => 'controller', 'controller' => 'index/hello', 'var' => []], Route::check($request, 'say/thinkphp')); } public function testRouteToMethod() @@ -235,8 +235,8 @@ class routeTest extends \PHPUnit_Framework_TestCase $request = Request::instance(); Route::get('user/:name', '\app\index\service\User::get', [], ['name' => '\w+']); Route::get('info/:name', '\app\index\model\Info@getInfo', [], ['name' => '\w+']); - $this->assertEquals(['type' => 'method', 'method' => '\app\index\service\User::get'], Route::check($request, 'user/thinkphp')); - $this->assertEquals(['type' => 'method', 'method' => ['\app\index\model\Info', 'getInfo']], Route::check($request, 'info/thinkphp')); + $this->assertEquals(['type' => 'method', 'method' => '\app\index\service\User::get', 'var' => []], Route::check($request, 'user/thinkphp')); + $this->assertEquals(['type' => 'method', 'method' => ['\app\index\model\Info', 'getInfo'], 'var' => []], Route::check($request, 'info/thinkphp')); } public function testRouteToRedirect() -- Gitee From 4aee4e378439573ab30735bc92a6fe104b0c208a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=97=A0=E5=BF=83?= <448901948@qq.com> Date: Mon, 28 Nov 2016 16:50:34 +0800 Subject: [PATCH 0181/1170] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Redirect=20restore?= =?UTF-8?q?=E3=80=81restore=E8=BF=94=E5=9B=9E=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/response/Redirect.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/think/response/Redirect.php b/library/think/response/Redirect.php index 0d65e5e3..4d06a24d 100644 --- a/library/think/response/Redirect.php +++ b/library/think/response/Redirect.php @@ -78,14 +78,17 @@ class Redirect extends Response /** * 记住当前url后跳转 + * @return $this */ - public function remember() + public function restore() { Session::set('redirect_url', Request::instance()->url()); + return $this; } /** * 跳转到上次记住的url + * @return $this */ public function restore() { @@ -93,5 +96,6 @@ class Redirect extends Response $this->data = Session::get('redirect_url'); Session::delete('redirect_url'); } + return $this; } } -- Gitee From bd6700acde2112ea1009751bef5a70c06339065c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=97=A0=E5=BF=83?= <448901948@qq.com> Date: Mon, 28 Nov 2016 16:51:53 +0800 Subject: [PATCH 0182/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/response/Redirect.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/response/Redirect.php b/library/think/response/Redirect.php index 4d06a24d..a3104c2f 100644 --- a/library/think/response/Redirect.php +++ b/library/think/response/Redirect.php @@ -80,7 +80,7 @@ class Redirect extends Response * 记住当前url后跳转 * @return $this */ - public function restore() + public function remember() { Session::set('redirect_url', Request::instance()->url()); return $this; -- Gitee From 7a79071d1a702b3b69a39a680fb5e2a0c94adb00 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 28 Nov 2016 22:44:59 +0800 Subject: [PATCH 0183/1170] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=AD=97=E6=AE=B5=E5=A4=9A=E6=AC=A1=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index a46bbed4..d35be22c 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -931,11 +931,16 @@ class Query $where[$field] = ['eq', $op]; } else { $where[$field] = [$op, $condition]; + // 记录一个字段多次查询条件 + $this->options['multi'][$field][] = $where[$field]; } if (!empty($where)) { if (!isset($this->options['where'][$logic])) { $this->options['where'][$logic] = []; } + if (isset($this->options['multi'][$field]) && count($this->options['multi'][$field]) > 1) { + $where[$field] = $this->options['multi'][$field]; + } $this->options['where'][$logic] = array_merge($this->options['where'][$logic], $where); } } -- Gitee From fedfd9c8573f43e3d376ea33026fca4aad8890ac Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 28 Nov 2016 23:24:48 +0800 Subject: [PATCH 0184/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index d35be22c..39ab03a9 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -917,6 +917,9 @@ class Query if (is_array($field)) { // 数组批量查询 $where = $field; + foreach ($where as $k => $val) { + $this->options['multi'][$k][] = $val; + } } elseif ($field && is_string($field)) { // 字符串查询 $where[$field] = ['null', '']; @@ -938,13 +941,25 @@ class Query if (!isset($this->options['where'][$logic])) { $this->options['where'][$logic] = []; } - if (isset($this->options['multi'][$field]) && count($this->options['multi'][$field]) > 1) { + if (is_string($field) && $this->checkMultiField($field)) { $where[$field] = $this->options['multi'][$field]; + } elseif (is_array($field)) { + foreach ($field as $key => $val) { + if ($this->checkMultiField($key)) { + $where[$key] = $this->options['multi'][$key]; + } + } } $this->options['where'][$logic] = array_merge($this->options['where'][$logic], $where); } } + // 检查是否存在一个字段多次查询条件 + private function checkMultiField($field) + { + return isset($this->options['multi'][$field]) && count($this->options['multi'][$field]) > 1; + } + /** * 去除某个查询条件 * @access public -- Gitee From 0962b21232eaea04350dd8705150128c1f1c5f47 Mon Sep 17 00:00:00 2001 From: quzhe Date: Tue, 29 Nov 2016 11:40:02 +0800 Subject: [PATCH 0185/1170] =?UTF-8?q?=E8=AE=A9Request=E6=94=AF=E6=8C=81jso?= =?UTF-8?q?n=E6=96=B9=E5=BC=8F=E7=9A=84POST=20=E7=9B=AE=E5=89=8DRESTful=20?= =?UTF-8?q?API=E7=94=A8json=E6=96=B9=E5=BC=8F=E6=8F=90=E4=BA=A4=E7=9A=84?= =?UTF-8?q?=E5=BE=88=E5=A4=9A=20=E7=9B=AE=E5=89=8DPUT/PATCH/DELETE?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=9D=87=E5=8F=AF=E4=BB=A5=E6=94=AF=E6=8C=81?= =?UTF-8?q?json=EF=BC=8C=E4=BD=86POST=E6=96=B9=E6=B3=95=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=EF=BC=8C=E8=BF=99=E4=B8=8D=E5=AF=B9=E7=AD=89=20=E5=85=B6?= =?UTF-8?q?=E5=AE=9E=E6=9B=B4=E5=A5=BD=E7=9A=84=E6=96=B9=E6=B3=95=E6=98=AF?= =?UTF-8?q?=E5=88=A4=E6=96=ADheader=E9=87=8Ccontent-type=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E4=B8=BAapplication/json=EF=BC=8C=E4=BD=86=E5=9B=A0=E4=B8=BA?= =?UTF-8?q?=E7=9B=AE=E5=89=8Dheader=E5=B1=9E=E6=80=A7=E9=87=87=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E6=98=AF=E6=87=92=E5=8A=A0=E8=BD=BD=EF=BC=8C=E6=89=80?= =?UTF-8?q?=E4=BB=A5=E6=9A=82=E6=97=B6=E6=B2=BF=E7=94=A8=E7=9B=AE=E5=89=8D?= =?UTF-8?q?=E7=9A=84=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/library/think/Request.php b/library/think/Request.php index d77e4e77..79c349f8 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -686,7 +686,12 @@ class Request public function post($name = '', $default = null, $filter = '') { if (empty($this->post)) { - $this->post = $_POST; + $content = $this->input; + if (empty($_POST) && strpos($content, '":')) { + $this->post = json_decode($content, true); + } else { + $this->post = $_POST; + } } if (is_array($name)) { $this->param = []; -- Gitee From da3f737ccc9f422575c47fbaad15fae05455fec5 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 29 Nov 2016 15:15:43 +0800 Subject: [PATCH 0186/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BApp=E7=B1=BBinvokeM?= =?UTF-8?q?ethod=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/App.php b/library/think/App.php index 2f0c57aa..671377b1 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -222,7 +222,7 @@ class App public static function invokeMethod($method, $vars = []) { if (is_array($method)) { - $class = is_object($method[0]) ? $method[0] : new $method[0](Request::instance()); + $class = is_object($method[0]) ? $method[0] : self::invokeClass($method[0]); $reflect = new \ReflectionMethod($class, $method[1]); } else { // 静态方法 -- Gitee From aed8be7150867173af3d10271e6943b3ee882c8d Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 29 Nov 2016 15:53:33 +0800 Subject: [PATCH 0187/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BModel=E7=9A=84?= =?UTF-8?q?=E4=B8=80=E5=A4=84=E6=95=B0=E6=8D=AE=E6=AF=94=E8=BE=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Model.php b/library/think/Model.php index df3692ed..fde0c318 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -300,7 +300,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess } // 标记字段更改 - if (!isset($this->data[$name]) || ($this->data[$name] != $value && !in_array($name, $this->change))) { + if (!isset($this->data[$name]) || (0 !== strcmp($this->data[$name], $value) && !in_array($name, $this->change))) { $this->change[] = $name; } // 设置数据对象属性 -- Gitee From 8b80794b39a602656e5600afa475dfd9edf3f4db Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 29 Nov 2016 16:00:23 +0800 Subject: [PATCH 0188/1170] =?UTF-8?q?Validate=E7=B1=BB=E6=9E=B6=E6=9E=84?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=A2=9E=E5=8A=A0field=E5=8F=82=E6=95=B0=20?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E8=AE=BE=E7=BD=AE=E9=AA=8C=E8=AF=81=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E7=9A=84=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index 17c6ae89..ac2f1925 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -34,6 +34,8 @@ class Validate // 验证提示信息 protected $message = []; + // 验证字段描述 + protected $field = []; // 验证规则默认提示信息 protected static $typeMsg = [ @@ -107,11 +109,13 @@ class Validate * @access public * @param array $rules 验证规则 * @param array $message 验证提示信息 + * @param array $field 验证字段描述信息 */ - public function __construct(array $rules = [], $message = []) + public function __construct(array $rules = [], $message = [], $field = []) { $this->rule = array_merge($this->rule, $rules); $this->message = array_merge($this->message, $message); + $this->field = $field; } /** @@ -119,12 +123,13 @@ class Validate * @access public * @param array $rules 验证规则 * @param array $message 验证提示信息 + * @param array $field 验证字段描述信息 * @return Validate */ - public static function make($rules = [], $message = []) + public static function make($rules = [], $message = [], $field = []) { if (is_null(self::$instance)) { - self::$instance = new self($rules, $message); + self::$instance = new self($rules, $message, $field); } return self::$instance; } @@ -291,7 +296,7 @@ class Validate // 字段|描述 用于指定属性名称 list($key, $title) = explode('|', $key); } else { - $title = $key; + $title = isset($this->field[$key]) ? $this->field[$key] : $key; } // 场景检测 -- Gitee From 2d4b1dda9c37c711bbf1088ad0061898d33c5a28 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 29 Nov 2016 22:08:12 +0800 Subject: [PATCH 0189/1170] =?UTF-8?q?=E8=AF=B7=E6=B1=82=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=A8=A1=E5=9D=97=E5=8D=95=E7=8B=AC=E5=BC=80?= =?UTF-8?q?=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/think/App.php b/library/think/App.php index 671377b1..367b4ae6 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -347,6 +347,8 @@ class App // 初始化模块 $request->module($module); $config = self::init($module); + // 模块请求缓存检查 + $request->cache($config['request_cache'], $config['request_cache_expire']); } else { throw new HttpException(404, 'module not exists:' . $module); } -- Gitee From 211b28706f6bdbd959079dfe2e9d855581d1cbc8 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 30 Nov 2016 15:33:14 +0800 Subject: [PATCH 0190/1170] =?UTF-8?q?=E5=A2=9E=E5=8A=A0debug=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E7=B1=BB=E5=9E=8B=20=E4=BB=85=E9=99=90=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E6=A8=A1=E5=BC=8F=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Log.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/think/Log.php b/library/think/Log.php index 5fd1631a..cdeccba9 100644 --- a/library/think/Log.php +++ b/library/think/Log.php @@ -32,13 +32,14 @@ class Log const SQL = 'sql'; const NOTICE = 'notice'; const ALERT = 'alert'; + const DEBUG = 'debug'; // 日志信息 protected static $log = []; // 配置参数 protected static $config = []; // 日志类型 - protected static $type = ['log', 'error', 'info', 'sql', 'notice', 'alert']; + protected static $type = ['log', 'error', 'info', 'sql', 'notice', 'alert', 'debug']; // 日志写入驱动 protected static $driver; @@ -136,6 +137,9 @@ class Log if (empty(self::$config['level'])) { // 获取全部日志 $log = self::$log; + if (!App::$debug && isset($log['debug'])) { + unset($log['debug']); + } } else { // 记录允许级别 $log = []; -- Gitee From 61462a628e070695148fdafae44d16f267fa7b99 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 30 Nov 2016 17:11:38 +0800 Subject: [PATCH 0191/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=A4=9A=E5=AF=B9?= =?UTF-8?q?=E5=A4=9A=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/Relation.php | 54 +++++++++++++++++--------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/library/think/model/Relation.php b/library/think/model/Relation.php index f9675c14..bec70387 100644 --- a/library/think/model/Relation.php +++ b/library/think/model/Relation.php @@ -662,32 +662,36 @@ class Relation public function __call($method, $args) { + static $baseQuery = []; if ($this->query) { - switch ($this->type) { - case self::HAS_MANY: - if (isset($this->where)) { - $this->query->where($this->where); - } elseif (isset($this->parent->{$this->localKey})) { - // 关联查询带入关联条件 - $this->query->where($this->foreignKey, $this->parent->{$this->localKey}); - } - break; - case self::HAS_MANY_THROUGH: - $through = $this->middle; - $model = $this->model; - $alias = Loader::parseName(basename(str_replace('\\', '/', $model))); - $throughTable = $through::getTable(); - $pk = (new $this->model)->getPk(); - $throughKey = $this->throughKey; - $modelTable = $this->parent->getTable(); - $this->query->field($alias . '.*')->alias($alias) - ->join($throughTable, $throughTable . '.' . $pk . '=' . $alias . '.' . $throughKey) - ->join($modelTable, $modelTable . '.' . $this->localKey . '=' . $throughTable . '.' . $this->foreignKey) - ->where($throughTable . '.' . $this->foreignKey, $this->parent->{$this->localKey}); - break; - case self::BELONGS_TO_MANY: - // TODO - + if (empty($baseQuery[$this->type])) { + $baseQuery[$this->type] = true; + switch ($this->type) { + case self::HAS_MANY: + if (isset($this->where)) { + $this->query->where($this->where); + } elseif (isset($this->parent->{$this->localKey})) { + // 关联查询带入关联条件 + $this->query->where($this->foreignKey, $this->parent->{$this->localKey}); + } + break; + case self::HAS_MANY_THROUGH: + $through = $this->middle; + $model = $this->model; + $alias = Loader::parseName(basename(str_replace('\\', '/', $model))); + $throughTable = $through::getTable(); + $pk = (new $this->model)->getPk(); + $throughKey = $this->throughKey; + $modelTable = $this->parent->getTable(); + $this->query->field($alias . '.*')->alias($alias) + ->join($throughTable, $throughTable . '.' . $pk . '=' . $alias . '.' . $throughKey) + ->join($modelTable, $modelTable . '.' . $this->localKey . '=' . $throughTable . '.' . $this->foreignKey) + ->where($throughTable . '.' . $this->foreignKey, $this->parent->{$this->localKey}); + break; + case self::BELONGS_TO_MANY: + $pk = $this->parent->getPk(); + $this->query->join($this->middle . ' pivot', 'pivot.' . $this->foreignKey . '=' . $this->query->getTable() . '.' . $this->query->getPk())->where('pivot.' . $this->localKey, $this->parent->$pk); + } } $result = call_user_func_array([$this->query, $method], $args); if ($result instanceof \think\db\Query) { -- Gitee From 7f527c256e5ae80f8659fdfdeddf53e6e14ef8f3 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 30 Nov 2016 19:52:58 +0800 Subject: [PATCH 0192/1170] =?UTF-8?q?=E5=85=B3=E8=81=94=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=A4=9A=E6=80=81=E4=B8=80=E5=AF=B9=E5=A4=9A?= =?UTF-8?q?=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 32 +++++++++++++++++ library/think/model/Relation.php | 62 ++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/library/think/Model.php b/library/think/Model.php index fde0c318..0f28b70a 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -1363,6 +1363,38 @@ abstract class Model implements \JsonSerializable, \ArrayAccess return $this->relation()->belongsToMany($model, $table, $foreignKey, $localKey, $alias); } + /** + * MORPH MANY 关联定义 + * @access public + * @param string $model 模型名 + * @param string $id 关联外键 + * @param string $morphType 多态字段名 + * @param string $type 多态类型 + * @return Relation + */ + public function morphMany($model, $id, $morphType = '', $type = '') + { + // 记录当前关联信息 + $model = $this->parseModel($model); + $type = $type ?: Loader::parseName($this->name); + $name = Loader::parseName(basename(str_replace('\\', '/', $model))); + $morphType = $morphType ?: Loader::parseName($name) . '_type'; + return $this->relation()->morphMany($model, $id, $morphType, $type); + } + + /** + * MORPH TO 关联定义 + * @access public + * @param string $morphType 多态字段名 + * @param string $foreignKey 外键名 + * @return Relation + */ + public function morphTo($morphType, $foreignKey) + { + // 记录当前关联信息 + return $this->relation()->morphTo($morphType, $foreignKey); + } + public function __call($method, $args) { $query = $this->db(); diff --git a/library/think/model/Relation.php b/library/think/model/Relation.php index bec70387..dbef09d3 100644 --- a/library/think/model/Relation.php +++ b/library/think/model/Relation.php @@ -24,6 +24,8 @@ class Relation const HAS_MANY_THROUGH = 5; const BELONGS_TO = 3; const BELONGS_TO_MANY = 4; + const MORPH_MANY = 7; + const MORPH_TO = 6; // 父模型对象 protected $parent; @@ -121,6 +123,20 @@ class Relation $set->pivot = new Pivot($pivot, $this->middle); } break; + case self::MORPH_MANY: + $result = $relation->select(); + break; + case self::MORPH_TO: + // 多态模型 + $model = $this->parent->{$this->middle}; + $path = explode('\\', get_class($this->parent)); + array_pop($path); + array_push($path, Loader::parseName($model, 1)); + $model = implode('\\', $path); + // 主键数据 + $pk = $this->parent->{$this->foreignKey}; + $result = (new $model)->find($pk); + break; default: // 直接返回 $result = $relation; @@ -516,6 +532,45 @@ class Relation return $this; } + /** + * MORPH_MANY 关联定义 + * @access public + * @param string $model 模型名 + * @param string $id 关联外键 + * @param string $morphType 多态字段名 + * @param string $type 多态类型 + * @return $this + */ + public function morphMany($model, $foreignKey, $morphType, $type) + { + // 记录当前关联信息 + $this->type = self::MORPH_MANY; + $this->model = $model; + $this->middle = $type; + $this->foreignKey = $foreignKey; + $this->localKey = $morphType; + $this->query = (new $model)->db(); + // 返回关联的模型对象 + return $this; + } + + /** + * MORPH_TO 关联定义 + * @access public + * @param string $morphType 多态字段名 + * @param string $foreignKey 外键名 + * @return $this + */ + public function morphTo($morphType, $foreignKey) + { + // 记录当前关联信息 + $this->type = self::MORPH_TO; + $this->middle = $morphType; + $this->foreignKey = $foreignKey; + // 返回关联的模型对象 + return $this; + } + /** * BELONGS TO MANY 关联查询 * @access public @@ -691,6 +746,13 @@ class Relation case self::BELONGS_TO_MANY: $pk = $this->parent->getPk(); $this->query->join($this->middle . ' pivot', 'pivot.' . $this->foreignKey . '=' . $this->query->getTable() . '.' . $this->query->getPk())->where('pivot.' . $this->localKey, $this->parent->$pk); + break; + case self::MORPH_MANY: + $pk = $this->parent->getPk(); + $map[$this->foreignKey] = $this->parent->$pk; + $map[$this->localKey] = $this->middle; + $this->query->where($map); + break; } } $result = call_user_func_array([$this->query, $method], $args); -- Gitee From 7983db9587b1686a6fbe30edc7875f580aba0495 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 30 Nov 2016 22:37:38 +0800 Subject: [PATCH 0193/1170] =?UTF-8?q?=E5=A4=9A=E6=80=81=E4=B8=80=E5=AF=B9?= =?UTF-8?q?=E5=A4=9A=E5=85=B3=E8=81=94=E6=96=B9=E6=B3=95=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 0f28b70a..32ce4e52 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -1367,31 +1367,39 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * MORPH MANY 关联定义 * @access public * @param string $model 模型名 - * @param string $id 关联外键 - * @param string $morphType 多态字段名 + * @param string|array $morph 多态字段信息 * @param string $type 多态类型 * @return Relation */ - public function morphMany($model, $id, $morphType = '', $type = '') + public function morphMany($model, $morph, $type = '') { // 记录当前关联信息 - $model = $this->parseModel($model); - $type = $type ?: Loader::parseName($this->name); - $name = Loader::parseName(basename(str_replace('\\', '/', $model))); - $morphType = $morphType ?: Loader::parseName($name) . '_type'; - return $this->relation()->morphMany($model, $id, $morphType, $type); + $model = $this->parseModel($model); + $type = $type ?: Loader::parseName($this->name); + if (is_array($morph)) { + list($foreignKey, $morphType) = $morph; + } else { + $morphType = $morph . '_type'; + $foreignKey = $morph . '_id'; + } + return $this->relation()->morphMany($model, $foreignKey, $morphType, $type); } /** * MORPH TO 关联定义 * @access public - * @param string $morphType 多态字段名 - * @param string $foreignKey 外键名 + * @param string|array $morph 多态字段信息 * @return Relation */ - public function morphTo($morphType, $foreignKey) + public function morphTo($morph) { // 记录当前关联信息 + if (is_array($morph)) { + list($foreignKey, $morphType) = $morph; + } else { + $morphType = $morph . '_type'; + $foreignKey = $morph . '_id'; + } return $this->relation()->morphTo($morphType, $foreignKey); } -- Gitee From 099c977b0a035d765789cb56fe73c373d07f1d59 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 30 Nov 2016 22:52:42 +0800 Subject: [PATCH 0194/1170] =?UTF-8?q?morphTo=E6=94=AF=E6=8C=81=E5=A4=9A?= =?UTF-8?q?=E6=80=81=E7=B1=BB=E5=9E=8B=E5=AD=97=E6=AE=B5=E5=88=AB=E5=90=8D?= =?UTF-8?q?=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 7 ++++--- library/think/model/Relation.php | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 32ce4e52..c626ea31 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -1388,10 +1388,11 @@ abstract class Model implements \JsonSerializable, \ArrayAccess /** * MORPH TO 关联定义 * @access public - * @param string|array $morph 多态字段信息 + * @param string|array $morph 多态字段信息 + * @param array $alias 多态别名定义 * @return Relation */ - public function morphTo($morph) + public function morphTo($morph, $alias = []) { // 记录当前关联信息 if (is_array($morph)) { @@ -1400,7 +1401,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $morphType = $morph . '_type'; $foreignKey = $morph . '_id'; } - return $this->relation()->morphTo($morphType, $foreignKey); + return $this->relation()->morphTo($morphType, $foreignKey, $alias); } public function __call($method, $args) diff --git a/library/think/model/Relation.php b/library/think/model/Relation.php index dbef09d3..c206c91d 100644 --- a/library/think/model/Relation.php +++ b/library/think/model/Relation.php @@ -129,10 +129,16 @@ class Relation case self::MORPH_TO: // 多态模型 $model = $this->parent->{$this->middle}; - $path = explode('\\', get_class($this->parent)); - array_pop($path); - array_push($path, Loader::parseName($model, 1)); - $model = implode('\\', $path); + // 多态类型映射 + if (isset($this->alias[$model])) { + $model = $this->alias[$model]; + } + if (false === strpos($model, '\\')) { + $path = explode('\\', get_class($this->parent)); + array_pop($path); + array_push($path, Loader::parseName($model, 1)); + $model = implode('\\', $path); + } // 主键数据 $pk = $this->parent->{$this->foreignKey}; $result = (new $model)->find($pk); @@ -559,14 +565,16 @@ class Relation * @access public * @param string $morphType 多态字段名 * @param string $foreignKey 外键名 + * @param array $alias 多态别名定义 * @return $this */ - public function morphTo($morphType, $foreignKey) + public function morphTo($morphType, $foreignKey, $alias) { // 记录当前关联信息 $this->type = self::MORPH_TO; $this->middle = $morphType; $this->foreignKey = $foreignKey; + $this->alias = $alias; // 返回关联的模型对象 return $this; } -- Gitee From a02c7321bb5aba21bc81f5cc566d897a3e2ddc0d Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 1 Dec 2016 10:50:56 +0800 Subject: [PATCH 0195/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=85=B3=E8=81=94?= =?UTF-8?q?=E5=A4=9A=E5=AF=B9=E5=A4=9A=E7=9A=84=E6=9F=A5=E8=AF=A2=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0getModel=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/Relation.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/library/think/model/Relation.php b/library/think/model/Relation.php index c206c91d..7be2ac46 100644 --- a/library/think/model/Relation.php +++ b/library/think/model/Relation.php @@ -21,11 +21,11 @@ class Relation { const HAS_ONE = 1; const HAS_MANY = 2; - const HAS_MANY_THROUGH = 5; const BELONGS_TO = 3; const BELONGS_TO_MANY = 4; - const MORPH_MANY = 7; + const HAS_MANY_THROUGH = 5; const MORPH_TO = 6; + const MORPH_MANY = 7; // 父模型对象 protected $parent; @@ -51,6 +51,7 @@ class Relation protected $where; // 关联查询参数 protected $option; + /** * 架构函数 * @access public @@ -61,6 +62,15 @@ class Relation $this->parent = $model; } + /** + * 获取关联的所属模型 + * @access public + */ + public function getModel() + { + return $this->parent; + } + /** * 获取当前关联信息 * @access public @@ -108,7 +118,7 @@ class Relation // 关联查询 $pk = $this->parent->getPk(); $condition['pivot.' . $localKey] = $this->parent->$pk; - $result = $this->belongsToManyQuery($relation, $this->middle, $foreignKey, $localKey, $condition)->select(); + $result = $this->belongsToManyQuery($relation->getModel(), $this->middle, $foreignKey, $localKey, $condition)->select(); foreach ($result as $set) { $pivot = []; foreach ($set->getData() as $key => $val) { -- Gitee From 77d2731892604af646e4186f95b93c68decc0afc Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 1 Dec 2016 11:28:49 +0800 Subject: [PATCH 0196/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=85=B3=E8=81=94?= =?UTF-8?q?=E5=A4=9A=E5=AF=B9=E5=A4=9A=E4=B8=80=E5=A4=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/Relation.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/library/think/model/Relation.php b/library/think/model/Relation.php index 7be2ac46..5bfd0773 100644 --- a/library/think/model/Relation.php +++ b/library/think/model/Relation.php @@ -71,6 +71,15 @@ class Relation return $this->parent; } + /** + * 获取关联的查询对象 + * @access public + */ + public function getQuery() + { + return $this->query; + } + /** * 获取当前关联信息 * @access public @@ -118,7 +127,7 @@ class Relation // 关联查询 $pk = $this->parent->getPk(); $condition['pivot.' . $localKey] = $this->parent->$pk; - $result = $this->belongsToManyQuery($relation->getModel(), $this->middle, $foreignKey, $localKey, $condition)->select(); + $result = $this->belongsToManyQuery($relation->getQuery(), $this->middle, $foreignKey, $localKey, $condition)->select(); foreach ($result as $set) { $pivot = []; foreach ($set->getData() as $key => $val) { @@ -604,7 +613,7 @@ class Relation // 关联查询封装 $tableName = $model->getTable(); $relationFk = $model->getPk(); - return $model::field($tableName . '.*') + return $model->field($tableName . '.*') ->field(true, false, $table, 'pivot', 'pivot__') ->join($table . ' pivot', 'pivot.' . $foreignKey . '=' . $tableName . '.' . $relationFk) ->where($condition); -- Gitee From 1afdde40e36b6fa34b4cdd60288b42c5a717ce46 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 1 Dec 2016 11:48:01 +0800 Subject: [PATCH 0197/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=A4=9A=E6=80=81?= =?UTF-8?q?=E5=85=B3=E8=81=94=E7=9A=84morphTo=E6=96=B9=E6=B3=95=20?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E4=B8=8D=E4=BC=A0=E5=85=A5=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E7=94=A8=E5=BD=93=E5=89=8D=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E6=B3=95=E5=90=8D=E4=BD=9C=E4=B8=BA=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=89=8D=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/think/Model.php b/library/think/Model.php index c626ea31..02806bd7 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -1392,8 +1392,12 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @param array $alias 多态别名定义 * @return Relation */ - public function morphTo($morph, $alias = []) + public function morphTo($morph = null, $alias = []) { + if (is_null($morph)) { + $trace = debug_backtrace(false, 2); + $morph = Loader::parseName($trace[1]['function']); + } // 记录当前关联信息 if (is_array($morph)) { list($foreignKey, $morphType) = $morph; -- Gitee From 7ef95130c195a3a76b8e7b7bedadd9f609f25ce2 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 1 Dec 2016 12:15:17 +0800 Subject: [PATCH 0198/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=85=B3=E8=81=94?= =?UTF-8?q?=E4=B8=80=E5=A4=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/Relation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/model/Relation.php b/library/think/model/Relation.php index 5bfd0773..21f68462 100644 --- a/library/think/model/Relation.php +++ b/library/think/model/Relation.php @@ -405,7 +405,7 @@ class Relation $foreignKey = $this->foreignKey; $localKey = $this->localKey; // 预载入关联查询 支持嵌套预载入 - $list = $this->belongsToManyQuery($model, $this->middle, $foreignKey, $localKey, $where)->with($subRelation)->select(); + $list = $this->belongsToManyQuery($model->getQuery(), $this->middle, $foreignKey, $localKey, $where)->with($subRelation)->select(); // 组装模型数据 $data = []; -- Gitee From b62175c34d6a3ba0e4c5c775f46764629377a997 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 1 Dec 2016 17:19:43 +0800 Subject: [PATCH 0199/1170] =?UTF-8?q?=E5=A4=9A=E6=80=81=E5=85=B3=E8=81=94?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=A2=84=E8=BD=BD=E5=85=A5=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 4 +- library/think/model/Relation.php | 156 ++++++++++++++++++++++++++++--- 2 files changed, 145 insertions(+), 15 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 02806bd7..0376f8d6 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -1377,7 +1377,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $model = $this->parseModel($model); $type = $type ?: Loader::parseName($this->name); if (is_array($morph)) { - list($foreignKey, $morphType) = $morph; + list($morphType, $foreignKey) = $morph; } else { $morphType = $morph . '_type'; $foreignKey = $morph . '_id'; @@ -1400,7 +1400,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess } // 记录当前关联信息 if (is_array($morph)) { - list($foreignKey, $morphType) = $morph; + list($morphType, $foreignKey) = $morph; } else { $morphType = $morph . '_type'; $foreignKey = $morph . '_id'; diff --git a/library/think/model/Relation.php b/library/think/model/Relation.php index 21f68462..fc420930 100644 --- a/library/think/model/Relation.php +++ b/library/think/model/Relation.php @@ -80,6 +80,26 @@ class Relation return $this->query; } + /** + * 解析模型的完整命名空间 + * @access public + * @param string $model 模型名(或者完整类名) + * @return string + */ + protected function parseModel($model) + { + if (isset($this->alias[$model])) { + $model = $this->alias[$model]; + } + if (false === strpos($model, '\\')) { + $path = explode('\\', get_class($this->parent)); + array_pop($path); + array_push($path, Loader::parseName($model, 1)); + $model = implode('\\', $path); + } + return $model; + } + /** * 获取当前关联信息 * @access public @@ -108,6 +128,7 @@ class Relation $relation = $this->parent->$name(); $foreignKey = $this->foreignKey; $localKey = $this->localKey; + $middle = $this->middle; // 判断关联类型执行查询 switch ($this->type) { @@ -127,7 +148,7 @@ class Relation // 关联查询 $pk = $this->parent->getPk(); $condition['pivot.' . $localKey] = $this->parent->$pk; - $result = $this->belongsToManyQuery($relation->getQuery(), $this->middle, $foreignKey, $localKey, $condition)->select(); + $result = $this->belongsToManyQuery($relation->getQuery(), $middle, $foreignKey, $localKey, $condition)->select(); foreach ($result as $set) { $pivot = []; foreach ($set->getData() as $key => $val) { @@ -147,19 +168,9 @@ class Relation break; case self::MORPH_TO: // 多态模型 - $model = $this->parent->{$this->middle}; - // 多态类型映射 - if (isset($this->alias[$model])) { - $model = $this->alias[$model]; - } - if (false === strpos($model, '\\')) { - $path = explode('\\', get_class($this->parent)); - array_pop($path); - array_push($path, Loader::parseName($model, 1)); - $model = implode('\\', $path); - } + $model = $this->parseModel($this->parent->$middle); // 主键数据 - $pk = $this->parent->{$this->foreignKey}; + $pk = $this->parent->$foreignKey; $result = (new $model)->find($pk); break; default: @@ -197,6 +208,7 @@ class Relation // 获取关联信息 $localKey = $this->localKey; $foreignKey = $this->foreignKey; + $middle = $this->middle; switch ($this->type) { case self::HAS_ONE: case self::BELONGS_TO: @@ -261,6 +273,64 @@ class Relation } } break; + case self::MORPH_MANY: + $range = []; + foreach ($resultSet as $result) { + $pk = $result->getPk(); + // 获取关联外键列表 + if (isset($result->$pk)) { + $range[] = $result->$pk; + } + } + + if (!empty($range)) { + $this->where[$foreignKey] = ['in', $range]; + $this->where[$localKey] = $middle; + $data = $this->eagerlyMorphToMany($model, [ + $foreignKey => ['in', $range], + $localKey => $middle, + ], $relation, $subRelation, $closure); + + // 关联数据封装 + foreach ($resultSet as $result) { + if (!isset($data[$result->$pk])) { + $data[$result->$pk] = []; + } + $result->setAttr($relation, $this->resultSetBuild($data[$result->$pk], $class)); + } + } + break; + case self::MORPH_TO: + $range = []; + foreach ($resultSet as $result) { + // 获取关联外键列表 + if (!empty($result->$foreignKey)) { + $range[$result->$middle][] = $result->$foreignKey; + } + } + + if (!empty($range)) { + foreach ($range as $key => $val) { + // 多态类型映射 + $model = $this->parseModel($key); + $obj = new $model; + $pk = $obj->getPk(); + $list = $obj->all($val, $subRelation); + $data = []; + foreach ($list as $k => $vo) { + $data[$vo->$pk] = $vo; + } + foreach ($resultSet as $result) { + if ($key == $result->$middle) { + if (!isset($data[$result->$foreignKey])) { + $data[$result->$foreignKey] = []; + } + $result->setAttr($relation, $this->resultSetBuild($data[$result->$foreignKey], $class)); + } + } + } + } + break; } } return $resultSet; @@ -304,6 +374,7 @@ class Relation $model = $this->parent->$relation(); $localKey = $this->localKey; $foreignKey = $this->foreignKey; + $middle = $this->middle; switch ($this->type) { case self::HAS_ONE: case self::BELONGS_TO: @@ -334,6 +405,18 @@ class Relation $result->setAttr($relation, $this->resultSetBuild($data[$pk], $class)); } break; + case self::MORPH_MANY: + $pk = $result->getPk(); + if (isset($result->$pk)) { + $data = $this->eagerlyMorphToMany($model, [$foreignKey => $result->$pk, $localKey => $middle], $relation, $subRelation, $closure); + $result->setAttr($relation, $this->resultSetBuild($data[$result->$pk], $class)); + } + break; + case self::MORPH_TO: + // 多态类型映射 + $model = $this->parseModel($result->{$this->middle}); + $this->eagerlyMorphToOne($model, $relation, $result, $subRelation); + break; } } @@ -426,6 +509,51 @@ class Relation return $data; } + /** + * 多态MorphTo 关联模型预查询 + * @access public + * @param object $model 关联模型对象 + * @param array $where 关联预查询条件 + * @param string $relation 关联名 + * @param string $subRelation 子关联 + * @return array + */ + protected function eagerlyMorphToOne($model, $relation, &$result, $subRelation = '') + { + // 预载入关联查询 支持嵌套预载入 + $pk = $this->parent->{$this->foreignKey}; + $data = (new $model)->with($subRelation)->find($pk); + if ($data) { + $data->isUpdate(true); + } + $result->setAttr($relation, $data ?: null); + } + + /** + * 多态一对多 关联模型预查询 + * @access public + * @param object $model 关联模型对象 + * @param array $where 关联预查询条件 + * @param string $relation 关联名 + * @param string $subRelation 子关联 + * @return array + */ + protected function eagerlyMorphToMany($model, $where, $relation, $subRelation = '', $closure = false) + { + // 预载入关联查询 支持嵌套预载入 + if ($closure) { + call_user_func_array($closure, [ & $model]); + } + $list = $model->getQuery()->where($where)->with($subRelation)->select(); + $foreignKey = $this->foreignKey; + // 组装模型数据 + $data = []; + foreach ($list as $set) { + $data[$set->$foreignKey][] = $set; + } + return $data; + } + /** * 设置当前关联定义的数据表别名 * @access public @@ -782,12 +910,14 @@ class Relation break; } } + $result = call_user_func_array([$this->query, $method], $args); if ($result instanceof \think\db\Query) { $this->option = $result->getOptions(); return $this; } else { $this->option = []; + $baseQuery = false; return $result; } } else { -- Gitee From 4a80099a511fb947be9f55a3bfdea74fb2181204 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 1 Dec 2016 18:32:28 +0800 Subject: [PATCH 0200/1170] =?UTF-8?q?=E9=83=A8=E7=BD=B2=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E4=B8=8B=E7=AE=80=E5=8C=96=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Log.php | 2 +- library/think/log/driver/File.php | 50 +++++++++++++++++------------ library/think/log/driver/Socket.php | 37 +++++++++++---------- 3 files changed, 51 insertions(+), 38 deletions(-) diff --git a/library/think/Log.php b/library/think/Log.php index cdeccba9..943e78c8 100644 --- a/library/think/Log.php +++ b/library/think/Log.php @@ -184,7 +184,7 @@ class Log self::init(Config::get('log')); } // 写入日志 - return self::$driver->save($log); + return self::$driver->save($log, false); } /** diff --git a/library/think/log/driver/File.php b/library/think/log/driver/File.php index c4e46279..f433718d 100644 --- a/library/think/log/driver/File.php +++ b/library/think/log/driver/File.php @@ -11,6 +11,8 @@ namespace think\log\driver; +use think\App; + /** * 本地化调试输出到文件 */ @@ -35,9 +37,10 @@ class File * 日志写入接口 * @access public * @param array $log 日志信息 + * @param bool $depr 是否写入分割线 * @return bool */ - public function save(array $log = []) + public function save(array $log = [], $depr = true) { $now = date($this->config['time_format']); $destination = $this->config['path'] . date('Ym') . DS . date('d') . '.log'; @@ -50,25 +53,29 @@ class File rename($destination, dirname($destination) . DS . $_SERVER['REQUEST_TIME'] . '-' . basename($destination)); } - // 获取基本信息 - if (isset($_SERVER['HTTP_HOST'])) { - $current_uri = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; - } else { - $current_uri = "cmd:" . implode(' ', $_SERVER['argv']); - } + $depr = $depr ? "---------------------------------------------------------------\r\n" : ''; - $runtime = number_format(microtime(true) - THINK_START_TIME, 10); - $reqs = $runtime > 0 ? number_format(1 / $runtime, 2) : '∞'; - $time_str = ' [运行时间:' . number_format($runtime, 6) . 's][吞吐率:' . $reqs . 'req/s]'; - $memory_use = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2); - $memory_str = ' [内存消耗:' . $memory_use . 'kb]'; - $file_load = ' [文件加载:' . count(get_included_files()) . ']'; + if (App::$debug) { + // 获取基本信息 + if (isset($_SERVER['HTTP_HOST'])) { + $current_uri = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; + } else { + $current_uri = "cmd:" . implode(' ', $_SERVER['argv']); + } - $info = '[ log ] ' . $current_uri . $time_str . $memory_str . $file_load . "\r\n"; - $server = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '0.0.0.0'; - $remote = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0'; - $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'CLI'; - $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; + $runtime = number_format(microtime(true) - THINK_START_TIME, 10); + $reqs = $runtime > 0 ? number_format(1 / $runtime, 2) : '∞'; + $time_str = ' [运行时间:' . number_format($runtime, 6) . 's][吞吐率:' . $reqs . 'req/s]'; + $memory_use = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2); + $memory_str = ' [内存消耗:' . $memory_use . 'kb]'; + $file_load = ' [文件加载:' . count(get_included_files()) . ']'; + + $info = '[ log ] ' . $current_uri . $time_str . $memory_str . $file_load . "\r\n"; + $server = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '0.0.0.0'; + $remote = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0'; + $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'CLI'; + $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; + } foreach ($log as $type => $val) { $level = ''; foreach ($val as $msg) { @@ -80,12 +87,15 @@ class File if (in_array($type, $this->config['apart_level'])) { // 独立记录的日志级别 $filename = $path . DS . date('d') . '_' . $type . '.log'; - error_log("[{$now}] {$server} {$remote} {$method} {$uri}\r\n{$level}\r\n---------------------------------------------------------------\r\n", 3, $filename); + error_log("[{$now}] {$level}\r\n{$depr}", 3, $filename); } else { $info .= $level; } } - return error_log("[{$now}] {$server} {$remote} {$method} {$uri}\r\n{$info}\r\n---------------------------------------------------------------\r\n", 3, $destination); + if (App::$debug) { + $info = "{$server} {$remote} {$method} {$uri}\r\n" . $info; + } + return error_log("[{$now}] {$info}\r\n{$depr}", 3, $destination); } } diff --git a/library/think/log/driver/Socket.php b/library/think/log/driver/Socket.php index f24b6091..cc4a8e12 100644 --- a/library/think/log/driver/Socket.php +++ b/library/think/log/driver/Socket.php @@ -63,24 +63,27 @@ class Socket if (!$this->check()) { return false; } - $runtime = number_format(microtime(true) - THINK_START_TIME, 10); - $reqs = $runtime > 0 ? number_format(1 / $runtime, 2) : '∞'; - $time_str = ' [运行时间:' . number_format($runtime, 6) . 's][吞吐率:' . $reqs . 'req/s]'; - $memory_use = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2); - $memory_str = ' [内存消耗:' . $memory_use . 'kb]'; - $file_load = ' [文件加载:' . count(get_included_files()) . ']'; - - if (isset($_SERVER['HTTP_HOST'])) { - $current_uri = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; - } else { - $current_uri = 'cmd:' . implode(' ', $_SERVER['argv']); + $trace = []; + if (App::$debug) { + $runtime = number_format(microtime(true) - THINK_START_TIME, 10); + $reqs = $runtime > 0 ? number_format(1 / $runtime, 2) : '∞'; + $time_str = ' [运行时间:' . number_format($runtime, 6) . 's][吞吐率:' . $reqs . 'req/s]'; + $memory_use = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2); + $memory_str = ' [内存消耗:' . $memory_use . 'kb]'; + $file_load = ' [文件加载:' . count(get_included_files()) . ']'; + + if (isset($_SERVER['HTTP_HOST'])) { + $current_uri = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; + } else { + $current_uri = 'cmd:' . implode(' ', $_SERVER['argv']); + } + // 基本信息 + $trace[] = [ + 'type' => 'group', + 'msg' => $current_uri . $time_str . $memory_str . $file_load, + 'css' => $this->css['page'], + ]; } - // 基本信息 - $trace[] = [ - 'type' => 'group', - 'msg' => $current_uri . $time_str . $memory_str . $file_load, - 'css' => $this->css['page'], - ]; foreach ($log as $type => $val) { $trace[] = [ -- Gitee From 82888cfe5342a04487081e4d0e00addecc22f3e1 Mon Sep 17 00:00:00 2001 From: lyaohe Date: Fri, 2 Dec 2016 11:53:09 +0800 Subject: [PATCH 0201/1170] =?UTF-8?q?error=E6=96=B9=E6=B3=95=E5=9C=A8ajax?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=EF=BC=8C=E9=BB=98=E8=AE=A4=E8=BF=94=E5=9B=9E?= =?UTF-8?q?url=E4=B8=BA=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/traits/controller/Jump.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/traits/controller/Jump.php b/library/traits/controller/Jump.php index 0fad996d..1ea788bb 100644 --- a/library/traits/controller/Jump.php +++ b/library/traits/controller/Jump.php @@ -80,8 +80,9 @@ trait Jump $code = $msg; $msg = ''; } + $isAjax = Request::instance()->isAjax(); if (is_null($url)) { - $url = 'javascript:history.back(-1);'; + $url = $isAjax ? '':'javascript:history.back(-1);'; } elseif ('' !== $url) { $url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : Url::build($url); } -- Gitee From 39ea6f812c8c0b873352a4495b47e32cb9cedcf4 Mon Sep 17 00:00:00 2001 From: lyaohe Date: Fri, 2 Dec 2016 15:11:34 +0800 Subject: [PATCH 0202/1170] =?UTF-8?q?error=E6=96=B9=E6=B3=95=E5=9C=A8ajax?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E9=BB=98=E8=AE=A4=E8=BF=94=E5=9B=9Eurl?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/traits/controller/Jump.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/library/traits/controller/Jump.php b/library/traits/controller/Jump.php index 1ea788bb..51f4281f 100644 --- a/library/traits/controller/Jump.php +++ b/library/traits/controller/Jump.php @@ -80,9 +80,8 @@ trait Jump $code = $msg; $msg = ''; } - $isAjax = Request::instance()->isAjax(); if (is_null($url)) { - $url = $isAjax ? '':'javascript:history.back(-1);'; + $url = Request::instance()->isAjax() ? '' : 'javascript:history.back(-1);'; } elseif ('' !== $url) { $url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : Url::build($url); } -- Gitee From 2061588c4909d1de8877020092a5c17d9c1f334f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 2 Dec 2016 19:12:49 +0800 Subject: [PATCH 0203/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BValidate=E7=B1=BB?= =?UTF-8?q?=E7=9A=84field=E5=B1=9E=E6=80=A7=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index ac2f1925..675af8f5 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -115,7 +115,7 @@ class Validate { $this->rule = array_merge($this->rule, $rules); $this->message = array_merge($this->message, $message); - $this->field = $field; + $this->field = array_merge($this->field, $field); } /** -- Gitee From 65f13177c2bdc1018aa6d72bd0652ec0b352b5a8 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 2 Dec 2016 22:14:57 +0800 Subject: [PATCH 0204/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E5=BC=95=E6=93=8E=E7=B1=BBparseTemplateFile=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Template.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/library/think/Template.php b/library/think/Template.php index 0c2265c0..74407d62 100644 --- a/library/think/Template.php +++ b/library/think/Template.php @@ -12,6 +12,7 @@ namespace think; use think\exception\TemplateNotFoundException; +use think\Request; /** * ThinkPHP分离出来的模板引擎 @@ -1061,14 +1062,18 @@ class Template { if ('' == pathinfo($template, PATHINFO_EXTENSION)) { if (strpos($template, '@')) { - // 跨模块调用模板 + list($module, $template) = explode('@', $template); + } + if (0 !== strpos($template, '/')) { $template = str_replace(['/', ':'], $this->config['view_depr'], $template); - $template = APP_PATH . str_replace('@', '/' . basename($this->config['view_path']) . '/', $template); + } + if ($this->config['view_base']) { + $module = isset($module) ? $module : Request::instance()->module(); + $path = $this->config['view_base'] . ($module ? $module . DS : ''); } else { - $template = str_replace(['/', ':'], $this->config['view_depr'], $template); - $template = $this->config['view_path'] . $template; + $path = $this->config['view_path']; } - $template .= '.' . ltrim($this->config['view_suffix'], '.'); + $template = $path . $template . '.' . ltrim($this->config['view_suffix'], '.'); } if (is_file($template)) { -- Gitee From 670b7d13a8e5373f2d96def6851bb768b2d677de Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 2 Dec 2016 22:24:28 +0800 Subject: [PATCH 0205/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Template.php | 1 + 1 file changed, 1 insertion(+) diff --git a/library/think/Template.php b/library/think/Template.php index 74407d62..944bf33d 100644 --- a/library/think/Template.php +++ b/library/think/Template.php @@ -26,6 +26,7 @@ class Template // 引擎配置 protected $config = [ 'view_path' => '', // 模板路径 + 'view_base' => '', 'view_suffix' => 'html', // 默认模板文件后缀 'view_depr' => DS, 'cache_suffix' => 'php', // 默认模板缓存后缀 -- Gitee From d11e4aea10cbe55a65d8d985be861404514e0d3f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 5 Dec 2016 08:42:08 +0800 Subject: [PATCH 0206/1170] =?UTF-8?q?=E5=85=B3=E8=81=94=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E6=9E=B6=E6=9E=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base.php | 2 +- library/think/Model.php | 127 ++- library/think/db/Query.php | 76 +- library/think/model/Relation.php | 838 +----------------- library/think/model/relation/BelongsTo.php | 171 ++++ .../think/model/relation/BelongsToMany.php | 330 +++++++ library/think/model/relation/HasMany.php | 251 ++++++ .../think/model/relation/HasManyThrough.php | 124 +++ library/think/model/relation/HasOne.php | 174 ++++ library/think/model/relation/MorphMany.php | 175 ++++ library/think/model/relation/MorphTo.php | 166 ++++ 11 files changed, 1481 insertions(+), 953 deletions(-) create mode 100644 library/think/model/relation/BelongsTo.php create mode 100644 library/think/model/relation/BelongsToMany.php create mode 100644 library/think/model/relation/HasMany.php create mode 100644 library/think/model/relation/HasManyThrough.php create mode 100644 library/think/model/relation/HasOne.php create mode 100644 library/think/model/relation/MorphMany.php create mode 100644 library/think/model/relation/MorphTo.php diff --git a/base.php b/base.php index 5bd1b405..dc43b26b 100644 --- a/base.php +++ b/base.php @@ -9,7 +9,7 @@ // | Author: liu21st // +---------------------------------------------------------------------- -define('THINK_VERSION', '5.0.3'); +define('THINK_VERSION', '5.0.4beta'); define('THINK_START_TIME', microtime(true)); define('THINK_START_MEM', memory_get_usage()); define('EXT', '.php'); diff --git a/library/think/Model.php b/library/think/Model.php index 0376f8d6..0a3a35f5 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -20,6 +20,13 @@ use think\Exception; use think\Exception\ValidateException; use think\Loader; use think\model\Relation; +use think\model\relation\BelongsTo; +use think\model\relation\BelongsToMany; +use think\model\relation\HasMany; +use think\model\relation\HasManyThrough; +use think\model\relation\HasOne; +use think\model\relation\MorphMany; +use think\model\relation\MorphTo; use think\paginator\Collection as PaginatorCollection; /** @@ -186,26 +193,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess return self::$links[$model]; } - /** - * 获取关联模型实例 - * @access protected - * @param string|array $relation 关联查询 - * @return Relation|Query - */ - protected function relation($relation = null) - { - if (!is_null($relation)) { - // 执行关联查询 - return $this->db()->relation($relation); - } - - // 获取关联对象实例 - if (is_null($this->relation)) { - $this->relation = new Relation($this); - } - return $this->relation; - } - /** * 初始化模型 * @access protected @@ -421,9 +408,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $value = $this->readTransform($value, $this->type[$name]); } elseif ($notFound) { $method = Loader::parseName($name, 1); - if (method_exists($this, $method) && !method_exists('\think\Model', $method)) { + if (method_exists($this, $method) && $this->$method() instanceof Relation) { // 不存在该字段 获取关联数据 - $value = $this->relation()->getRelation($method); + $value = $this->$method()->getRelation(); // 保存关联对象值 $this->data[$name] = $value; } else { @@ -1157,18 +1144,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess public static function has($relation, $operator = '>=', $count = 1, $id = '*') { $model = new static(); - $info = $model->$relation()->getRelationInfo(); - $table = $info['model']::getTable(); - switch ($info['type']) { - case Relation::HAS_MANY: - return $model->db()->alias('a') - ->join($table . ' b', 'a.' . $info['localKey'] . '=b.' . $info['foreignKey'], $info['joinType']) - ->group('b.' . $info['foreignKey']) - ->having('count(' . $id . ')' . $operator . $count); - case Relation::HAS_MANY_THROUGH: // TODO - default: - return $model; - } + return $model->$relation()->has($model, $operator, $count, $id); } /** @@ -1181,27 +1157,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess public static function hasWhere($relation, $where = []) { $model = new static(); - $info = $model->$relation()->getRelationInfo(); - switch ($info['type']) { - case Relation::HAS_ONE: - case Relation::HAS_MANY: - $table = $info['model']::getTable(); - if (is_array($where)) { - foreach ($where as $key => $val) { - if (false === strpos($key, '.')) { - $where['b.' . $key] = $val; - unset($where[$key]); - } - } - } - return $model->db()->alias('a') - ->field('a.*') - ->join($table . ' b', 'a.' . $info['localKey'] . '=b.' . $info['foreignKey'], $info['joinType']) - ->where($where); - case Relation::HAS_MANY_THROUGH: // TODO - default: - return $model; - } + return $model->$relation()->hasWhere($model, $where); } /** @@ -1232,9 +1188,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess if (is_string($relations)) { $relations = explode(',', $relations); } - $this->relation(); + foreach ($relations as $relation) { - $this->data[$relation] = $this->relation->getRelation($relation); + $this->data[$relation] = $this->$relation()->getRelation(); } return $this; } @@ -1246,9 +1202,21 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @param string $relation 关联名 * @return array */ - public function eagerlyResultSet($resultSet, $relation) - { - return $this->relation()->eagerlyResultSet($resultSet, $relation); + public function eagerlyResultSet(&$resultSet, $relation, $class = '') + { + $relations = is_string($relation) ? explode(',', $relation) : $relation; + foreach ($relations as $key => $relation) { + $subRelation = ''; + $closure = false; + if ($relation instanceof \Closure) { + $closure = $relation; + $relation = $key; + } + if (strpos($relation, '.')) { + list($relation, $subRelation) = explode('.', $relation); + } + $this->$relation()->eagerlyResultSet($resultSet, $relation, $subRelation, $closure, $class); + } } /** @@ -1258,9 +1226,22 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @param string $relation 关联名 * @return Model */ - public function eagerlyResult($result, $relation) + public function eagerlyResult(&$result, $relation, $class = '') { - return $this->relation()->eagerlyResult($result, $relation); + $relations = is_string($relation) ? explode(',', $relation) : $relation; + + foreach ($relations as $key => $relation) { + $subRelation = ''; + $closure = false; + if ($relation instanceof \Closure) { + $closure = $relation; + $relation = $key; + } + if (strpos($relation, '.')) { + list($relation, $subRelation) = explode('.', $relation); + } + $this->$relation()->eagerlyResult($result, $relation, $subRelation, $closure, $class); + } } /** @@ -1279,7 +1260,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $model = $this->parseModel($model); $localKey = $localKey ?: $this->getPk(); $foreignKey = $foreignKey ?: Loader::parseName($this->name) . '_id'; - return $this->relation()->hasOne($model, $foreignKey, $localKey, $alias, $joinType); + return new HasOne($this, $model, $foreignKey, $localKey, $alias, $joinType); } /** @@ -1298,7 +1279,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $model = $this->parseModel($model); $foreignKey = $foreignKey ?: Loader::parseName(basename(str_replace('\\', '/', $model))) . '_id'; $otherKey = $otherKey ?: (new $model)->getPk(); - return $this->relation()->belongsTo($model, $foreignKey, $otherKey, $alias, $joinType); + return new BelongsTo($this, $model, $foreignKey, $otherKey, $alias, $joinType); } /** @@ -1316,7 +1297,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $model = $this->parseModel($model); $localKey = $localKey ?: $this->getPk(); $foreignKey = $foreignKey ?: Loader::parseName($this->name) . '_id'; - return $this->relation()->hasMany($model, $foreignKey, $localKey, $alias); + return new HasMany($this, $model, $foreignKey, $localKey, $alias); } /** @@ -1339,7 +1320,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $foreignKey = $foreignKey ?: Loader::parseName($this->name) . '_id'; $name = Loader::parseName(basename(str_replace('\\', '/', $through))); $throughKey = $throughKey ?: $name . '_id'; - return $this->relation()->hasManyThrough($model, $through, $foreignKey, $throughKey, $localKey, $alias); + return new HasManyThrough($this, $model, $through, $foreignKey, $throughKey, $localKey, $alias); } /** @@ -1360,7 +1341,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $table = $table ?: $this->db()->getTable(Loader::parseName($this->name) . '_' . $name); $foreignKey = $foreignKey ?: $name . '_id'; $localKey = $localKey ?: Loader::parseName($this->name) . '_id'; - return $this->relation()->belongsToMany($model, $table, $foreignKey, $localKey, $alias); + return new BelongsToMany($this, $model, $table, $foreignKey, $localKey, $alias); } /** @@ -1371,18 +1352,22 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @param string $type 多态类型 * @return Relation */ - public function morphMany($model, $morph, $type = '') + public function morphMany($model, $morph = null, $type = '') { // 记录当前关联信息 $model = $this->parseModel($model); - $type = $type ?: Loader::parseName($this->name); + if (is_null($morph)) { + $trace = debug_backtrace(false, 2); + $morph = Loader::parseName($trace[1]['function']); + } + $type = $type ?: Loader::parseName($this->name); if (is_array($morph)) { list($morphType, $foreignKey) = $morph; } else { $morphType = $morph . '_type'; $foreignKey = $morph . '_id'; } - return $this->relation()->morphMany($model, $foreignKey, $morphType, $type); + return new MorphMany($this, $model, $foreignKey, $morphType, $type); } /** @@ -1405,7 +1390,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $morphType = $morph . '_type'; $foreignKey = $morph . '_id'; } - return $this->relation()->morphTo($morphType, $foreignKey, $alias); + return new MorphTo($this, $morphType, $foreignKey, $alias); } public function __call($method, $args) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 39ab03a9..b6ad8ff8 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -27,6 +27,8 @@ use think\exception\PDOException; use think\Loader; use think\Model; use think\model\Relation; +use think\model\relation\BelongsTo; +use think\model\relation\HasOne; use think\Paginator; class Query @@ -114,6 +116,16 @@ class Query return $this; } + /** + * 获取当前的模型对象名 + * @access public + * @return Connection + */ + public function getModel() + { + return $this->model; + } + /** * 指定默认的数据表名(不含前缀) * @access public @@ -976,6 +988,20 @@ class Query return $this; } + /** + * 去除某个查询参数 + * @access public + * @param string $option 参数名 + * @return $this + */ + public function removeOption($option) + { + if (isset($this->options[$option])) { + unset($this->options[$option]); + } + return $this; + } + /** * 指定查询数量 * @access public @@ -1601,13 +1627,14 @@ class Query $with = explode(',', $with); } - $i = 0; + $first = true; $currentModel = $this->model; /** @var Model $class */ $class = new $currentModel; foreach ($with as $key => $relation) { - $closure = false; + $subRelation = ''; + $closure = false; if ($relation instanceof \Closure) { // 支持闭包查询过滤关联条件 $closure = $relation; @@ -1620,48 +1647,9 @@ class Query /** @var Relation $model */ $model = $class->$relation(); - $info = $model->getRelationInfo(); - if (in_array($info['type'], [Relation::HAS_ONE, Relation::BELONGS_TO])) { - if (0 == $i) { - $name = Loader::parseName(basename(str_replace('\\', '/', $currentModel))); - $table = $this->getTable(); - $alias = isset($info['alias'][$name]) ? $info['alias'][$name] : $name; - $this->table([$table => $alias]); - if (isset($this->options['field'])) { - $field = $this->options['field']; - unset($this->options['field']); - } else { - $field = true; - } - $this->field($field, false, $table, $alias); - } - // 预载入封装 - $joinTable = $model->getTable(); - $joinName = Loader::parseName(basename(str_replace('\\', '/', $info['model']))); - $joinAlias = isset($info['alias'][$joinName]) ? $info['alias'][$joinName] : $relation; - $this->via($joinAlias); - - if (Relation::HAS_ONE == $info['type']) { - $this->join($joinTable . ' ' . $joinAlias, $alias . '.' . $info['localKey'] . '=' . $joinAlias . '.' . $info['foreignKey'], $info['joinType']); - } else { - $this->join($joinTable . ' ' . $joinAlias, $alias . '.' . $info['foreignKey'] . '=' . $joinAlias . '.' . $info['localKey'], $info['joinType']); - } - - if ($closure) { - // 执行闭包查询 - call_user_func_array($closure, [ & $this]); - //指定获取关联的字段 - //需要在 回调中 调方法 withField 方法,如 - // $query->where(['id'=>1])->withField('id,name'); - if (!empty($this->options['with_field'])) { - $field = $this->options['with_field']; - unset($this->options['with_field']); - } - } elseif (isset($info['option']['field'])) { - $field = $info['option']['field']; - } - $this->field($field, false, $joinTable, $joinAlias, $relation . '__'); - $i++; + if ($model instanceof HasOne || $model instanceof BelongsTo) { + $model->eagerly($this, $relation, $subRelation, $closure, $first); + $first = false; } elseif ($closure) { $with[$key] = $closure; } diff --git a/library/think/model/Relation.php b/library/think/model/Relation.php index fc420930..d7938836 100644 --- a/library/think/model/Relation.php +++ b/library/think/model/Relation.php @@ -11,34 +11,14 @@ namespace think\model; -use think\Db; -use think\Exception; -use think\Loader; -use think\Model; -use think\model\Pivot; - -class Relation +abstract class Relation { - const HAS_ONE = 1; - const HAS_MANY = 2; - const BELONGS_TO = 3; - const BELONGS_TO_MANY = 4; - const HAS_MANY_THROUGH = 5; - const MORPH_TO = 6; - const MORPH_MANY = 7; - // 父模型对象 protected $parent; /** @var Model 当前关联的模型类 */ protected $model; - // 中间表模型 - protected $middle; - // 当前关联类型 - protected $type; // 关联表外键 protected $foreignKey; - // 中间关联表外键 - protected $throughKey; // 关联表主键 protected $localKey; // 数据表别名 @@ -52,16 +32,6 @@ class Relation // 关联查询参数 protected $option; - /** - * 架构函数 - * @access public - * @param Model $model 上级模型对象 - */ - public function __construct(Model $model) - { - $this->parent = $model; - } - /** * 获取关联的所属模型 * @access public @@ -80,262 +50,6 @@ class Relation return $this->query; } - /** - * 解析模型的完整命名空间 - * @access public - * @param string $model 模型名(或者完整类名) - * @return string - */ - protected function parseModel($model) - { - if (isset($this->alias[$model])) { - $model = $this->alias[$model]; - } - if (false === strpos($model, '\\')) { - $path = explode('\\', get_class($this->parent)); - array_pop($path); - array_push($path, Loader::parseName($model, 1)); - $model = implode('\\', $path); - } - return $model; - } - - /** - * 获取当前关联信息 - * @access public - * @param string $name 关联信息 - * @return array|string|integer - */ - public function getRelationInfo($name = '') - { - $info = [ - 'type' => $this->type, - 'model' => $this->model, - 'middle' => $this->middle, - 'foreignKey' => $this->foreignKey, - 'localKey' => $this->localKey, - 'alias' => $this->alias, - 'joinType' => $this->joinType, - 'option' => $this->option, - ]; - return $name ? $info[$name] : $info; - } - - // 获取关联数据 - public function getRelation($name) - { - // 执行关联定义方法 - $relation = $this->parent->$name(); - $foreignKey = $this->foreignKey; - $localKey = $this->localKey; - $middle = $this->middle; - - // 判断关联类型执行查询 - switch ($this->type) { - case self::HAS_ONE: - $result = $relation->where($foreignKey, $this->parent->$localKey)->find(); - break; - case self::BELONGS_TO: - $result = $relation->where($localKey, $this->parent->$foreignKey)->find(); - break; - case self::HAS_MANY: - $result = $relation->select(); - break; - case self::HAS_MANY_THROUGH: - $result = $relation->select(); - break; - case self::BELONGS_TO_MANY: - // 关联查询 - $pk = $this->parent->getPk(); - $condition['pivot.' . $localKey] = $this->parent->$pk; - $result = $this->belongsToManyQuery($relation->getQuery(), $middle, $foreignKey, $localKey, $condition)->select(); - foreach ($result as $set) { - $pivot = []; - foreach ($set->getData() as $key => $val) { - if (strpos($key, '__')) { - list($name, $attr) = explode('__', $key, 2); - if ('pivot' == $name) { - $pivot[$attr] = $val; - unset($set->$key); - } - } - } - $set->pivot = new Pivot($pivot, $this->middle); - } - break; - case self::MORPH_MANY: - $result = $relation->select(); - break; - case self::MORPH_TO: - // 多态模型 - $model = $this->parseModel($this->parent->$middle); - // 主键数据 - $pk = $this->parent->$foreignKey; - $result = (new $model)->find($pk); - break; - default: - // 直接返回 - $result = $relation; - } - return $result; - } - - /** - * 预载入关联查询 返回数据集 - * @access public - * @param array $resultSet 数据集 - * @param string $relation 关联名 - * @param string $class 数据集对象名 为空表示数组 - * @return array - */ - public function eagerlyResultSet($resultSet, $relation, $class = '') - { - /** @var array $relations */ - $relations = is_string($relation) ? explode(',', $relation) : $relation; - - foreach ($relations as $key => $relation) { - $subRelation = ''; - $closure = false; - if ($relation instanceof \Closure) { - $closure = $relation; - $relation = $key; - } - if (strpos($relation, '.')) { - list($relation, $subRelation) = explode('.', $relation); - } - // 执行关联方法 - $model = $this->parent->$relation(); - // 获取关联信息 - $localKey = $this->localKey; - $foreignKey = $this->foreignKey; - $middle = $this->middle; - switch ($this->type) { - case self::HAS_ONE: - case self::BELONGS_TO: - foreach ($resultSet as $result) { - // 模型关联组装 - $this->match($this->model, $relation, $result); - } - break; - case self::HAS_MANY: - $range = []; - foreach ($resultSet as $result) { - // 获取关联外键列表 - if (isset($result->$localKey)) { - $range[] = $result->$localKey; - } - } - - if (!empty($range)) { - $this->where[$foreignKey] = ['in', $range]; - $data = $this->eagerlyOneToMany($model, [ - $foreignKey => [ - 'in', - $range, - ], - ], $relation, $subRelation, $closure); - - // 关联数据封装 - foreach ($resultSet as $result) { - if (!isset($data[$result->$localKey])) { - $data[$result->$localKey] = []; - } - $result->setAttr($relation, $this->resultSetBuild($data[$result->$localKey], $class)); - } - } - break; - case self::BELONGS_TO_MANY: - $pk = $resultSet[0]->getPk(); - $range = []; - foreach ($resultSet as $result) { - // 获取关联外键列表 - if (isset($result->$pk)) { - $range[] = $result->$pk; - } - } - - if (!empty($range)) { - // 查询关联数据 - $data = $this->eagerlyManyToMany($model, [ - 'pivot.' . $localKey => [ - 'in', - $range, - ], - ], $relation, $subRelation); - - // 关联数据封装 - foreach ($resultSet as $result) { - if (!isset($data[$result->$pk])) { - $data[$result->$pk] = []; - } - - $result->setAttr($relation, $this->resultSetBuild($data[$result->$pk], $class)); - } - } - break; - case self::MORPH_MANY: - $range = []; - foreach ($resultSet as $result) { - $pk = $result->getPk(); - // 获取关联外键列表 - if (isset($result->$pk)) { - $range[] = $result->$pk; - } - } - - if (!empty($range)) { - $this->where[$foreignKey] = ['in', $range]; - $this->where[$localKey] = $middle; - $data = $this->eagerlyMorphToMany($model, [ - $foreignKey => ['in', $range], - $localKey => $middle, - ], $relation, $subRelation, $closure); - - // 关联数据封装 - foreach ($resultSet as $result) { - if (!isset($data[$result->$pk])) { - $data[$result->$pk] = []; - } - $result->setAttr($relation, $this->resultSetBuild($data[$result->$pk], $class)); - } - } - break; - case self::MORPH_TO: - $range = []; - foreach ($resultSet as $result) { - // 获取关联外键列表 - if (!empty($result->$foreignKey)) { - $range[$result->$middle][] = $result->$foreignKey; - } - } - - if (!empty($range)) { - foreach ($range as $key => $val) { - // 多态类型映射 - $model = $this->parseModel($key); - $obj = new $model; - $pk = $obj->getPk(); - $list = $obj->all($val, $subRelation); - $data = []; - foreach ($list as $k => $vo) { - $data[$vo->$pk] = $vo; - } - foreach ($resultSet as $result) { - if ($key == $result->$middle) { - if (!isset($data[$result->$foreignKey])) { - $data[$result->$foreignKey] = []; - } - $result->setAttr($relation, $this->resultSetBuild($data[$result->$foreignKey], $class)); - } - } - } - } - break; - } - } - return $resultSet; - } - /** * 封装关联数据集 * @access public @@ -348,212 +62,6 @@ class Relation return $class ? new $class($resultSet) : $resultSet; } - /** - * 预载入关联查询 返回模型对象 - * @access public - * @param Model $result 数据对象 - * @param string $relation 关联名 - * @param string $class 数据集对象名 为空表示数组 - * @return Model - */ - public function eagerlyResult($result, $relation, $class = '') - { - $relations = is_string($relation) ? explode(',', $relation) : $relation; - - foreach ($relations as $key => $relation) { - $subRelation = ''; - $closure = false; - if ($relation instanceof \Closure) { - $closure = $relation; - $relation = $key; - } - if (strpos($relation, '.')) { - list($relation, $subRelation) = explode('.', $relation); - } - // 执行关联方法 - $model = $this->parent->$relation(); - $localKey = $this->localKey; - $foreignKey = $this->foreignKey; - $middle = $this->middle; - switch ($this->type) { - case self::HAS_ONE: - case self::BELONGS_TO: - // 模型关联组装 - $this->match($this->model, $relation, $result); - break; - case self::HAS_MANY: - if (isset($result->$localKey)) { - $data = $this->eagerlyOneToMany($model, [$foreignKey => $result->$localKey], $relation, $subRelation, $closure); - // 关联数据封装 - if (!isset($data[$result->$localKey])) { - $data[$result->$localKey] = []; - } - $result->setAttr($relation, $this->resultSetBuild($data[$result->$localKey], $class)); - } - break; - case self::BELONGS_TO_MANY: - $pk = $result->getPk(); - if (isset($result->$pk)) { - $pk = $result->$pk; - // 查询管理数据 - $data = $this->eagerlyManyToMany($model, ['pivot.' . $localKey => $pk], $relation, $subRelation); - - // 关联数据封装 - if (!isset($data[$pk])) { - $data[$pk] = []; - } - $result->setAttr($relation, $this->resultSetBuild($data[$pk], $class)); - } - break; - case self::MORPH_MANY: - $pk = $result->getPk(); - if (isset($result->$pk)) { - $data = $this->eagerlyMorphToMany($model, [$foreignKey => $result->$pk, $localKey => $middle], $relation, $subRelation, $closure); - $result->setAttr($relation, $this->resultSetBuild($data[$result->$pk], $class)); - } - break; - case self::MORPH_TO: - // 多态类型映射 - $model = $this->parseModel($result->{$this->middle}); - $this->eagerlyMorphToOne($model, $relation, $result, $subRelation); - break; - - } - } - return $result; - } - - /** - * 一对一 关联模型预查询拼装 - * @access public - * @param string $model 模型名称 - * @param string $relation 关联名 - * @param Model $result 模型对象实例 - * @return void - */ - protected function match($model, $relation, &$result) - { - // 重新组装模型数据 - foreach ($result->getData() as $key => $val) { - if (strpos($key, '__')) { - list($name, $attr) = explode('__', $key, 2); - if ($name == $relation) { - $list[$name][$attr] = $val; - unset($result->$key); - } - } - } - - $result->setAttr($relation, !isset($list[$relation]) ? null : (new $model($list[$relation]))->isUpdate(true)); - } - - /** - * 一对多 关联模型预查询 - * @access public - * @param object $model 关联模型对象 - * @param array $where 关联预查询条件 - * @param string $relation 关联名 - * @param string $subRelation 子关联 - * @param bool $closure - * @return array - */ - protected function eagerlyOneToMany($model, $where, $relation, $subRelation = '', $closure = false) - { - $foreignKey = $this->foreignKey; - // 预载入关联查询 支持嵌套预载入 - if ($closure) { - call_user_func_array($closure, [ & $model]); - } - $list = $model->where($where)->with($subRelation)->select(); - - // 组装模型数据 - $data = []; - foreach ($list as $set) { - $data[$set->$foreignKey][] = $set; - } - return $data; - } - - /** - * 多对多 关联模型预查询 - * @access public - * @param object $model 关联模型对象 - * @param array $where 关联预查询条件 - * @param string $relation 关联名 - * @param string $subRelation 子关联 - * @return array - */ - protected function eagerlyManyToMany($model, $where, $relation, $subRelation = '') - { - $foreignKey = $this->foreignKey; - $localKey = $this->localKey; - // 预载入关联查询 支持嵌套预载入 - $list = $this->belongsToManyQuery($model->getQuery(), $this->middle, $foreignKey, $localKey, $where)->with($subRelation)->select(); - - // 组装模型数据 - $data = []; - foreach ($list as $set) { - $pivot = []; - foreach ($set->getData() as $key => $val) { - if (strpos($key, '__')) { - list($name, $attr) = explode('__', $key, 2); - if ('pivot' == $name) { - $pivot[$attr] = $val; - unset($set->$key); - } - } - } - $set->pivot = new Pivot($pivot, $this->middle); - $data[$pivot[$localKey]][] = $set; - } - return $data; - } - - /** - * 多态MorphTo 关联模型预查询 - * @access public - * @param object $model 关联模型对象 - * @param array $where 关联预查询条件 - * @param string $relation 关联名 - * @param string $subRelation 子关联 - * @return array - */ - protected function eagerlyMorphToOne($model, $relation, &$result, $subRelation = '') - { - // 预载入关联查询 支持嵌套预载入 - $pk = $this->parent->{$this->foreignKey}; - $data = (new $model)->with($subRelation)->find($pk); - if ($data) { - $data->isUpdate(true); - } - $result->setAttr($relation, $data ?: null); - } - - /** - * 多态一对多 关联模型预查询 - * @access public - * @param object $model 关联模型对象 - * @param array $where 关联预查询条件 - * @param string $relation 关联名 - * @param string $subRelation 子关联 - * @return array - */ - protected function eagerlyMorphToMany($model, $where, $relation, $subRelation = '', $closure = false) - { - // 预载入关联查询 支持嵌套预载入 - if ($closure) { - call_user_func_array($closure, [ & $model]); - } - $list = $model->getQuery()->where($where)->with($subRelation)->select(); - $foreignKey = $this->foreignKey; - // 组装模型数据 - $data = []; - foreach ($list as $set) { - $data[$set->$foreignKey][] = $set; - } - return $data; - } - /** * 设置当前关联定义的数据表别名 * @access public @@ -566,363 +74,19 @@ class Relation return $this; } - /** - * HAS ONE 关联定义 - * @access public - * @param string $model 模型名 - * @param string $foreignKey 关联外键 - * @param string $localKey 关联主键 - * @param array $alias 别名定义 - * @param string $joinType JOIN类型 - * @return $this - */ - public function hasOne($model, $foreignKey, $localKey, $alias = [], $joinType = 'INNER') - { - $this->type = self::HAS_ONE; - $this->model = $model; - $this->foreignKey = $foreignKey; - $this->localKey = $localKey; - $this->alias = $alias; - $this->joinType = $joinType; - $this->query = (new $model)->db(); - // 返回关联的模型对象 - return $this; - } - - /** - * BELONGS TO 关联定义 - * @access public - * @param string $model 模型名 - * @param string $foreignKey 关联外键 - * @param string $otherKey 关联主键 - * @param array $alias 别名定义 - * @param string $joinType JOIN类型 - * @return $this - */ - public function belongsTo($model, $foreignKey, $otherKey, $alias = [], $joinType = 'INNER') - { - // 记录当前关联信息 - $this->type = self::BELONGS_TO; - $this->model = $model; - $this->foreignKey = $foreignKey; - $this->localKey = $otherKey; - $this->alias = $alias; - $this->joinType = $joinType; - $this->query = (new $model)->db(); - // 返回关联的模型对象 - return $this; - } - - /** - * HAS MANY 关联定义 - * @access public - * @param string $model 模型名 - * @param string $foreignKey 关联外键 - * @param string $localKey 关联主键 - * @param array $alias 别名定义 - * @return $this - */ - public function hasMany($model, $foreignKey, $localKey, $alias) - { - // 记录当前关联信息 - $this->type = self::HAS_MANY; - $this->model = $model; - $this->foreignKey = $foreignKey; - $this->localKey = $localKey; - $this->alias = $alias; - $this->query = (new $model)->db(); - // 返回关联的模型对象 - return $this; - } - - /** - * HAS MANY 远程关联定义 - * @access public - * @param string $model 模型名 - * @param string $through 中间模型名 - * @param string $firstkey 关联外键 - * @param string $secondKey 关联外键 - * @param string $localKey 关联主键 - * @param array $alias 别名定义 - * @return $this - */ - public function hasManyThrough($model, $through, $foreignKey, $throughKey, $localKey, $alias) - { - // 记录当前关联信息 - $this->type = self::HAS_MANY_THROUGH; - $this->model = $model; - $this->middle = $through; - $this->foreignKey = $foreignKey; - $this->throughKey = $throughKey; - $this->localKey = $localKey; - $this->alias = $alias; - $this->query = (new $model)->db(); - // 返回关联的模型对象 - return $this; - } - - /** - * BELONGS TO MANY 关联定义 - * @access public - * @param string $model 模型名 - * @param string $table 中间表名 - * @param string $foreignKey 关联模型外键 - * @param string $localKey 当前模型关联键 - * @param array $alias 别名定义 - * @return $this - */ - public function belongsToMany($model, $table, $foreignKey, $localKey, $alias) - { - // 记录当前关联信息 - $this->type = self::BELONGS_TO_MANY; - $this->model = $model; - $this->foreignKey = $foreignKey; - $this->localKey = $localKey; - $this->middle = $table; - $this->alias = $alias; - $this->query = (new $model)->db(); - // 返回关联的模型对象 - return $this; - } - - /** - * MORPH_MANY 关联定义 - * @access public - * @param string $model 模型名 - * @param string $id 关联外键 - * @param string $morphType 多态字段名 - * @param string $type 多态类型 - * @return $this - */ - public function morphMany($model, $foreignKey, $morphType, $type) - { - // 记录当前关联信息 - $this->type = self::MORPH_MANY; - $this->model = $model; - $this->middle = $type; - $this->foreignKey = $foreignKey; - $this->localKey = $morphType; - $this->query = (new $model)->db(); - // 返回关联的模型对象 - return $this; - } - - /** - * MORPH_TO 关联定义 - * @access public - * @param string $morphType 多态字段名 - * @param string $foreignKey 外键名 - * @param array $alias 多态别名定义 - * @return $this - */ - public function morphTo($morphType, $foreignKey, $alias) - { - // 记录当前关联信息 - $this->type = self::MORPH_TO; - $this->middle = $morphType; - $this->foreignKey = $foreignKey; - $this->alias = $alias; - // 返回关联的模型对象 - return $this; - } - - /** - * BELONGS TO MANY 关联查询 - * @access public - * @param object $model 关联模型对象 - * @param string $table 中间表名 - * @param string $foreignKey 关联模型关联键 - * @param string $localKey 当前模型关联键 - * @param array $condition 关联查询条件 - * @return \think\db\Query|string - */ - protected function belongsToManyQuery($model, $table, $foreignKey, $localKey, $condition = []) - { - // 关联查询封装 - $tableName = $model->getTable(); - $relationFk = $model->getPk(); - return $model->field($tableName . '.*') - ->field(true, false, $table, 'pivot', 'pivot__') - ->join($table . ' pivot', 'pivot.' . $foreignKey . '=' . $tableName . '.' . $relationFk) - ->where($condition); - } - - /** - * 保存(新增)当前关联数据对象 - * @access public - * @param mixed $data 数据 可以使用数组 关联模型对象 和 关联对象的主键 - * @param array $pivot 中间表额外数据 - * @return integer - */ - public function save($data, array $pivot = []) - { - // 判断关联类型 - switch ($this->type) { - case self::HAS_ONE: - case self::BELONGS_TO: - case self::HAS_MANY: - if ($data instanceof Model) { - $data = $data->getData(); - } - // 保存关联表数据 - $data[$this->foreignKey] = $this->parent->{$this->localKey}; - $model = new $this->model; - return $model->save($data); - case self::BELONGS_TO_MANY: - // 保存关联表/中间表数据 - return $this->attach($data, $pivot); - } - } - - /** - * 批量保存当前关联数据对象 - * @access public - * @param array $dataSet 数据集 - * @param array $pivot 中间表额外数据 - * @return integer - */ - public function saveAll(array $dataSet, array $pivot = []) - { - $result = false; - foreach ($dataSet as $key => $data) { - // 判断关联类型 - switch ($this->type) { - case self::HAS_MANY: - $data[$this->foreignKey] = $this->parent->{$this->localKey}; - $result = $this->save($data); - break; - case self::BELONGS_TO_MANY: - // TODO - $result = $this->attach($data, !empty($pivot) ? $pivot[$key] : []); - break; - } - } - return $result; - } - - /** - * 附加关联的一个中间表数据 - * @access public - * @param mixed $data 数据 可以使用数组、关联模型对象 或者 关联对象的主键 - * @param array $pivot 中间表额外数据 - * @return integer - */ - public function attach($data, $pivot = []) - { - if (is_array($data)) { - // 保存关联表数据 - $model = new $this->model; - $model->save($data); - $id = $model->getLastInsID(); - } elseif (is_numeric($data) || is_string($data)) { - // 根据关联表主键直接写入中间表 - $id = $data; - } elseif ($data instanceof Model) { - // 根据关联表主键直接写入中间表 - $relationFk = $data->getPk(); - $id = $data->$relationFk; - } - - if ($id) { - // 保存中间表数据 - $pk = $this->parent->getPk(); - $pivot[$this->localKey] = $this->parent->$pk; - $pivot[$this->foreignKey] = $id; - $query = clone $this->parent->db(); - return $query->table($this->middle)->insert($pivot); - } else { - throw new Exception('miss relation data'); - } - } - - /** - * 解除关联的一个中间表数据 - * @access public - * @param integer|array $data 数据 可以使用关联对象的主键 - * @param bool $relationDel 是否同时删除关联表数据 - * @return integer - */ - public function detach($data, $relationDel = false) - { - if (is_array($data)) { - $id = $data; - } elseif (is_numeric($data) || is_string($data)) { - // 根据关联表主键直接写入中间表 - $id = $data; - } elseif ($data instanceof Model) { - // 根据关联表主键直接写入中间表 - $relationFk = $data->getPk(); - $id = $data->$relationFk; - } - // 删除中间表数据 - $pk = $this->parent->getPk(); - $pivot[$this->localKey] = $this->parent->$pk; - if (isset($id)) { - $pivot[$this->foreignKey] = is_array($id) ? ['in', $id] : $id; - } - $query = clone $this->parent->db(); - $query->table($this->middle)->where($pivot)->delete(); - - // 删除关联表数据 - if (isset($id) && $relationDel) { - $model = $this->model; - $model::destroy($id); - } - } - public function __call($method, $args) { - static $baseQuery = []; if ($this->query) { - if (empty($baseQuery[$this->type])) { - $baseQuery[$this->type] = true; - switch ($this->type) { - case self::HAS_MANY: - if (isset($this->where)) { - $this->query->where($this->where); - } elseif (isset($this->parent->{$this->localKey})) { - // 关联查询带入关联条件 - $this->query->where($this->foreignKey, $this->parent->{$this->localKey}); - } - break; - case self::HAS_MANY_THROUGH: - $through = $this->middle; - $model = $this->model; - $alias = Loader::parseName(basename(str_replace('\\', '/', $model))); - $throughTable = $through::getTable(); - $pk = (new $this->model)->getPk(); - $throughKey = $this->throughKey; - $modelTable = $this->parent->getTable(); - $this->query->field($alias . '.*')->alias($alias) - ->join($throughTable, $throughTable . '.' . $pk . '=' . $alias . '.' . $throughKey) - ->join($modelTable, $modelTable . '.' . $this->localKey . '=' . $throughTable . '.' . $this->foreignKey) - ->where($throughTable . '.' . $this->foreignKey, $this->parent->{$this->localKey}); - break; - case self::BELONGS_TO_MANY: - $pk = $this->parent->getPk(); - $this->query->join($this->middle . ' pivot', 'pivot.' . $this->foreignKey . '=' . $this->query->getTable() . '.' . $this->query->getPk())->where('pivot.' . $this->localKey, $this->parent->$pk); - break; - case self::MORPH_MANY: - $pk = $this->parent->getPk(); - $map[$this->foreignKey] = $this->parent->$pk; - $map[$this->localKey] = $this->middle; - $this->query->where($map); - break; - } - } - $result = call_user_func_array([$this->query, $method], $args); if ($result instanceof \think\db\Query) { $this->option = $result->getOptions(); return $this; } else { $this->option = []; - $baseQuery = false; return $result; } } else { throw new Exception('method not exists:' . __CLASS__ . '->' . $method); } } - } diff --git a/library/think/model/relation/BelongsTo.php b/library/think/model/relation/BelongsTo.php new file mode 100644 index 00000000..ae5c400e --- /dev/null +++ b/library/think/model/relation/BelongsTo.php @@ -0,0 +1,171 @@ + +// +---------------------------------------------------------------------- + +namespace think\model\relation; + +use think\Db; +use think\db\Query; +use think\Loader; +use think\Model; +use think\model\Relation; + +class BelongsTo extends Relation +{ + /** + * 架构函数 + * @access public + * @param Model $parent 上级模型对象 + * @param string $model 模型名 + * @param string $foreignKey 关联外键 + * @param string $otherKey 关联主键 + * @param array $alias 别名定义 + * @param string $joinType JOIN类型 + */ + public function __construct(Model $parent, $model, $foreignKey, $localKey, $alias = [], $joinType = 'INNER') + { + $this->parent = $parent; + $this->model = $model; + $this->foreignKey = $foreignKey; + $this->localKey = $localKey; + $this->alias = $alias; + $this->joinType = $joinType; + $this->query = (new $model)->db(); + } + + // 动态获取关联数据 + public function getRelation() + { + $foreignKey = $this->foreignKey; + $localKey = $this->localKey; + return $this->query->where($localKey, $this->parent->$foreignKey)->find(); + } + + /** + * 预载入关联查询 + * @access public + * @param Query $query 查询对象 + * @param string $relation 关联名 + * @return void + */ + public function eagerly(Query $query, $relation, $subRelation, $closure, $first) + { + $name = Loader::parseName(basename(str_replace('\\', '/', $query->getModel()))); + $alias = isset($this->alias[$name]) ? $this->alias[$name] : $name; + if ($first) { + + $table = $query->getTable(); + $query->table([$table => $alias]); + if ($query->getOptions('field')) { + $field = $query->getOptions('field'); + $query->removeOption('field'); + } else { + $field = true; + } + $query->field($field, false, $table, $alias); + } + + // 预载入封装 + $joinTable = $this->query->getTable(); + $joinName = Loader::parseName(basename(str_replace('\\', '/', $this->model))); + $joinAlias = isset($this->alias[$joinName]) ? $this->alias[$joinName] : $relation; + $query->via($joinAlias); + + $query->join($joinTable . ' ' . $joinAlias, $alias . '.' . $this->foreignKey . '=' . $joinAlias . '.' . $this->localKey, $this->joinType); + + if ($closure) { + // 执行闭包查询 + call_user_func_array($closure, [ & $query]); + //指定获取关联的字段 + //需要在 回调中 调方法 withField 方法,如 + // $query->where(['id'=>1])->withField('id,name'); + if ($query->getOptions('with_field')) { + $field = $query->getOptions('with_field'); + $query->removeOption('with_field'); + } + } elseif (isset($this->option['field'])) { + $field = $this->option['field']; + } else { + $field = true; + } + $query->field($field, false, $joinTable, $joinAlias, $relation . '__'); + } + + /** + * 预载入关联查询 返回数据集 + * @access public + * @param array $resultSet 数据集 + * @param string $relation 关联名 + * @param string $class 数据集对象名 为空表示数组 + * @return array + */ + public function eagerlyResultSet(&$resultSet, $relation) + { + foreach ($resultSet as $result) { + // 模型关联组装 + $this->match($this->model, $relation, $result); + } + } + + /** + * 预载入关联查询 返回模型对象 + * @access public + * @param Model $result 数据对象 + * @param string $relation 关联名 + * @param string $class 数据集对象名 为空表示数组 + * @return Model + */ + public function eagerlyResult(&$result, $relation) + { + // 模型关联组装 + $this->match($this->model, $relation, $result); + } + + /** + * 一对一 关联模型预查询拼装 + * @access public + * @param string $model 模型名称 + * @param string $relation 关联名 + * @param Model $result 模型对象实例 + * @return void + */ + protected function match($model, $relation, &$result) + { + // 重新组装模型数据 + foreach ($result->getData() as $key => $val) { + if (strpos($key, '__')) { + list($name, $attr) = explode('__', $key, 2); + if ($name == $relation) { + $list[$name][$attr] = $val; + unset($result->$key); + } + } + } + + $result->setAttr($relation, !isset($list[$relation]) ? null : (new $model($list[$relation]))->isUpdate(true)); + } + + /** + * 保存(新增)当前关联数据对象 + * @access public + * @param mixed $data 数据 可以使用数组 关联模型对象 和 关联对象的主键 + * @return integer + */ + public function save($data) + { + if ($data instanceof Model) { + $data = $data->getData(); + } + // 保存关联表数据 + $data[$this->foreignKey] = $this->parent->{$this->localKey}; + $model = new $this->model; + return $model->save($data); + } +} diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php new file mode 100644 index 00000000..59220aee --- /dev/null +++ b/library/think/model/relation/BelongsToMany.php @@ -0,0 +1,330 @@ + +// +---------------------------------------------------------------------- + +namespace think\model\relation; + +use think\Db; +use think\db\Query; +use think\Model; +use think\model\Pivot; +use think\model\Relation; + +class BelongsToMany extends Relation +{ + // 中间表模型 + protected $middle; + + /** + * 架构函数 + * @access public + * @param Model $parent 上级模型对象 + * @param string $model 模型名 + * @param string $table 中间表名 + * @param string $foreignKey 关联模型外键 + * @param string $localKey 当前模型关联键 + * @param array $alias 别名定义 + */ + public function __construct(Model $parent, $model, $table, $foreignKey, $localKey, $alias = []) + { + $this->parent = $parent; + $this->model = $model; + $this->foreignKey = $foreignKey; + $this->localKey = $localKey; + $this->middle = $table; + $this->alias = $alias; + $this->query = (new $model)->db(); + } + + // 动态获取关联数据 + public function getRelation() + { + $foreignKey = $this->foreignKey; + $localKey = $this->localKey; + $middle = $this->middle; + // 关联查询 + $pk = $this->parent->getPk(); + $condition['pivot.' . $localKey] = $this->parent->$pk; + $result = $this->belongsToManyQuery($middle, $foreignKey, $localKey, $condition)->select(); + foreach ($result as $set) { + $pivot = []; + foreach ($set->getData() as $key => $val) { + if (strpos($key, '__')) { + list($name, $attr) = explode('__', $key, 2); + if ('pivot' == $name) { + $pivot[$attr] = $val; + unset($set->$key); + } + } + } + $set->pivot = new Pivot($pivot, $this->middle); + } + return $result; + } + + /** + * 预载入关联查询 + * @access public + * @param Query $query 查询对象 + * @param string $relation 关联名 + * @param bool $first 是否需要使用基础表 + * @return void + */ + public function eagerly(Query $query, $relation, $subRelation, $closure, $first) + { + + } + + /** + * 预载入关联查询 返回数据集 + * @access public + * @param array $resultSet 数据集 + * @param string $relation 关联名 + * @param string $class 数据集对象名 为空表示数组 + * @return array + */ + public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class) + { + $localKey = $this->localKey; + $foreignKey = $this->foreignKey; + + $pk = $resultSet[0]->getPk(); + $range = []; + foreach ($resultSet as $result) { + // 获取关联外键列表 + if (isset($result->$pk)) { + $range[] = $result->$pk; + } + } + + if (!empty($range)) { + // 查询关联数据 + $data = $this->eagerlyManyToMany([ + 'pivot.' . $localKey => [ + 'in', + $range, + ], + ], $relation, $subRelation); + + // 关联数据封装 + foreach ($resultSet as $result) { + if (!isset($data[$result->$pk])) { + $data[$result->$pk] = []; + } + + $result->setAttr($relation, $this->resultSetBuild($data[$result->$pk], $class)); + } + } + } + + /** + * 预载入关联查询 返回模型对象 + * @access public + * @param Model $result 数据对象 + * @param string $relation 关联名 + * @param string $class 数据集对象名 为空表示数组 + * @return Model + */ + public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class) + { + $localKey = $this->localKey; + $foreignKey = $this->foreignKey; + + $pk = $result->getPk(); + if (isset($result->$pk)) { + $pk = $result->$pk; + // 查询管理数据 + $data = $this->eagerlyManyToMany(['pivot.' . $localKey => $pk], $relation, $subRelation); + + // 关联数据封装 + if (!isset($data[$pk])) { + $data[$pk] = []; + } + $result->setAttr($relation, $this->resultSetBuild($data[$pk], $class)); + } + } + + /** + * 多对多 关联模型预查询 + * @access public + * @param array $where 关联预查询条件 + * @param string $relation 关联名 + * @param string $subRelation 子关联 + * @return array + */ + protected function eagerlyManyToMany($where, $relation, $subRelation = '') + { + $foreignKey = $this->foreignKey; + $localKey = $this->localKey; + // 预载入关联查询 支持嵌套预载入 + $list = $this->belongsToManyQuery($this->middle, $foreignKey, $localKey, $where)->with($subRelation)->select(); + + // 组装模型数据 + $data = []; + foreach ($list as $set) { + $pivot = []; + foreach ($set->getData() as $key => $val) { + if (strpos($key, '__')) { + list($name, $attr) = explode('__', $key, 2); + if ('pivot' == $name) { + $pivot[$attr] = $val; + unset($set->$key); + } + } + } + $set->pivot = new Pivot($pivot, $this->middle); + $data[$pivot[$localKey]][] = $set; + } + return $data; + } + + /** + * BELONGS TO MANY 关联查询 + * @access public + * @param string $table 中间表名 + * @param string $foreignKey 关联模型关联键 + * @param string $localKey 当前模型关联键 + * @param array $condition 关联查询条件 + * @return \think\db\Query|string + */ + protected function belongsToManyQuery($table, $foreignKey, $localKey, $condition = []) + { + // 关联查询封装 + $tableName = $this->query->getTable(); + $relationFk = $this->query->getPk(); + return $this->query->field($tableName . '.*') + ->field(true, false, $table, 'pivot', 'pivot__') + ->join($table . ' pivot', 'pivot.' . $foreignKey . '=' . $tableName . '.' . $relationFk) + ->where($condition); + } + + /** + * 保存(新增)当前关联数据对象 + * @access public + * @param mixed $data 数据 可以使用数组 关联模型对象 和 关联对象的主键 + * @param array $pivot 中间表额外数据 + * @return integer + */ + public function save($data, array $pivot = []) + { + // 保存关联表/中间表数据 + return $this->attach($data, $pivot); + } + + /** + * 批量保存当前关联数据对象 + * @access public + * @param array $dataSet 数据集 + * @param array $pivot 中间表额外数据 + * @return integer + */ + public function saveAll(array $dataSet, array $pivot = []) + { + $result = false; + foreach ($dataSet as $key => $data) { + $result = $this->attach($data, !empty($pivot) ? $pivot[$key] : []); + } + return $result; + } + + /** + * 附加关联的一个中间表数据 + * @access public + * @param mixed $data 数据 可以使用数组、关联模型对象 或者 关联对象的主键 + * @param array $pivot 中间表额外数据 + * @return integer + */ + public function attach($data, $pivot = []) + { + if (is_array($data)) { + // 保存关联表数据 + $model = new $this->model; + $model->save($data); + $id = $model->getLastInsID(); + } elseif (is_numeric($data) || is_string($data)) { + // 根据关联表主键直接写入中间表 + $id = $data; + } elseif ($data instanceof Model) { + // 根据关联表主键直接写入中间表 + $relationFk = $data->getPk(); + $id = $data->$relationFk; + } + + if ($id) { + // 保存中间表数据 + $pk = $this->parent->getPk(); + $pivot[$this->localKey] = $this->parent->$pk; + $pivot[$this->foreignKey] = $id; + $query = clone $this->parent->db(); + return $query->table($this->middle)->insert($pivot); + } else { + throw new Exception('miss relation data'); + } + } + + /** + * 解除关联的一个中间表数据 + * @access public + * @param integer|array $data 数据 可以使用关联对象的主键 + * @param bool $relationDel 是否同时删除关联表数据 + * @return integer + */ + public function detach($data, $relationDel = false) + { + if (is_array($data)) { + $id = $data; + } elseif (is_numeric($data) || is_string($data)) { + // 根据关联表主键直接写入中间表 + $id = $data; + } elseif ($data instanceof Model) { + // 根据关联表主键直接写入中间表 + $relationFk = $data->getPk(); + $id = $data->$relationFk; + } + // 删除中间表数据 + $pk = $this->parent->getPk(); + $pivot[$this->localKey] = $this->parent->$pk; + if (isset($id)) { + $pivot[$this->foreignKey] = is_array($id) ? ['in', $id] : $id; + } + $query = clone $this->parent->db(); + $query->table($this->middle)->where($pivot)->delete(); + + // 删除关联表数据 + if (isset($id) && $relationDel) { + $model = $this->model; + $model::destroy($id); + } + } + + public function __call($method, $args) + { + static $baseQuery = false; + if ($this->query) { + if (empty($baseQuery)) { + $baseQuery = true; + $pk = $this->parent->getPk(); + $this->query->join($this->middle . ' pivot', 'pivot.' . $this->foreignKey . '=' . $this->query->getTable() . '.' . $this->query->getPk())->where('pivot.' . $this->localKey, $this->parent->$pk); + } + + $result = call_user_func_array([$this->query, $method], $args); + if ($result instanceof \think\db\Query) { + $this->option = $result->getOptions(); + return $this; + } else { + $this->option = []; + $baseQuery = false; + return $result; + } + } else { + throw new Exception('method not exists:' . __CLASS__ . '->' . $method); + } + } +} diff --git a/library/think/model/relation/HasMany.php b/library/think/model/relation/HasMany.php new file mode 100644 index 00000000..5c7d129a --- /dev/null +++ b/library/think/model/relation/HasMany.php @@ -0,0 +1,251 @@ + +// +---------------------------------------------------------------------- + +namespace think\model\relation; + +use think\Db; +use think\db\Query; +use think\Model; +use think\model\Relation; + +class HasMany extends Relation +{ + /** + * 架构函数 + * @access public + * @param Model $parent 上级模型对象 + * @param string $model 模型名 + * @param string $foreignKey 关联外键 + * @param string $localKey 关联主键 + * @param array $alias 别名定义 + */ + public function __construct(Model $parent, $model, $foreignKey, $localKey, $alias = []) + { + $this->parent = $parent; + $this->model = $model; + $this->foreignKey = $foreignKey; + $this->localKey = $localKey; + $this->alias = $alias; + $this->query = (new $model)->db(); + } + + // 动态获取关联数据 + public function getRelation() + { + return $this->select(); + } + + /** + * 预载入关联查询 + * @access public + * @param Query $query 查询对象 + * @param string $relation 关联名 + * @param bool $first 是否需要使用基础表 + * @return void + */ + public function eagerly(Query $query, $relation, $subRelation, $closure, $first) + { + + } + + /** + * 预载入关联查询 返回数据集 + * @access public + * @param array $resultSet 数据集 + * @param string $relation 关联名 + * @param string $class 数据集对象名 为空表示数组 + * @return array + */ + public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class) + { + $localKey = $this->localKey; + $foreignKey = $this->foreignKey; + + $range = []; + foreach ($resultSet as $result) { + // 获取关联外键列表 + if (isset($result->$localKey)) { + $range[] = $result->$localKey; + } + } + + if (!empty($range)) { + $this->where[$foreignKey] = ['in', $range]; + $data = $this->eagerlyOneToMany($this, [ + $foreignKey => [ + 'in', + $range, + ], + ], $relation, $subRelation, $closure); + + // 关联数据封装 + foreach ($resultSet as $result) { + if (!isset($data[$result->$localKey])) { + $data[$result->$localKey] = []; + } + $result->setAttr($relation, $this->resultSetBuild($data[$result->$localKey], $class)); + } + } + } + + /** + * 预载入关联查询 返回模型对象 + * @access public + * @param Model $result 数据对象 + * @param string $relation 关联名 + * @param string $class 数据集对象名 为空表示数组 + * @return Model + */ + public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class) + { + $localKey = $this->localKey; + $foreignKey = $this->foreignKey; + + if (isset($result->$localKey)) { + $data = $this->eagerlyOneToMany($this, [$foreignKey => $result->$localKey], $relation, $subRelation, $closure); + // 关联数据封装 + if (!isset($data[$result->$localKey])) { + $data[$result->$localKey] = []; + } + $result->setAttr($relation, $this->resultSetBuild($data[$result->$localKey], $class)); + } + } + + /** + * 一对多 关联模型预查询 + * @access public + * @param object $model 关联模型对象 + * @param array $where 关联预查询条件 + * @param string $relation 关联名 + * @param string $subRelation 子关联 + * @param bool $closure + * @return array + */ + protected function eagerlyOneToMany($model, $where, $relation, $subRelation = '', $closure = false) + { + $foreignKey = $this->foreignKey; + // 预载入关联查询 支持嵌套预载入 + if ($closure) { + call_user_func_array($closure, [ & $model]); + } + $list = $model->where($where)->with($subRelation)->select(); + + // 组装模型数据 + $data = []; + foreach ($list as $set) { + $data[$set->$foreignKey][] = $set; + } + return $data; + } + + /** + * 保存(新增)当前关联数据对象 + * @access public + * @param mixed $data 数据 可以使用数组 关联模型对象 和 关联对象的主键 + * @return integer + */ + public function save($data) + { + if ($data instanceof Model) { + $data = $data->getData(); + } + // 保存关联表数据 + $data[$this->foreignKey] = $this->parent->{$this->localKey}; + $model = new $this->model; + return $model->save($data); + } + + /** + * 批量保存当前关联数据对象 + * @access public + * @param array $dataSet 数据集 + * @return integer + */ + public function saveAll(array $dataSet) + { + $result = false; + foreach ($dataSet as $key => $data) { + $data[$this->foreignKey] = $this->parent->{$this->localKey}; + $result = $this->save($data); + } + return $result; + } + + /** + * 根据关联条件查询当前模型 + * @access public + * @param Model $model 模型对象 + * @param string $operator 比较操作符 + * @param integer $count 个数 + * @param string $id 关联表的统计字段 + * @return Query + */ + public static function has($model, $operator = '>=', $count = 1, $id = '*') + { + $table = $this->query->getTable(); + return $model->db()->alias('a') + ->join($table . ' b', 'a.' . $this->localKey . '=b.' . $this->foreignKey, $this->joinType) + ->group('b.' . $this->foreignKey) + ->having('count(' . $id . ')' . $operator . $count); + } + + /** + * 根据关联条件查询当前模型 + * @access public + * @param Model $model 模型对象 + * @param mixed $where 查询条件(数组或者闭包) + * @return Query + */ + public static function hasWhere($model, $where = []) + { + $table = $this->query->getTable(); + if (is_array($where)) { + foreach ($where as $key => $val) { + if (false === strpos($key, '.')) { + $where['b.' . $key] = $val; + unset($where[$key]); + } + } + } + return $model->db()->alias('a') + ->field('a.*') + ->join($table . ' b', 'a.' . $this->localKey . '=b.' . $this->foreignKey, $this->joinType) + ->where($where); + } + + public function __call($method, $args) + { + static $baseQuery = false; + if ($this->query) { + if (empty($baseQuery)) { + $baseQuery = true; + if (isset($this->where)) { + $this->query->where($this->where); + } elseif (isset($this->parent->{$this->localKey})) { + // 关联查询带入关联条件 + $this->query->where($this->foreignKey, $this->parent->{$this->localKey}); + } + } + + $result = call_user_func_array([$this->query, $method], $args); + if ($result instanceof \think\db\Query) { + $this->option = $result->getOptions(); + return $this; + } else { + $this->option = []; + $baseQuery = false; + return $result; + } + } else { + throw new Exception('method not exists:' . __CLASS__ . '->' . $method); + } + } +} diff --git a/library/think/model/relation/HasManyThrough.php b/library/think/model/relation/HasManyThrough.php new file mode 100644 index 00000000..8f76f573 --- /dev/null +++ b/library/think/model/relation/HasManyThrough.php @@ -0,0 +1,124 @@ + +// +---------------------------------------------------------------------- + +namespace think\model\relation; + +use think\Db; +use think\db\Query; +use think\Model; +use think\model\Relation; + +class HasManyThrough extends Relation +{ + // 中间关联表外键 + protected $throughKey; + + /** + * 架构函数 + * @access public + * @param Model $parent 上级模型对象 + * @param string $model 模型名 + * @param string $through 中间模型名 + * @param string $firstkey 关联外键 + * @param string $secondKey 关联外键 + * @param string $localKey 关联主键 + * @param array $alias 别名定义 + */ + public function __construct(Model $parent, $model, $through, $foreignKey, $throughKey, $localKey, $alias = []) + { + $this->parent = $parent; + $this->model = $model; + $this->middle = $through; + $this->foreignKey = $foreignKey; + $this->throughKey = $throughKey; + $this->localKey = $localKey; + $this->alias = $alias; + $this->query = (new $model)->db(); + } + + // 动态获取关联数据 + public function getRelation() + { + return $this->select(); + } + + /** + * 预载入关联查询 + * @access public + * @param Query $query 查询对象 + * @param string $relation 关联名 + * @param bool $first 是否需要使用基础表 + * @return void + */ + public function eagerly(Query $query, $relation, $subRelation, $closure, $first) + { + + } + + /** + * 预载入关联查询 返回数据集 + * @access public + * @param array $resultSet 数据集 + * @param string $relation 关联名 + * @param string $class 数据集对象名 为空表示数组 + * @return array + */ + public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class) + { + + } + + /** + * 预载入关联查询 返回模型对象 + * @access public + * @param Model $result 数据对象 + * @param string $relation 关联名 + * @param string $class 数据集对象名 为空表示数组 + * @return Model + */ + public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class) + { + + } + + public function __call($method, $args) + { + static $baseQuery = false; + if ($this->query) { + if (empty($baseQuery)) { + $baseQuery = true; + $through = $this->middle; + $model = $this->model; + $alias = Loader::parseName(basename(str_replace('\\', '/', $model))); + $throughTable = $through::getTable(); + $pk = (new $this->model)->getPk(); + $throughKey = $this->throughKey; + $modelTable = $this->parent->getTable(); + $this->query->field($alias . '.*')->alias($alias) + ->join($throughTable, $throughTable . '.' . $pk . '=' . $alias . '.' . $throughKey) + ->join($modelTable, $modelTable . '.' . $this->localKey . '=' . $throughTable . '.' . $this->foreignKey) + ->where($throughTable . '.' . $this->foreignKey, $this->parent->{$this->localKey}); + } + + $result = call_user_func_array([$this->query, $method], $args); + if ($result instanceof \think\db\Query) { + $this->option = $result->getOptions(); + return $this; + } else { + $this->option = []; + $baseQuery = false; + return $result; + } + } else { + throw new Exception('method not exists:' . __CLASS__ . '->' . $method); + } + } +} diff --git a/library/think/model/relation/HasOne.php b/library/think/model/relation/HasOne.php new file mode 100644 index 00000000..c7b71c53 --- /dev/null +++ b/library/think/model/relation/HasOne.php @@ -0,0 +1,174 @@ + +// +---------------------------------------------------------------------- + +namespace think\model\relation; + +use think\Db; +use think\db\Query; +use think\Loader; +use think\Model; +use think\model\Relation; + +class HasOne extends Relation +{ + /** + * 架构函数 + * @access public + * @param Model $parent 上级模型对象 + * @param string $model 模型名 + * @param string $foreignKey 关联外键 + * @param string $localKey 关联主键 + * @param array $alias 别名定义 + * @param string $joinType JOIN类型 + */ + public function __construct(Model $parent, $model, $foreignKey, $localKey, $alias = [], $joinType = 'INNER') + { + $this->parent = $parent; + $this->model = $model; + $this->foreignKey = $foreignKey; + $this->localKey = $localKey; + $this->alias = $alias; + $this->joinType = $joinType; + $this->query = (new $model)->db(); + } + + // 动态获取关联数据 + public function getRelation() + { + // 执行关联定义方法 + $localKey = $this->localKey; + + // 判断关联类型执行查询 + return $this->query->where($this->foreignKey, $this->parent->$localKey)->find(); + } + + /** + * 预载入关联查询 + * @access public + * @param Query $query 查询对象 + * @param string $relation 关联名 + * @return void + */ + public function eagerly(Query $query, $relation, $subRelation, &$closure, $first) + { + $name = Loader::parseName(basename(str_replace('\\', '/', $query->getModel()))); + $alias = isset($this->alias[$name]) ? $this->alias[$name] : $name; + if ($first) { + $table = $query->getTable(); + $query->table([$table => $alias]); + if ($query->getOptions('field')) { + $field = $query->getOptions('field'); + $query->removeOption('field'); + } else { + $field = true; + } + $query->field($field, false, $table, $alias); + + } + + // 预载入封装 + $joinTable = $this->query->getTable(); + $joinName = Loader::parseName(basename(str_replace('\\', '/', $this->model))); + $joinAlias = isset($this->alias[$joinName]) ? $this->alias[$joinName] : $relation; + $query->via($joinAlias); + + $query->join($joinTable . ' ' . $joinAlias, $alias . '.' . $this->localKey . '=' . $joinAlias . '.' . $this->foreignKey, $this->joinType); + + if ($closure) { + // 执行闭包查询 + call_user_func_array($closure, [ & $query]); + //指定获取关联的字段 + //需要在 回调中 调方法 withField 方法,如 + // $query->where(['id'=>1])->withField('id,name'); + if ($query->getOptions('with_field')) { + $field = $query->getOptions('with_field'); + $query->removeOption('with_field'); + } + $closure = null; + } elseif (isset($this->option['field'])) { + $field = $this->option['field']; + } else { + $field = true; + } + $query->field($field, false, $joinTable, $joinAlias, $relation . '__'); + } + + /** + * 预载入关联查询 返回数据集 + * @access public + * @param array $resultSet 数据集 + * @param string $relation 关联名 + * @param string $class 数据集对象名 为空表示数组 + * @return array + */ + public function eagerlyResultSet(&$resultSet, $relation) + { + foreach ($resultSet as $result) { + // 模型关联组装 + $this->match($this->model, $relation, $result); + } + } + + /** + * 预载入关联查询 返回模型对象 + * @access public + * @param Model $result 数据对象 + * @param string $relation 关联名 + * @param string $class 数据集对象名 为空表示数组 + * @return Model + */ + public function eagerlyResult(&$result, $relation) + { + // 模型关联组装 + $this->match($this->model, $relation, $result); + } + + /** + * 一对一 关联模型预查询拼装 + * @access public + * @param string $model 模型名称 + * @param string $relation 关联名 + * @param Model $result 模型对象实例 + * @return void + */ + protected function match($model, $relation, &$result) + { + // 重新组装模型数据 + foreach ($result->getData() as $key => $val) { + if (strpos($key, '__')) { + list($name, $attr) = explode('__', $key, 2); + if ($name == $relation) { + $list[$name][$attr] = $val; + unset($result->$key); + } + } + } + + $result->setAttr($relation, !isset($list[$relation]) ? null : (new $model($list[$relation]))->isUpdate(true)); + } + + /** + * 保存(新增)当前关联数据对象 + * @access public + * @param mixed $data 数据 可以使用数组 关联模型对象 和 关联对象的主键 + * @return integer + */ + public function save($data) + { + if ($data instanceof Model) { + $data = $data->getData(); + } + // 保存关联表数据 + $data[$this->foreignKey] = $this->parent->{$this->localKey}; + $model = new $this->model; + return $model->save($data); + } +} diff --git a/library/think/model/relation/MorphMany.php b/library/think/model/relation/MorphMany.php new file mode 100644 index 00000000..9d6371ba --- /dev/null +++ b/library/think/model/relation/MorphMany.php @@ -0,0 +1,175 @@ + +// +---------------------------------------------------------------------- + +namespace think\model\relation; + +use think\Db; +use think\db\Query; +use think\Model; +use think\model\Relation; + +class MorphMany extends Relation +{ + // 多态字段 + protected $morphKey; + protected $morphType; + // 多态类型 + protected $type; + + /** + * 架构函数 + * @access public + * @param Model $parent 上级模型对象 + * @param string $model 模型名 + * @param string $morphKey 关联外键 + * @param string $morphType 多态字段名 + * @param string $type 多态类型 + */ + public function __construct(Model $parent, $model, $morphKey, $morphType, $type) + { + $this->parent = $parent; + $this->model = $model; + $this->type = $type; + $this->morphKey = $morphKey; + $this->morphType = $morphType; + $this->query = (new $model)->db(); + } + + // 动态获取关联数据 + public function getRelation() + { + return $this->select(); + } + + /** + * 预载入关联查询 + * @access public + * @param Query $query 查询对象 + * @param string $relation 关联名 + * @param bool $first 是否需要使用基础表 + * @return void + */ + public function eagerly(Query $query, $relation, $subRelation, $closure, $first) + { + + } + + /** + * 预载入关联查询 返回数据集 + * @access public + * @param array $resultSet 数据集 + * @param string $relation 关联名 + * @param string $class 数据集对象名 为空表示数组 + * @return array + */ + public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class) + { + $morphType = $this->morphType; + $morphKey = $this->morphKey; + $type = $this->type; + $range = []; + foreach ($resultSet as $result) { + $pk = $result->getPk(); + // 获取关联外键列表 + if (isset($result->$pk)) { + $range[] = $result->$pk; + } + } + + if (!empty($range)) { + $this->where[$morphKey] = ['in', $range]; + $this->where[$morphType] = $type; + $data = $this->eagerlyMorphToMany([ + $morphKey => ['in', $range], + $morphType => $type, + ], $relation, $subRelation, $closure); + + // 关联数据封装 + foreach ($resultSet as $result) { + if (!isset($data[$result->$pk])) { + $data[$result->$pk] = []; + } + $result->setAttr($relation, $this->resultSetBuild($data[$result->$pk], $class)); + } + } + } + + /** + * 预载入关联查询 返回模型对象 + * @access public + * @param Model $result 数据对象 + * @param string $relation 关联名 + * @param string $class 数据集对象名 为空表示数组 + * @return Model + */ + public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class) + { + $morphType = $this->morphType; + $morphKey = $this->morphKey; + $type = $this->type; + $pk = $result->getPk(); + if (isset($result->$pk)) { + $data = $this->eagerlyMorphToMany([$morphKey => $result->$pk, $morphType => $type], $relation, $subRelation, $closure); + $result->setAttr($relation, $this->resultSetBuild($data[$result->$pk], $class)); + } + } + + /** + * 多态一对多 关联模型预查询 + * @access public + * @param object $model 关联模型对象 + * @param array $where 关联预查询条件 + * @param string $relation 关联名 + * @param string $subRelation 子关联 + * @return array + */ + protected function eagerlyMorphToMany($where, $relation, $subRelation = '', $closure = false) + { + // 预载入关联查询 支持嵌套预载入 + if ($closure) { + call_user_func_array($closure, [ & $this]); + } + $list = $this->query->where($where)->with($subRelation)->select(); + $morphKey = $this->morphKey; + // 组装模型数据 + $data = []; + foreach ($list as $set) { + $data[$set->$morphKey][] = $set; + } + return $data; + } + + public function __call($method, $args) + { + static $baseQuery = false; + if ($this->query) { + if (empty($baseQuery)) { + $baseQuery = true; + $pk = $this->parent->getPk(); + $map[$this->morphKey] = $this->parent->$pk; + $map[$this->morphType] = $this->type; + $this->query->where($map); + } + + $result = call_user_func_array([$this->query, $method], $args); + if ($result instanceof \think\db\Query) { + $this->option = $result->getOptions(); + return $this; + } else { + $this->option = []; + $baseQuery = false; + return $result; + } + } else { + throw new Exception('method not exists:' . __CLASS__ . '->' . $method); + } + } +} diff --git a/library/think/model/relation/MorphTo.php b/library/think/model/relation/MorphTo.php new file mode 100644 index 00000000..0d55d2e4 --- /dev/null +++ b/library/think/model/relation/MorphTo.php @@ -0,0 +1,166 @@ + +// +---------------------------------------------------------------------- + +namespace think\model\relation; + +use think\db\Query; +use think\Loader; +use think\Model; +use think\model\Relation; + +class MorphTo extends Relation +{ + // 多态字段 + protected $morphKey; + protected $morphType; + + /** + * 架构函数 + * @access public + * @param Model $parent 上级模型对象 + * @param string $morphType 多态字段名 + * @param string $morphKey 外键名 + * @param array $alias 多态别名定义 + */ + public function __construct(Model $parent, $morphType, $morphKey, $alias = []) + { + $this->parent = $parent; + $this->morphType = $morphType; + $this->morphKey = $morphKey; + $this->alias = $alias; + } + + // 动态获取关联数据 + public function getRelation() + { + $morphKey = $this->morphKey; + $morphType = $this->morphType; + // 多态模型 + $model = $this->parseModel($this->parent->$morphType); + // 主键数据 + $pk = $this->parent->$morphKey; + return (new $model)->find($pk); + } + + /** + * 解析模型的完整命名空间 + * @access public + * @param string $model 模型名(或者完整类名) + * @return string + */ + protected function parseModel($model) + { + if (isset($this->alias[$model])) { + $model = $this->alias[$model]; + } + if (false === strpos($model, '\\')) { + $path = explode('\\', get_class($this->parent)); + array_pop($path); + array_push($path, Loader::parseName($model, 1)); + $model = implode('\\', $path); + } + return $model; + } + + /** + * 预载入关联查询 + * @access public + * @param Query $query 查询对象 + * @param string $relation 关联名 + * @param bool $first 是否需要使用基础表 + * @return void + */ + public function eagerly(Query $query, $relation, $subRelation, $closure, $first) + { + + } + + /** + * 预载入关联查询 返回数据集 + * @access public + * @param array $resultSet 数据集 + * @param string $relation 关联名 + * @param string $class 数据集对象名 为空表示数组 + * @return array + */ + public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class) + { + $morphKey = $this->morphKey; + $morphType = $this->morphType; + $range = []; + foreach ($resultSet as $result) { + // 获取关联外键列表 + if (!empty($result->$morphKey)) { + $range[$result->$morphType][] = $result->$morphKey; + } + } + + if (!empty($range)) { + foreach ($range as $key => $val) { + // 多态类型映射 + $model = $this->parseModel($key); + $obj = new $model; + $pk = $obj->getPk(); + $list = $obj->all($val, $subRelation); + $data = []; + foreach ($list as $k => $vo) { + $data[$vo->$pk] = $vo; + } + foreach ($resultSet as $result) { + if ($key == $result->$morphType) { + if (!isset($data[$result->$morphKey])) { + $data[$result->$morphKey] = []; + } + $result->setAttr($relation, $this->resultSetBuild($data[$result->$morphKey], $class)); + } + } + } + } + } + + /** + * 预载入关联查询 返回模型对象 + * @access public + * @param Model $result 数据对象 + * @param string $relation 关联名 + * @param string $class 数据集对象名 为空表示数组 + * @return Model + */ + public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class) + { + $morphKey = $this->morphKey; + $morphType = $this->morphType; + // 多态类型映射 + $model = $this->parseModel($result->{$this->morphType}); + $this->eagerlyMorphToOne($model, $relation, $result, $subRelation); + } + + /** + * 多态MorphTo 关联模型预查询 + * @access public + * @param object $model 关联模型对象 + * @param array $where 关联预查询条件 + * @param string $relation 关联名 + * @param string $subRelation 子关联 + * @return array + */ + protected function eagerlyMorphToOne($model, $relation, &$result, $subRelation = '') + { + // 预载入关联查询 支持嵌套预载入 + $pk = $this->parent->{$this->morphKey}; + $data = (new $model)->with($subRelation)->find($pk); + if ($data) { + $data->isUpdate(true); + } + $result->setAttr($relation, $data ?: null); + } + +} -- Gitee From 1d2b44adc8346aa6924c92f8d77be06445967976 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 5 Dec 2016 10:55:50 +0800 Subject: [PATCH 0207/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Query=E7=9A=84selec?= =?UTF-8?q?t=E6=96=B9=E6=B3=95=E7=9A=84=E5=85=B3=E8=81=94=E9=A2=84?= =?UTF-8?q?=E8=BD=BD=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 2 +- library/think/model/relation/HasManyThrough.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index b6ad8ff8..4d63ba14 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1985,7 +1985,7 @@ class Query } if (!empty($options['with']) && $result instanceof Model) { // 预载入 - $resultSet = $result->eagerlyResultSet($resultSet, $options['with'], is_object($resultSet) ? get_class($resultSet) : ''); + $result->eagerlyResultSet($resultSet, $options['with'], is_object($resultSet) ? get_class($resultSet) : ''); } } } elseif (!empty($options['fail'])) { diff --git a/library/think/model/relation/HasManyThrough.php b/library/think/model/relation/HasManyThrough.php index 8f76f573..2661b7b3 100644 --- a/library/think/model/relation/HasManyThrough.php +++ b/library/think/model/relation/HasManyThrough.php @@ -13,6 +13,7 @@ namespace think\model\relation; use think\Db; use think\db\Query; +use think\Loader; use think\Model; use think\model\Relation; -- Gitee From 5037c64f53baf2ac0cf0d0add769fcd5486e5d5c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 5 Dec 2016 11:55:04 +0800 Subject: [PATCH 0208/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=85=B3=E8=81=94?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/Relation.php | 12 +- library/think/model/relation/BelongsTo.php | 132 +------------- .../think/model/relation/BelongsToMany.php | 65 +++---- library/think/model/relation/HasMany.php | 69 +++----- .../think/model/relation/HasManyThrough.php | 68 ++++---- library/think/model/relation/HasOne.php | 133 +-------------- library/think/model/relation/MorphMany.php | 67 +++----- library/think/model/relation/MorphTo.php | 27 ++- library/think/model/relation/OneToOne.php | 161 ++++++++++++++++++ 9 files changed, 306 insertions(+), 428 deletions(-) create mode 100644 library/think/model/relation/OneToOne.php diff --git a/library/think/model/Relation.php b/library/think/model/Relation.php index d7938836..22223281 100644 --- a/library/think/model/Relation.php +++ b/library/think/model/Relation.php @@ -11,6 +11,8 @@ namespace think\model; +use think\db\Query; + abstract class Relation { // 父模型对象 @@ -31,6 +33,8 @@ abstract class Relation protected $where; // 关联查询参数 protected $option; + // 基础查询 + protected $baseQuery; /** * 获取关联的所属模型 @@ -77,12 +81,16 @@ abstract class Relation public function __call($method, $args) { if ($this->query) { + // 执行基础查询 + $this->baseQuery(); + $result = call_user_func_array([$this->query, $method], $args); - if ($result instanceof \think\db\Query) { + if ($result instanceof Query) { $this->option = $result->getOptions(); return $this; } else { - $this->option = []; + $this->option = []; + $this->baseQuery = false; return $result; } } else { diff --git a/library/think/model/relation/BelongsTo.php b/library/think/model/relation/BelongsTo.php index ae5c400e..ffab752d 100644 --- a/library/think/model/relation/BelongsTo.php +++ b/library/think/model/relation/BelongsTo.php @@ -11,13 +11,10 @@ namespace think\model\relation; -use think\Db; -use think\db\Query; -use think\Loader; use think\Model; -use think\model\Relation; +use think\model\relation\OneToOne; -class BelongsTo extends Relation +class BelongsTo extends OneToOne { /** * 架构函数 @@ -40,7 +37,10 @@ class BelongsTo extends Relation $this->query = (new $model)->db(); } - // 动态获取关联数据 + /** + * 延迟获取关联数据 + * @access public + */ public function getRelation() { $foreignKey = $this->foreignKey; @@ -48,124 +48,4 @@ class BelongsTo extends Relation return $this->query->where($localKey, $this->parent->$foreignKey)->find(); } - /** - * 预载入关联查询 - * @access public - * @param Query $query 查询对象 - * @param string $relation 关联名 - * @return void - */ - public function eagerly(Query $query, $relation, $subRelation, $closure, $first) - { - $name = Loader::parseName(basename(str_replace('\\', '/', $query->getModel()))); - $alias = isset($this->alias[$name]) ? $this->alias[$name] : $name; - if ($first) { - - $table = $query->getTable(); - $query->table([$table => $alias]); - if ($query->getOptions('field')) { - $field = $query->getOptions('field'); - $query->removeOption('field'); - } else { - $field = true; - } - $query->field($field, false, $table, $alias); - } - - // 预载入封装 - $joinTable = $this->query->getTable(); - $joinName = Loader::parseName(basename(str_replace('\\', '/', $this->model))); - $joinAlias = isset($this->alias[$joinName]) ? $this->alias[$joinName] : $relation; - $query->via($joinAlias); - - $query->join($joinTable . ' ' . $joinAlias, $alias . '.' . $this->foreignKey . '=' . $joinAlias . '.' . $this->localKey, $this->joinType); - - if ($closure) { - // 执行闭包查询 - call_user_func_array($closure, [ & $query]); - //指定获取关联的字段 - //需要在 回调中 调方法 withField 方法,如 - // $query->where(['id'=>1])->withField('id,name'); - if ($query->getOptions('with_field')) { - $field = $query->getOptions('with_field'); - $query->removeOption('with_field'); - } - } elseif (isset($this->option['field'])) { - $field = $this->option['field']; - } else { - $field = true; - } - $query->field($field, false, $joinTable, $joinAlias, $relation . '__'); - } - - /** - * 预载入关联查询 返回数据集 - * @access public - * @param array $resultSet 数据集 - * @param string $relation 关联名 - * @param string $class 数据集对象名 为空表示数组 - * @return array - */ - public function eagerlyResultSet(&$resultSet, $relation) - { - foreach ($resultSet as $result) { - // 模型关联组装 - $this->match($this->model, $relation, $result); - } - } - - /** - * 预载入关联查询 返回模型对象 - * @access public - * @param Model $result 数据对象 - * @param string $relation 关联名 - * @param string $class 数据集对象名 为空表示数组 - * @return Model - */ - public function eagerlyResult(&$result, $relation) - { - // 模型关联组装 - $this->match($this->model, $relation, $result); - } - - /** - * 一对一 关联模型预查询拼装 - * @access public - * @param string $model 模型名称 - * @param string $relation 关联名 - * @param Model $result 模型对象实例 - * @return void - */ - protected function match($model, $relation, &$result) - { - // 重新组装模型数据 - foreach ($result->getData() as $key => $val) { - if (strpos($key, '__')) { - list($name, $attr) = explode('__', $key, 2); - if ($name == $relation) { - $list[$name][$attr] = $val; - unset($result->$key); - } - } - } - - $result->setAttr($relation, !isset($list[$relation]) ? null : (new $model($list[$relation]))->isUpdate(true)); - } - - /** - * 保存(新增)当前关联数据对象 - * @access public - * @param mixed $data 数据 可以使用数组 关联模型对象 和 关联对象的主键 - * @return integer - */ - public function save($data) - { - if ($data instanceof Model) { - $data = $data->getData(); - } - // 保存关联表数据 - $data[$this->foreignKey] = $this->parent->{$this->localKey}; - $model = new $this->model; - return $model->save($data); - } } diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index 59220aee..ccb43be4 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -43,7 +43,10 @@ class BelongsToMany extends Relation $this->query = (new $model)->db(); } - // 动态获取关联数据 + /** + * 延迟获取关联数据 + * @access public + */ public function getRelation() { $foreignKey = $this->foreignKey; @@ -70,25 +73,14 @@ class BelongsToMany extends Relation } /** - * 预载入关联查询 - * @access public - * @param Query $query 查询对象 - * @param string $relation 关联名 - * @param bool $first 是否需要使用基础表 - * @return void - */ - public function eagerly(Query $query, $relation, $subRelation, $closure, $first) - { - - } - - /** - * 预载入关联查询 返回数据集 + * 预载入关联查询(数据集) * @access public * @param array $resultSet 数据集 - * @param string $relation 关联名 + * @param string $relation 当前关联名 + * @param string $subRelation 子关联名 + * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 - * @return array + * @return void */ public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class) { @@ -125,12 +117,14 @@ class BelongsToMany extends Relation } /** - * 预载入关联查询 返回模型对象 + * 预载入关联查询(单个数据) * @access public * @param Model $result 数据对象 - * @param string $relation 关联名 + * @param string $relation 当前关联名 + * @param string $subRelation 子关联名 + * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 - * @return Model + * @return void */ public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class) { @@ -304,27 +298,18 @@ class BelongsToMany extends Relation } } - public function __call($method, $args) + /** + * 执行基础查询(进执行一次) + * @access protected + * @return void + */ + protected function baseQuery() { - static $baseQuery = false; - if ($this->query) { - if (empty($baseQuery)) { - $baseQuery = true; - $pk = $this->parent->getPk(); - $this->query->join($this->middle . ' pivot', 'pivot.' . $this->foreignKey . '=' . $this->query->getTable() . '.' . $this->query->getPk())->where('pivot.' . $this->localKey, $this->parent->$pk); - } - - $result = call_user_func_array([$this->query, $method], $args); - if ($result instanceof \think\db\Query) { - $this->option = $result->getOptions(); - return $this; - } else { - $this->option = []; - $baseQuery = false; - return $result; - } - } else { - throw new Exception('method not exists:' . __CLASS__ . '->' . $method); + if (empty($this->baseQuery)) { + $pk = $this->parent->getPk(); + $this->query->join($this->middle . ' pivot', 'pivot.' . $this->foreignKey . '=' . $this->query->getTable() . '.' . $this->query->getPk())->where('pivot.' . $this->localKey, $this->parent->$pk); + $this->baseQuery = true; } } + } diff --git a/library/think/model/relation/HasMany.php b/library/think/model/relation/HasMany.php index 5c7d129a..7d73e3a2 100644 --- a/library/think/model/relation/HasMany.php +++ b/library/think/model/relation/HasMany.php @@ -37,32 +37,24 @@ class HasMany extends Relation $this->query = (new $model)->db(); } - // 动态获取关联数据 - public function getRelation() - { - return $this->select(); - } - /** - * 预载入关联查询 + * 延迟获取关联数据 * @access public - * @param Query $query 查询对象 - * @param string $relation 关联名 - * @param bool $first 是否需要使用基础表 - * @return void */ - public function eagerly(Query $query, $relation, $subRelation, $closure, $first) + public function getRelation() { - + return $this->select(); } /** - * 预载入关联查询 返回数据集 + * 预载入关联查询 * @access public * @param array $resultSet 数据集 - * @param string $relation 关联名 + * @param string $relation 当前关联名 + * @param string $subRelation 子关联名 + * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 - * @return array + * @return void */ public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class) { @@ -97,12 +89,14 @@ class HasMany extends Relation } /** - * 预载入关联查询 返回模型对象 + * 预载入关联查询 * @access public * @param Model $result 数据对象 - * @param string $relation 关联名 + * @param string $relation 当前关联名 + * @param string $subRelation 子关联名 + * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 - * @return Model + * @return void */ public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class) { @@ -221,31 +215,22 @@ class HasMany extends Relation ->where($where); } - public function __call($method, $args) + /** + * 执行基础查询(进执行一次) + * @access protected + * @return void + */ + protected function baseQuery() { - static $baseQuery = false; - if ($this->query) { - if (empty($baseQuery)) { - $baseQuery = true; - if (isset($this->where)) { - $this->query->where($this->where); - } elseif (isset($this->parent->{$this->localKey})) { - // 关联查询带入关联条件 - $this->query->where($this->foreignKey, $this->parent->{$this->localKey}); - } + if (empty($this->baseQuery)) { + if (isset($this->where)) { + $this->query->where($this->where); + } elseif (isset($this->parent->{$this->localKey})) { + // 关联查询带入关联条件 + $this->query->where($this->foreignKey, $this->parent->{$this->localKey}); } - - $result = call_user_func_array([$this->query, $method], $args); - if ($result instanceof \think\db\Query) { - $this->option = $result->getOptions(); - return $this; - } else { - $this->option = []; - $baseQuery = false; - return $result; - } - } else { - throw new Exception('method not exists:' . __CLASS__ . '->' . $method); + $this->baseQuery = true; } } + } diff --git a/library/think/model/relation/HasManyThrough.php b/library/think/model/relation/HasManyThrough.php index 2661b7b3..9f4c0431 100644 --- a/library/think/model/relation/HasManyThrough.php +++ b/library/think/model/relation/HasManyThrough.php @@ -45,7 +45,10 @@ class HasManyThrough extends Relation $this->query = (new $model)->db(); } - // 动态获取关联数据 + /** + * 延迟获取关联数据 + * @access public + */ public function getRelation() { return $this->select(); @@ -65,12 +68,14 @@ class HasManyThrough extends Relation } /** - * 预载入关联查询 返回数据集 + * 预载入关联查询 * @access public * @param array $resultSet 数据集 - * @param string $relation 关联名 + * @param string $relation 当前关联名 + * @param string $subRelation 子关联名 + * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 - * @return array + * @return void */ public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class) { @@ -81,45 +86,38 @@ class HasManyThrough extends Relation * 预载入关联查询 返回模型对象 * @access public * @param Model $result 数据对象 - * @param string $relation 关联名 + * @param string $relation 当前关联名 + * @param string $subRelation 子关联名 + * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 - * @return Model + * @return void */ public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class) { } - public function __call($method, $args) + /** + * 执行基础查询(进执行一次) + * @access protected + * @return void + */ + protected function baseQuery() { - static $baseQuery = false; - if ($this->query) { - if (empty($baseQuery)) { - $baseQuery = true; - $through = $this->middle; - $model = $this->model; - $alias = Loader::parseName(basename(str_replace('\\', '/', $model))); - $throughTable = $through::getTable(); - $pk = (new $this->model)->getPk(); - $throughKey = $this->throughKey; - $modelTable = $this->parent->getTable(); - $this->query->field($alias . '.*')->alias($alias) - ->join($throughTable, $throughTable . '.' . $pk . '=' . $alias . '.' . $throughKey) - ->join($modelTable, $modelTable . '.' . $this->localKey . '=' . $throughTable . '.' . $this->foreignKey) - ->where($throughTable . '.' . $this->foreignKey, $this->parent->{$this->localKey}); - } - - $result = call_user_func_array([$this->query, $method], $args); - if ($result instanceof \think\db\Query) { - $this->option = $result->getOptions(); - return $this; - } else { - $this->option = []; - $baseQuery = false; - return $result; - } - } else { - throw new Exception('method not exists:' . __CLASS__ . '->' . $method); + if (empty($this->baseQuery)) { + $through = $this->middle; + $model = $this->model; + $alias = Loader::parseName(basename(str_replace('\\', '/', $model))); + $throughTable = $through::getTable(); + $pk = (new $this->model)->getPk(); + $throughKey = $this->throughKey; + $modelTable = $this->parent->getTable(); + $this->query->field($alias . '.*')->alias($alias) + ->join($throughTable, $throughTable . '.' . $pk . '=' . $alias . '.' . $throughKey) + ->join($modelTable, $modelTable . '.' . $this->localKey . '=' . $throughTable . '.' . $this->foreignKey) + ->where($throughTable . '.' . $this->foreignKey, $this->parent->{$this->localKey}); + $this->baseQuery = true; } } + } diff --git a/library/think/model/relation/HasOne.php b/library/think/model/relation/HasOne.php index c7b71c53..85ac237e 100644 --- a/library/think/model/relation/HasOne.php +++ b/library/think/model/relation/HasOne.php @@ -11,13 +11,10 @@ namespace think\model\relation; -use think\Db; -use think\db\Query; -use think\Loader; use think\Model; -use think\model\Relation; +use think\model\relation\OneToOne; -class HasOne extends Relation +class HasOne extends OneToOne { /** * 架构函数 @@ -40,7 +37,10 @@ class HasOne extends Relation $this->query = (new $model)->db(); } - // 动态获取关联数据 + /** + * 延迟获取关联数据 + * @access public + */ public function getRelation() { // 执行关联定义方法 @@ -50,125 +50,4 @@ class HasOne extends Relation return $this->query->where($this->foreignKey, $this->parent->$localKey)->find(); } - /** - * 预载入关联查询 - * @access public - * @param Query $query 查询对象 - * @param string $relation 关联名 - * @return void - */ - public function eagerly(Query $query, $relation, $subRelation, &$closure, $first) - { - $name = Loader::parseName(basename(str_replace('\\', '/', $query->getModel()))); - $alias = isset($this->alias[$name]) ? $this->alias[$name] : $name; - if ($first) { - $table = $query->getTable(); - $query->table([$table => $alias]); - if ($query->getOptions('field')) { - $field = $query->getOptions('field'); - $query->removeOption('field'); - } else { - $field = true; - } - $query->field($field, false, $table, $alias); - - } - - // 预载入封装 - $joinTable = $this->query->getTable(); - $joinName = Loader::parseName(basename(str_replace('\\', '/', $this->model))); - $joinAlias = isset($this->alias[$joinName]) ? $this->alias[$joinName] : $relation; - $query->via($joinAlias); - - $query->join($joinTable . ' ' . $joinAlias, $alias . '.' . $this->localKey . '=' . $joinAlias . '.' . $this->foreignKey, $this->joinType); - - if ($closure) { - // 执行闭包查询 - call_user_func_array($closure, [ & $query]); - //指定获取关联的字段 - //需要在 回调中 调方法 withField 方法,如 - // $query->where(['id'=>1])->withField('id,name'); - if ($query->getOptions('with_field')) { - $field = $query->getOptions('with_field'); - $query->removeOption('with_field'); - } - $closure = null; - } elseif (isset($this->option['field'])) { - $field = $this->option['field']; - } else { - $field = true; - } - $query->field($field, false, $joinTable, $joinAlias, $relation . '__'); - } - - /** - * 预载入关联查询 返回数据集 - * @access public - * @param array $resultSet 数据集 - * @param string $relation 关联名 - * @param string $class 数据集对象名 为空表示数组 - * @return array - */ - public function eagerlyResultSet(&$resultSet, $relation) - { - foreach ($resultSet as $result) { - // 模型关联组装 - $this->match($this->model, $relation, $result); - } - } - - /** - * 预载入关联查询 返回模型对象 - * @access public - * @param Model $result 数据对象 - * @param string $relation 关联名 - * @param string $class 数据集对象名 为空表示数组 - * @return Model - */ - public function eagerlyResult(&$result, $relation) - { - // 模型关联组装 - $this->match($this->model, $relation, $result); - } - - /** - * 一对一 关联模型预查询拼装 - * @access public - * @param string $model 模型名称 - * @param string $relation 关联名 - * @param Model $result 模型对象实例 - * @return void - */ - protected function match($model, $relation, &$result) - { - // 重新组装模型数据 - foreach ($result->getData() as $key => $val) { - if (strpos($key, '__')) { - list($name, $attr) = explode('__', $key, 2); - if ($name == $relation) { - $list[$name][$attr] = $val; - unset($result->$key); - } - } - } - - $result->setAttr($relation, !isset($list[$relation]) ? null : (new $model($list[$relation]))->isUpdate(true)); - } - - /** - * 保存(新增)当前关联数据对象 - * @access public - * @param mixed $data 数据 可以使用数组 关联模型对象 和 关联对象的主键 - * @return integer - */ - public function save($data) - { - if ($data instanceof Model) { - $data = $data->getData(); - } - // 保存关联表数据 - $data[$this->foreignKey] = $this->parent->{$this->localKey}; - $model = new $this->model; - return $model->save($data); - } } diff --git a/library/think/model/relation/MorphMany.php b/library/think/model/relation/MorphMany.php index 9d6371ba..cfce9b57 100644 --- a/library/think/model/relation/MorphMany.php +++ b/library/think/model/relation/MorphMany.php @@ -43,32 +43,24 @@ class MorphMany extends Relation $this->query = (new $model)->db(); } - // 动态获取关联数据 - public function getRelation() - { - return $this->select(); - } - /** - * 预载入关联查询 + * 延迟获取关联数据 * @access public - * @param Query $query 查询对象 - * @param string $relation 关联名 - * @param bool $first 是否需要使用基础表 - * @return void */ - public function eagerly(Query $query, $relation, $subRelation, $closure, $first) + public function getRelation() { - + return $this->select(); } /** - * 预载入关联查询 返回数据集 + * 预载入关联查询 * @access public * @param array $resultSet 数据集 - * @param string $relation 关联名 + * @param string $relation 当前关联名 + * @param string $subRelation 子关联名 + * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 - * @return array + * @return void */ public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class) { @@ -103,12 +95,14 @@ class MorphMany extends Relation } /** - * 预载入关联查询 返回模型对象 + * 预载入关联查询 * @access public * @param Model $result 数据对象 - * @param string $relation 关联名 + * @param string $relation 当前关联名 + * @param string $subRelation 子关联名 + * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 - * @return Model + * @return void */ public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class) { @@ -147,29 +141,20 @@ class MorphMany extends Relation return $data; } - public function __call($method, $args) + /** + * 执行基础查询(进执行一次) + * @access protected + * @return void + */ + protected function baseQuery() { - static $baseQuery = false; - if ($this->query) { - if (empty($baseQuery)) { - $baseQuery = true; - $pk = $this->parent->getPk(); - $map[$this->morphKey] = $this->parent->$pk; - $map[$this->morphType] = $this->type; - $this->query->where($map); - } - - $result = call_user_func_array([$this->query, $method], $args); - if ($result instanceof \think\db\Query) { - $this->option = $result->getOptions(); - return $this; - } else { - $this->option = []; - $baseQuery = false; - return $result; - } - } else { - throw new Exception('method not exists:' . __CLASS__ . '->' . $method); + if (empty($this->baseQuery)) { + $pk = $this->parent->getPk(); + $map[$this->morphKey] = $this->parent->$pk; + $map[$this->morphType] = $this->type; + $this->query->where($map); + $this->baseQuery = true; } } + } diff --git a/library/think/model/relation/MorphTo.php b/library/think/model/relation/MorphTo.php index 0d55d2e4..2b370e08 100644 --- a/library/think/model/relation/MorphTo.php +++ b/library/think/model/relation/MorphTo.php @@ -11,7 +11,6 @@ namespace think\model\relation; -use think\db\Query; use think\Loader; use think\Model; use think\model\Relation; @@ -38,7 +37,10 @@ class MorphTo extends Relation $this->alias = $alias; } - // 动态获取关联数据 + /** + * 延迟获取关联数据 + * @access public + */ public function getRelation() { $morphKey = $this->morphKey; @@ -70,19 +72,6 @@ class MorphTo extends Relation return $model; } - /** - * 预载入关联查询 - * @access public - * @param Query $query 查询对象 - * @param string $relation 关联名 - * @param bool $first 是否需要使用基础表 - * @return void - */ - public function eagerly(Query $query, $relation, $subRelation, $closure, $first) - { - - } - /** * 预载入关联查询 返回数据集 * @access public @@ -163,4 +152,12 @@ class MorphTo extends Relation $result->setAttr($relation, $data ?: null); } + /** + * 执行基础查询(进执行一次) + * @access protected + * @return void + */ + protected function baseQuery() + { + } } diff --git a/library/think/model/relation/OneToOne.php b/library/think/model/relation/OneToOne.php new file mode 100644 index 00000000..650000e9 --- /dev/null +++ b/library/think/model/relation/OneToOne.php @@ -0,0 +1,161 @@ + +// +---------------------------------------------------------------------- + +namespace think\model\relation; + +use think\db\Query; +use think\Loader; +use think\Model; +use think\model\Relation; +use think\model\relation\BelongsTo; + +abstract class OneToOne extends Relation +{ + /** + * 预载入关联查询 + * @access public + * @param Query $query 查询对象 + * @param string $relation 关联名 + * @param string $subRelation 子关联 + * @param \Closure $closure 闭包条件 + * @param bool $first + * @return void + */ + public function eagerly(Query $query, $relation, $subRelation, $closure, $first) + { + $name = Loader::parseName(basename(str_replace('\\', '/', $query->getModel()))); + $alias = isset($this->alias[$name]) ? $this->alias[$name] : $name; + if ($first) { + $table = $query->getTable(); + $query->table([$table => $alias]); + if ($query->getOptions('field')) { + $field = $query->getOptions('field'); + $query->removeOption('field'); + } else { + $field = true; + } + $query->field($field, false, $table, $alias); + } + + // 预载入封装 + $joinTable = $this->query->getTable(); + $joinName = Loader::parseName(basename(str_replace('\\', '/', $this->model))); + $joinAlias = isset($this->alias[$joinName]) ? $this->alias[$joinName] : $relation; + $query->via($joinAlias); + + if ($this instanceof BelongsTo) { + $query->join($joinTable . ' ' . $joinAlias, $alias . '.' . $this->foreignKey . '=' . $joinAlias . '.' . $this->localKey, $this->joinType); + } else { + $query->join($joinTable . ' ' . $joinAlias, $alias . '.' . $this->localKey . '=' . $joinAlias . '.' . $this->foreignKey, $this->joinType); + } + + if ($closure) { + // 执行闭包查询 + call_user_func_array($closure, [ & $query]); + //指定获取关联的字段 + //需要在 回调中 调方法 withField 方法,如 + // $query->where(['id'=>1])->withField('id,name'); + if ($query->getOptions('with_field')) { + $field = $query->getOptions('with_field'); + $query->removeOption('with_field'); + } + } elseif (isset($this->option['field'])) { + $field = $this->option['field']; + } else { + $field = true; + } + $query->field($field, false, $joinTable, $joinAlias, $relation . '__'); + } + + /** + * 预载入关联查询 + * @access public + * @param array $resultSet 数据集 + * @param string $relation 当前关联名 + * @param string $subRelation 子关联名 + * @param \Closure $closure 闭包 + * @param string $class 数据集对象名 为空表示数组 + * @return void + */ + public function eagerlyResultSet(&$resultSet, $relation) + { + foreach ($resultSet as $result) { + // 模型关联组装 + $this->match($this->model, $relation, $result); + } + } + + /** + * 预载入关联查询 返回模型对象 + * @access public + * @param Model $result 数据对象 + * @param string $relation 当前关联名 + * @param string $subRelation 子关联名 + * @param \Closure $closure 闭包 + * @param string $class 数据集对象名 为空表示数组 + * @return void + */ + public function eagerlyResult(&$result, $relation) + { + // 模型关联组装 + $this->match($this->model, $relation, $result); + } + + /** + * 一对一 关联模型预查询拼装 + * @access public + * @param string $model 模型名称 + * @param string $relation 关联名 + * @param Model $result 模型对象实例 + * @return void + */ + protected function match($model, $relation, &$result) + { + // 重新组装模型数据 + foreach ($result->getData() as $key => $val) { + if (strpos($key, '__')) { + list($name, $attr) = explode('__', $key, 2); + if ($name == $relation) { + $list[$name][$attr] = $val; + unset($result->$key); + } + } + } + + $result->setAttr($relation, !isset($list[$relation]) ? null : (new $model($list[$relation]))->isUpdate(true)); + } + + /** + * 保存(新增)当前关联数据对象 + * @access public + * @param mixed $data 数据 可以使用数组 关联模型对象 和 关联对象的主键 + * @return integer + */ + public function save($data) + { + if ($data instanceof Model) { + $data = $data->getData(); + } + // 保存关联表数据 + $data[$this->foreignKey] = $this->parent->{$this->localKey}; + $model = new $this->model; + return $model->save($data); + } + + /** + * 执行基础查询(进执行一次) + * @access protected + * @return void + */ + protected function baseQuery() + { + } +} -- Gitee From 1f53806272bd9a1f8e0d057030dc9ec902e174d3 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 5 Dec 2016 12:01:35 +0800 Subject: [PATCH 0209/1170] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/relation/BelongsToMany.php | 2 +- .../think/model/relation/HasManyThrough.php | 15 --------------- library/think/model/relation/MorphTo.php | 18 +++++++++++------- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index ccb43be4..486f08d8 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -186,7 +186,7 @@ class BelongsToMany extends Relation * @param string $foreignKey 关联模型关联键 * @param string $localKey 当前模型关联键 * @param array $condition 关联查询条件 - * @return \think\db\Query|string + * @return Query */ protected function belongsToManyQuery($table, $foreignKey, $localKey, $condition = []) { diff --git a/library/think/model/relation/HasManyThrough.php b/library/think/model/relation/HasManyThrough.php index 9f4c0431..9339d505 100644 --- a/library/think/model/relation/HasManyThrough.php +++ b/library/think/model/relation/HasManyThrough.php @@ -54,19 +54,6 @@ class HasManyThrough extends Relation return $this->select(); } - /** - * 预载入关联查询 - * @access public - * @param Query $query 查询对象 - * @param string $relation 关联名 - * @param bool $first 是否需要使用基础表 - * @return void - */ - public function eagerly(Query $query, $relation, $subRelation, $closure, $first) - { - - } - /** * 预载入关联查询 * @access public @@ -79,7 +66,6 @@ class HasManyThrough extends Relation */ public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class) { - } /** @@ -94,7 +80,6 @@ class HasManyThrough extends Relation */ public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class) { - } /** diff --git a/library/think/model/relation/MorphTo.php b/library/think/model/relation/MorphTo.php index 2b370e08..6de1d4f4 100644 --- a/library/think/model/relation/MorphTo.php +++ b/library/think/model/relation/MorphTo.php @@ -73,12 +73,14 @@ class MorphTo extends Relation } /** - * 预载入关联查询 返回数据集 + * 预载入关联查询 * @access public * @param array $resultSet 数据集 - * @param string $relation 关联名 + * @param string $relation 当前关联名 + * @param string $subRelation 子关联名 + * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 - * @return array + * @return void */ public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class) { @@ -116,12 +118,14 @@ class MorphTo extends Relation } /** - * 预载入关联查询 返回模型对象 + * 预载入关联查询 * @access public * @param Model $result 数据对象 - * @param string $relation 关联名 + * @param string $relation 当前关联名 + * @param string $subRelation 子关联名 + * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 - * @return Model + * @return void */ public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class) { @@ -139,7 +143,7 @@ class MorphTo extends Relation * @param array $where 关联预查询条件 * @param string $relation 关联名 * @param string $subRelation 子关联 - * @return array + * @return void */ protected function eagerlyMorphToOne($model, $relation, &$result, $subRelation = '') { -- Gitee From 30077757bdf99f360ce529c600118ea2037a4347 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 5 Dec 2016 12:12:33 +0800 Subject: [PATCH 0210/1170] =?UTF-8?q?Model=E7=B1=BB=E5=A2=9E=E5=8A=A0toCol?= =?UTF-8?q?lection=E6=96=B9=E6=B3=95=20=E7=94=A8=E4=BA=8E=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E6=95=B0=E6=8D=AE=E9=9B=86=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 0a3a35f5..6a6841a6 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -13,6 +13,7 @@ namespace think; use InvalidArgumentException; use think\Cache; +use think\Collection; use think\Config; use think\Db; use think\db\Query; @@ -565,6 +566,17 @@ abstract class Model implements \JsonSerializable, \ArrayAccess return json_encode($this->toArray(), $options); } + /** + * 转换当前模型数据集为数据集对象 + * @access public + * @param array|Collection $collection 数据集 + * @return Collection + */ + public function toCollection($collection) + { + return new Collection($collection); + } + /** * 获取模型对象的主键 * @access public @@ -1200,6 +1212,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @access public * @param array $resultSet 数据集 * @param string $relation 关联名 + * @param string $class 数据集对象名 为空表示数组 * @return array */ public function eagerlyResultSet(&$resultSet, $relation, $class = '') @@ -1224,6 +1237,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @access public * @param Model $result 数据对象 * @param string $relation 关联名 + * @param string $class 数据集对象名 为空表示数组 * @return Model */ public function eagerlyResult(&$result, $relation, $class = '') @@ -1252,7 +1266,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @param string $localKey 关联主键 * @param array $alias 别名定义 * @param string $joinType JOIN类型 - * @return Relation + * @return HasOne */ public function hasOne($model, $foreignKey = '', $localKey = '', $alias = [], $joinType = 'INNER') { @@ -1271,7 +1285,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @param string $otherKey 关联主键 * @param array $alias 别名定义 * @param string $joinType JOIN类型 - * @return Relation + * @return BelongsTo */ public function belongsTo($model, $foreignKey = '', $otherKey = '', $alias = [], $joinType = 'INNER') { @@ -1289,7 +1303,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @param string $foreignKey 关联外键 * @param string $localKey 关联主键 * @param array $alias 别名定义 - * @return Relation + * @return HasMany */ public function hasMany($model, $foreignKey = '', $localKey = '', $alias = []) { @@ -1309,7 +1323,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @param string $throughKey 关联外键 * @param string $localKey 关联主键 * @param array $alias 别名定义 - * @return Relation + * @return HasManyThrough */ public function hasManyThrough($model, $through, $foreignKey = '', $throughKey = '', $localKey = '', $alias = []) { @@ -1331,7 +1345,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @param string $foreignKey 关联外键 * @param string $localKey 当前模型关联键 * @param array $alias 别名定义 - * @return Relation + * @return BelongsToMany */ public function belongsToMany($model, $table = '', $foreignKey = '', $localKey = '', $alias = []) { @@ -1347,10 +1361,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess /** * MORPH MANY 关联定义 * @access public - * @param string $model 模型名 - * @param string|array $morph 多态字段信息 - * @param string $type 多态类型 - * @return Relation + * @param string $model 模型名 + * @param string|array $morph 多态字段信息 + * @param string $type 多态类型 + * @return MorphMany */ public function morphMany($model, $morph = null, $type = '') { @@ -1375,7 +1389,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @access public * @param string|array $morph 多态字段信息 * @param array $alias 多态别名定义 - * @return Relation + * @return MorphTo */ public function morphTo($morph = null, $alias = []) { -- Gitee From 405825ff8a1db02736df2e6b9dc8debae9b3840c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 5 Dec 2016 16:24:02 +0800 Subject: [PATCH 0211/1170] =?UTF-8?q?Model=E7=B1=BB=E5=A2=9E=E5=8A=A0resul?= =?UTF-8?q?tSetType=E5=B1=9E=E6=80=A7=20=E7=94=A8=E4=BA=8E=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E6=A8=A1=E5=9E=8B=E6=9F=A5=E8=AF=A2=E7=9A=84=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E9=9B=86=E5=AF=B9=E8=B1=A1=EF=BC=88=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA=E8=BF=94=E5=9B=9E=E6=95=B0=E7=BB=84=EF=BC=89?= =?UTF-8?q?=20Db=E7=B1=BB=E6=9F=A5=E8=AF=A2=E4=B8=8D=E5=86=8D=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=AE=BE=E7=BD=AE=E8=87=AA=E5=AE=9A=E4=B9=89=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E9=9B=86=E5=AF=B9=E8=B1=A1=EF=BC=88=E5=8F=AA=E8=83=BD?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=95=B0=E7=BB=84=E6=88=96=E8=80=85think\Col?= =?UTF-8?q?lection=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 12 +++++++++++- library/think/db/Connection.php | 5 +---- library/think/db/Query.php | 31 +++++++++++-------------------- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 6a6841a6..68688759 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -111,6 +111,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess protected $useGlobalScope = true; // 是否采用批量验证 protected $batchValidate = false; + // 查询数据集对象 + protected $resultSetType; /** * 初始化过的模型. @@ -574,7 +576,15 @@ abstract class Model implements \JsonSerializable, \ArrayAccess */ public function toCollection($collection) { - return new Collection($collection); + if ($this->resultSetType) { + if ('collection' == $this->resultSetType) { + $collection = new Collection($collection); + } else { + $class = $this->resultSetType; + $collection = new $class($collection); + } + } + return $collection; } /** diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index d9b7978f..f7d33161 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -489,10 +489,7 @@ abstract class Connection $result = $this->PDOStatement->fetchAll($this->fetchType); $this->numRows = count($result); - if (!empty($class)) { - // 返回指定数据集对象类 - $result = new $class($result); - } elseif ('collection' == $this->resultSetType) { + if ('collection' == $this->resultSetType) { // 返回数据集Collection对象 $result = new Collection($result); } diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 4d63ba14..a2c0f211 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1318,18 +1318,6 @@ class Query return $this; } - /** - * 指定数据集返回对象 - * @access public - * @param string $class 指定返回的数据集对象类名 - * @return $this - */ - public function fetchClass($class) - { - $this->options['fetch_class'] = $class; - return $this; - } - /** * 设置从主服务器读取数据 * @access public @@ -1967,12 +1955,11 @@ class Query } } - // 返回结果处理 - if (count($resultSet) > 0) { - // 数据列表读取后的处理 - if (!empty($this->model)) { - // 生成模型对象 - $model = $this->model; + // 数据列表读取后的处理 + if (!empty($this->model)) { + // 生成模型对象 + $model = $this->model; + if (count($resultSet) > 0) { foreach ($resultSet as $key => $result) { /** @var Model $result */ $result = new $model($result); @@ -1983,12 +1970,16 @@ class Query } $resultSet[$key] = $result; } - if (!empty($options['with']) && $result instanceof Model) { + if (!empty($options['with'])) { // 预载入 $result->eagerlyResultSet($resultSet, $options['with'], is_object($resultSet) ? get_class($resultSet) : ''); } } - } elseif (!empty($options['fail'])) { + // 模型数据集转换 + $resultSet = (new $model)->toCollection($resultSet); + } + // 返回结果处理 + if (!empty($options['fail']) && count($resultSet) == 0) { $this->throwNotFound($options); } return $resultSet; -- Gitee From 7f3fe01504f9f2307254764981884afef25eca26 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 5 Dec 2016 16:25:46 +0800 Subject: [PATCH 0212/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BValidate=E7=B1=BB?= =?UTF-8?q?=E7=9A=84getRuleMsg=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index 675af8f5..84546464 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -1198,7 +1198,7 @@ class Validate $msg = $title . '规则错误'; } - if (is_string($msg) && strpos($msg, '{%')) { + if (is_string($msg) && 0 === strpos($msg, '{%')) { $msg = Lang::get(substr($msg, 2, -1)); } -- Gitee From 84f9ffab46897635558b26170287c794cd8869a8 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 5 Dec 2016 16:36:50 +0800 Subject: [PATCH 0213/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E8=A1=8C=E4=B8=8B=E7=9A=84=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Log.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/think/Log.php b/library/think/Log.php index 943e78c8..413e2761 100644 --- a/library/think/Log.php +++ b/library/think/Log.php @@ -84,6 +84,10 @@ class Log public static function record($msg, $type = 'log') { self::$log[$type][] = $msg; + if (IS_CLI && count(self::$log[$type]) > 100) { + // 命令行下面日志写入改进 + self::save(); + } } /** -- Gitee From 32c2f5799baf19455dbd47ae2247a27d2bfdc839 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 5 Dec 2016 16:48:18 +0800 Subject: [PATCH 0214/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=AD=90=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E4=BD=9C=E4=B8=BA=E8=A1=A8=E5=90=8D=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index a2c0f211..6b6b5d10 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1449,6 +1449,11 @@ class Query $tableName = $this->parseSqlTable($tableName); } + // 修正子查询作为表名的问题 + if (strpos($tableName, ')')) { + return []; + } + list($guid) = explode(' ', $tableName); $db = $this->getConfig('database'); if (!isset(self::$info[$db . '.' . $guid])) { -- Gitee From 47ad3507d517778fcc8d7d9a8e8c22881b7e4001 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 6 Dec 2016 07:50:08 +0800 Subject: [PATCH 0215/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BTemplate=E7=B1=BBpa?= =?UTF-8?q?rseTemplateFile=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Template.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Template.php b/library/think/Template.php index 944bf33d..03137be8 100644 --- a/library/think/Template.php +++ b/library/think/Template.php @@ -1072,7 +1072,7 @@ class Template $module = isset($module) ? $module : Request::instance()->module(); $path = $this->config['view_base'] . ($module ? $module . DS : ''); } else { - $path = $this->config['view_path']; + $path = isset($module) ? APP_PATH . $module . 'view' . DS : $this->config['view_path']; } $template = $path . $template . '.' . ltrim($this->config['view_suffix'], '.'); } -- Gitee From 57fe06a11b4e040901297937b0387716d050d1f3 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 6 Dec 2016 07:52:47 +0800 Subject: [PATCH 0216/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BModel=E7=B1=BB?= =?UTF-8?q?=E7=9A=84useGlobalScope=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 68688759..404e63de 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -113,6 +113,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess protected $batchValidate = false; // 查询数据集对象 protected $resultSetType; + // + protected static $db; /** * 初始化过的模型. @@ -1149,8 +1151,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess */ public static function useGlobalScope($use) { - $model = new static(); - $model->useGlobalScope = $use; + $model = new static(); + self::$db = $model->db($use); return $model; } @@ -1433,7 +1435,12 @@ abstract class Model implements \JsonSerializable, \ArrayAccess public static function __callStatic($method, $params) { - $query = (new static())->db(); + if (isset(static::$db)) { + $query = static::$db; + } else { + $query = (new static())->db(); + } + return call_user_func_array([$query, $method], $params); } -- Gitee From b7f7a8a2a764cc92c5398930a01ed1767d93e295 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 6 Dec 2016 08:07:09 +0800 Subject: [PATCH 0217/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=A4=9A=E8=A1=A8?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=9A=84=E5=AD=97=E6=AE=B5=E4=B8=8D=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Builder.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index c60d139a..f830d876 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -90,7 +90,7 @@ abstract class Builder $result = []; foreach ($data as $key => $val) { $item = $this->parseKey($key, $options); - if (!in_array($key, $fields, true)) { + if (false === strpos($key, '.') && !in_array($key, $fields, true)) { if ($options['strict']) { throw new Exception('fields not exists:[' . $key . ']'); } @@ -100,9 +100,10 @@ abstract class Builder $result[$item] = 'NULL'; } elseif (is_scalar($val)) { // 过滤非标量数据 - if ($this->query->isBind(substr($val, 1))) { + if (0 === strpos($val, ':') && $this->query->isBind(substr($val, 1))) { $result[$item] = $val; } else { + $key = str_replace('.', '_', $key); $this->query->bind($key, $val, isset($bind[$key]) ? $bind[$key] : PDO::PARAM_STR); $result[$item] = ':' . $key; } -- Gitee From 3e53f0f4529014ae3bd6812af4054172f5133989 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 6 Dec 2016 08:13:27 +0800 Subject: [PATCH 0218/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Template=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Template.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Template.php b/library/think/Template.php index 03137be8..e73bbcf8 100644 --- a/library/think/Template.php +++ b/library/think/Template.php @@ -1072,7 +1072,7 @@ class Template $module = isset($module) ? $module : Request::instance()->module(); $path = $this->config['view_base'] . ($module ? $module . DS : ''); } else { - $path = isset($module) ? APP_PATH . $module . 'view' . DS : $this->config['view_path']; + $path = isset($module) ? APP_PATH . $module . DS . basename($this->config['view_path']) . DS : $this->config['view_path']; } $template = $path . $template . '.' . ltrim($this->config['view_suffix'], '.'); } -- Gitee From 4ebd16f8efd5ce792efb31a1e108aa927f361191 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 6 Dec 2016 13:59:37 +0800 Subject: [PATCH 0219/1170] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Validate=E7=B1=BB?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E9=AA=8C=E8=AF=81=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E7=9A=84=E6=9B=BF=E6=8D=A2=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 1 + 1 file changed, 1 insertion(+) diff --git a/library/think/Validate.php b/library/think/Validate.php index 84546464..3f9b2589 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -408,6 +408,7 @@ class Validate return $message; } elseif (true !== $result) { // 返回自定义错误信息 + $result = str_replace([':attribute', ':rule'], [$title, (string) $rule], $result); return $result; } $i++; -- Gitee From 1cff11b9cc2548d19180f34a9adf5f72bbd8de73 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 6 Dec 2016 14:07:08 +0800 Subject: [PATCH 0220/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E9=94=99=E8=AF=AF=E4=BF=A1=E6=81=AF=E7=9A=84=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index 3f9b2589..e2b07875 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -408,7 +408,9 @@ class Validate return $message; } elseif (true !== $result) { // 返回自定义错误信息 - $result = str_replace([':attribute', ':rule'], [$title, (string) $rule], $result); + if (is_string($result) && false !== strpos($result, ':')) { + $result = str_replace([':attribute', ':rule'], [$title, (string) $rule], $result); + } return $result; } $i++; -- Gitee From 7ce4d935f66592b87e6edc676b81617e29c9e089 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 6 Dec 2016 14:23:08 +0800 Subject: [PATCH 0221/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9Bconfirm=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E8=A7=84=E5=88=99=20=E6=94=AF=E6=8C=81=20password=20?= =?UTF-8?q?=E5=8F=8A=20password=5Fconfirm=20=E8=87=AA=E5=8A=A8=E8=A7=84?= =?UTF-8?q?=E5=88=99=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index e2b07875..101bb2ef 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -422,13 +422,21 @@ class Validate /** * 验证是否和某个字段的值一致 * @access protected - * @param mixed $value 字段值 + * @param mixed $value 字段值 * @param mixed $rule 验证规则 * @param array $data 数据 + * @param string $field 字段名 * @return bool */ - protected function confirm($value, $rule, $data) + protected function confirm($value, $rule, $data, $field) { + if ('' == $rule) { + if (strpos($field, '_confirm')) { + $rule = strstr($field, '_confirm', true); + } else { + $rule = $field . '_confirm'; + } + } return $this->getDataValue($data, $rule) == $value; } -- Gitee From 0788e048a7e92916e7ca7d1531cbd13d9dfa71c6 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 6 Dec 2016 16:42:32 +0800 Subject: [PATCH 0222/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BResponse=E7=B1=BB?= =?UTF-8?q?=E7=9A=84send=E6=96=B9=E6=B3=95=20=E5=BD=93=E4=B8=BA=E9=87=8D?= =?UTF-8?q?=E5=AE=9A=E5=90=91=E7=9A=84=E6=97=B6=E5=80=99=E4=B8=8D=E6=B8=85?= =?UTF-8?q?=E7=A9=BA=E5=BD=93=E6=AC=A1=E6=9C=89=E6=95=88=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Response.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/think/Response.php b/library/think/Response.php index 2b84ed17..e0f5d7e2 100644 --- a/library/think/Response.php +++ b/library/think/Response.php @@ -133,7 +133,9 @@ class Response Hook::listen('response_end', $this); // 清空当次请求有效的数据 - Session::flush(); + if (!($this instanceof RedirectResponse)) { + Session::flush(); + } } /** -- Gitee From 4780d194b52a5bf4aefba950f1c2e5c71c1ecf9b Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 7 Dec 2016 07:16:50 +0800 Subject: [PATCH 0223/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E6=93=8D=E4=BD=9Cjoin=E8=87=AA=E8=BA=AB=E5=90=8E?= =?UTF-8?q?=E5=87=BA=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Builder.php | 3 +++ library/think/db/Query.php | 3 +++ 2 files changed, 6 insertions(+) diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index f830d876..9c9ceb63 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -183,6 +183,9 @@ abstract class Builder $item = []; foreach ((array) $tables as $key => $table) { if (!is_numeric($key)) { + if (strpos($key, '@think')) { + $key = strstr($key, '@think', true); + } $key = $this->parseSqlTable($key); $item[] = $this->parseKey($key) . ' ' . $this->parseKey($table); } else { diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 6b6b5d10..1135a3d2 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -716,6 +716,9 @@ class Query } } if (isset($alias)) { + if (isset($this->options['alias'][$table])) { + $table = $table . '@think' . uniqid(); + } $table = [$table => $alias]; $this->alias($table); } -- Gitee From cc573e4dbaaa7af0522c1e96c522d208bf432c72 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 7 Dec 2016 07:27:04 +0800 Subject: [PATCH 0224/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BModel=E7=B1=BBsave?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=86=99=E5=85=A5=E5=AF=B9=E4=B8=BB=E9=94=AE?= =?UTF-8?q?=E5=80=BC=E7=9A=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Model.php b/library/think/Model.php index 404e63de..93953f2c 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -728,7 +728,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $result = $this->db()->insert($this->data); // 获取自动增长主键 - if ($result && is_string($pk) && !isset($this->data[$pk])) { + if ($result && is_string($pk) && (!isset($this->data[$pk]) || '' == $this->data[$pk])) { $insertId = $this->db()->getLastInsID($sequence); if ($insertId) { $this->data[$pk] = $insertId; -- Gitee From bf3797dedab64e07d171d8146249cfdd1d683f99 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 7 Dec 2016 07:41:48 +0800 Subject: [PATCH 0225/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=97=AD=E5=8C=85?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Builder.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index 9c9ceb63..dd50b2b7 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -330,7 +330,9 @@ abstract class Builder } elseif (in_array($exp, ['NOT IN', 'IN'])) { // IN 查询 if ($value instanceof \Closure) { + $query = $this->query; $whereStr .= $key . ' ' . $exp . ' ' . $this->parseClosure($value); + $this->query = $query; } else { $value = is_array($value) ? $value : explode(',', $value); if (array_key_exists($field, $binds)) { @@ -376,7 +378,9 @@ abstract class Builder } elseif (in_array($exp, ['NOT EXISTS', 'EXISTS'])) { // EXISTS 查询 if ($value instanceof \Closure) { + $query = $this->query; $whereStr .= $exp . ' ' . $this->parseClosure($value); + $this->query = $query; } else { $whereStr .= $exp . ' (' . $value . ')'; } -- Gitee From 0428e1b120e932365830acba0ef8cbc4616f70f7 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 7 Dec 2016 07:47:35 +0800 Subject: [PATCH 0226/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BRequest=E7=B1=BB?= =?UTF-8?q?=E7=9A=84file=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/think/Request.php b/library/think/Request.php index 79c349f8..a30180a8 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -852,7 +852,7 @@ class Request $keys = array_keys($file); $count = count($file['name']); for ($i = 0; $i < $count; $i++) { - if (empty($file['tmp_name'][$i])) { + if (empty($file['tmp_name'][$i]) || !is_file($file['tmp_name'][$i])) { continue; } $temp['key'] = $key; @@ -866,7 +866,7 @@ class Request if ($file instanceof File) { $array[$key] = $file; } else { - if (empty($file['tmp_name'])) { + if (empty($file['tmp_name']) || !is_file($file['tmp_name'])) { continue; } $array[$key] = (new File($file['tmp_name']))->setUploadInfo($file); -- Gitee From 024f75c84675393f4482dfe330aef7221341cabc Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 7 Dec 2016 08:13:15 +0800 Subject: [PATCH 0227/1170] =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E7=9A=84=E6=B3=9B=E5=9F=9F=E5=90=8D=E5=88=B0=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E4=B8=AD=20=E5=8F=98=E9=87=8F=E5=90=8D?= =?UTF-8?q?=E4=B8=BA=5F=5Fdomain=5F=5F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/think/Route.php b/library/think/Route.php index e2ebd655..d3272071 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -770,6 +770,10 @@ class Route } } if (!empty($item)) { + if (isset($panDomain)) { + // 保存当前泛域名 + $request->route(['__domain__' => $panDomain]); + } if (isset($item['[bind]'])) { // 解析子域名部署规则 list($rule, $option, $pattern) = $item['[bind]']; -- Gitee From e0d23618b6f358456b4e56bed729c076447bece4 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 7 Dec 2016 11:18:04 +0800 Subject: [PATCH 0228/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BB?= =?UTF-8?q?=E7=9A=84column=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 1135a3d2..9f43f25a 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -469,6 +469,9 @@ class Query $key1 = array_shift($fields); $key2 = $fields ? array_shift($fields) : ''; $key = $key ?: $key1; + if (strpos($key, '.')) { + list($alias, $key) = explode('.', $key); + } foreach ($resultSet as $val) { if ($count > 2) { $result[$val[$key]] = $val; -- Gitee From 73c47acef89f353b1546203976622d7c20095221 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 7 Dec 2016 12:14:31 +0800 Subject: [PATCH 0229/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BB?= =?UTF-8?q?=E5=92=8CBuilder=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Builder.php | 29 ++++++++++------- library/think/db/Query.php | 62 ++++++++++++++++++++---------------- 2 files changed, 52 insertions(+), 39 deletions(-) diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index dd50b2b7..406da565 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -37,22 +37,33 @@ abstract class Builder /** * 架构函数 * @access public - * @param Connection $connection 数据库连接对象实例 + * @param Connection $connection 数据库连接对象实例 + * @param Query $query 数据库查询对象实例 */ - public function __construct(Connection $connection) + public function __construct(Connection $connection, Query $query) { $this->connection = $connection; + $this->query = $query; } /** - * 设置当前的Query对象实例 - * @access protected - * @param Query $query 当前查询对象实例 + * 获取当前的连接对象实例 + * @access public + * @return void + */ + public function getConnection() + { + return $this->connection; + } + + /** + * 获取当前的Query对象实例 + * @access public * @return void */ - public function setQuery(Query $query) + public function getQuery() { - $this->query = $query; + return $this->query; } /** @@ -330,9 +341,7 @@ abstract class Builder } elseif (in_array($exp, ['NOT IN', 'IN'])) { // IN 查询 if ($value instanceof \Closure) { - $query = $this->query; $whereStr .= $key . ' ' . $exp . ' ' . $this->parseClosure($value); - $this->query = $query; } else { $value = is_array($value) ? $value : explode(',', $value); if (array_key_exists($field, $binds)) { @@ -378,9 +387,7 @@ abstract class Builder } elseif (in_array($exp, ['NOT EXISTS', 'EXISTS'])) { // EXISTS 查询 if ($value instanceof \Closure) { - $query = $this->query; $whereStr .= $exp . ' ' . $this->parseClosure($value); - $this->query = $query; } else { $whereStr .= $exp . ' (' . $value . ')'; } diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 9f43f25a..f0e1ae5b 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -35,7 +35,7 @@ class Query { // 数据库Connection对象实例 protected $connection; - // 数据库驱动类型 + // 数据库Builder对象实例 protected $builder; // 当前模型类名称 protected $model; @@ -63,9 +63,10 @@ class Query public function __construct(Connection $connection = null, $model = '') { $this->connection = $connection ?: Db::connect([], true); - $this->builder = $this->connection->getConfig('builder') ?: $this->connection->getConfig('type'); $this->prefix = $this->connection->getConfig('prefix'); $this->model = $model; + // 设置当前连接的Builder对象 + $this->setBuilder(); } /** @@ -113,19 +114,42 @@ class Query public function connect($config) { $this->connection = Db::connect($config); + $this->setBuilder(); return $this; } + /** + * 设置当前的数据库Builder对象 + * @access protected + * @return void + */ + protected function setBuilder() + { + $builder = $this->connection->getConfig('builder') ?: $this->connection->getConfig('type'); + $class = false !== strpos($builder, '\\') ? $builder : '\\think\\db\\builder\\' . ucfirst($builder); + $this->builder = new $class($this->connection, $this); + } + /** * 获取当前的模型对象名 * @access public - * @return Connection + * @return string */ public function getModel() { return $this->model; } + /** + * 获取当前的builder实例对象 + * @access public + * @return Builder + */ + public function getBuilder() + { + return $this->builder; + } + /** * 指定默认的数据表名(不含前缀) * @access public @@ -362,24 +386,6 @@ class Query } } - /** - * 获取当前的builder实例对象 - * @access protected - * @return Builder - */ - protected function builder() - { - static $builder = []; - $driver = $this->builder; - if (!isset($builder[$driver])) { - $class = false !== strpos($driver, '\\') ? $driver : '\\think\\db\\builder\\' . ucfirst($driver); - $builder[$driver] = new $class($this->connection); - } - // 设置当前查询对象 - $builder[$driver]->setQuery($this); - return $builder[$driver]; - } - /** * 得到某个字段的值 * @access public @@ -1758,7 +1764,7 @@ class Query // 分析查询表达式 $options = $this->parseExpress(); // 生成SQL语句 - $sql = $this->builder()->insert($data, $options, $replace); + $sql = $this->builder->insert($data, $options, $replace); // 获取参数绑定 $bind = $this->getBind(); if ($options['fetch_sql']) { @@ -1802,7 +1808,7 @@ class Query return false; } // 生成SQL语句 - $sql = $this->builder()->insertAll($dataSet, $options); + $sql = $this->builder->insertAll($dataSet, $options); // 获取参数绑定 $bind = $this->getBind(); if ($options['fetch_sql']) { @@ -1828,7 +1834,7 @@ class Query $options = $this->parseExpress(); // 生成SQL语句 $table = $this->parseSqlTable($table); - $sql = $this->builder()->selectInsert($fields, $table, $options); + $sql = $this->builder->selectInsert($fields, $table, $options); // 获取参数绑定 $bind = $this->getBind(); if ($options['fetch_sql']) { @@ -1886,7 +1892,7 @@ class Query $key = 'think:' . $options['table'] . '|' . $options['where']['AND'][$pk]; } // 生成UPDATE SQL语句 - $sql = $this->builder()->update($data, $options); + $sql = $this->builder->update($data, $options); // 获取参数绑定 $bind = $this->getBind(); if ($options['fetch_sql']) { @@ -1941,7 +1947,7 @@ class Query } if (!$resultSet) { // 生成查询SQL - $sql = $this->builder()->select($options); + $sql = $this->builder->select($options); // 获取参数绑定 $bind = $this->getBind(); if ($options['fetch_sql']) { @@ -2035,7 +2041,7 @@ class Query } if (!$result) { // 生成查询SQL - $sql = $this->builder()->select($options); + $sql = $this->builder->select($options); // 获取参数绑定 $bind = $this->getBind(); if ($options['fetch_sql']) { @@ -2231,7 +2237,7 @@ class Query throw new Exception('delete without condition'); } // 生成删除SQL语句 - $sql = $this->builder()->delete($options); + $sql = $this->builder->delete($options); // 获取参数绑定 $bind = $this->getBind(); if ($options['fetch_sql']) { -- Gitee From 90b0da7bede6b705a4c53d0e59eab386305e0091 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 7 Dec 2016 15:33:15 +0800 Subject: [PATCH 0230/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BModel=E7=B1=BBsetAt?= =?UTF-8?q?tr=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/think/Model.php b/library/think/Model.php index 93953f2c..4176a12d 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -292,7 +292,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess } // 标记字段更改 - if (!isset($this->data[$name]) || (0 !== strcmp($this->data[$name], $value) && !in_array($name, $this->change))) { + if (isset($this->data[$name]) && is_scalar($this->data[$name]) && is_scalar($value) && 0 !== strcmp($this->data[$name], $value)) { + $this->change[] = $name; + } elseif (!isset($this->data[$name]) || $value != $this->data[$name]) { $this->change[] = $name; } // 设置数据对象属性 -- Gitee From c951001f6c7d85d7bc05604d6e5a701635840622 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 7 Dec 2016 17:00:25 +0800 Subject: [PATCH 0231/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BResponse=E7=B1=BBge?= =?UTF-8?q?tHeader=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Response.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/think/Response.php b/library/think/Response.php index e0f5d7e2..a7ebecf7 100644 --- a/library/think/Response.php +++ b/library/think/Response.php @@ -284,7 +284,11 @@ class Response */ public function getHeader($name = '') { - return !empty($name) ? $this->header[$name] : $this->header; + if (!empty($name)) { + return isset($this->header[$name]) ? $this->header[$name] : null; + } else { + return $this->header; + } } /** -- Gitee From 275d04d316dee56ece9d65051f8229d55f183971 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 7 Dec 2016 18:17:45 +0800 Subject: [PATCH 0232/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=A4=9A=E5=AF=B9?= =?UTF-8?q?=E5=A4=9A=E5=85=B3=E8=81=94=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/relation/BelongsToMany.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index 486f08d8..b5d21680 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -256,8 +256,7 @@ class BelongsToMany extends Relation $pk = $this->parent->getPk(); $pivot[$this->localKey] = $this->parent->$pk; $pivot[$this->foreignKey] = $id; - $query = clone $this->parent->db(); - return $query->table($this->middle)->insert($pivot); + return $this->query->table($this->middle)->insert($pivot); } else { throw new Exception('miss relation data'); } @@ -288,8 +287,7 @@ class BelongsToMany extends Relation if (isset($id)) { $pivot[$this->foreignKey] = is_array($id) ? ['in', $id] : $id; } - $query = clone $this->parent->db(); - $query->table($this->middle)->where($pivot)->delete(); + $this->query->table($this->middle)->where($pivot)->delete(); // 删除关联表数据 if (isset($id) && $relationDel) { -- Gitee From 89239cceb47e84dfbeba877add82cc15185cafa9 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 7 Dec 2016 18:18:38 +0800 Subject: [PATCH 0233/1170] =?UTF-8?q?Model=E7=B1=BB=E7=9A=84append=20hidde?= =?UTF-8?q?n=E5=92=8Cvisible=20=E6=96=B9=E6=B3=95=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E4=BC=9A=E5=92=8C=E5=B1=9E=E6=80=A7=E8=AE=BE=E7=BD=AE=E5=90=88?= =?UTF-8?q?=E5=B9=B6=20=E5=A2=9E=E5=8A=A0=E7=AC=AC=E4=BA=8C=E4=B8=AA?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E7=94=A8=E4=BA=8E=E8=A6=86=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 4176a12d..2b7f3ae3 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -487,11 +487,12 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * 设置需要追加的输出属性 * @access public * @param array $append 属性列表 + * @param bool $override 是否覆盖 * @return $this */ - public function append($append = []) + public function append($append = [], $override = false) { - $this->append = $append; + $this->append = $override ? $append : array_merge($this->append, $append); return $this; } @@ -499,22 +500,24 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * 设置需要隐藏的输出属性 * @access public * @param array $hidden 属性列表 + * @param bool $override 是否覆盖 * @return $this */ - public function hidden($hidden = []) + public function hidden($hidden = [], $override = false) { - $this->hidden = $hidden; + $this->hidden = $override ? $hidden : array_merge($this->hidden, $hidden); return $this; } /** * 设置需要输出的属性 * @param array $visible + * @param bool $override 是否覆盖 * @return $this */ - public function visible($visible = []) + public function visible($visible = [], $override = false) { - $this->visible = $visible; + $this->visible = $override ? $visible : array_merge($this->visible, $visible); return $this; } -- Gitee From 501cc852077fa21b7e97d2dc581fb2770a6d212a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 8 Dec 2016 11:04:39 +0800 Subject: [PATCH 0234/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BPhp=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E5=BC=95=E6=93=8E=E9=A9=B1=E5=8A=A8=E7=9A=84=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E5=AE=9A=E4=BD=8D=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convention.php | 4 +++- library/think/view/driver/Php.php | 20 ++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/convention.php b/convention.php index 8eb30f43..487c2481 100644 --- a/convention.php +++ b/convention.php @@ -115,7 +115,9 @@ return [ 'template' => [ // 模板引擎类型 支持 php think 支持扩展 'type' => 'Think', - // 模板路径 + // 视图基础目录,配置目录为所有模块的视图起始目录 + 'view_base' => '', + // 当前模板的视图目录 留空为自动获取 'view_path' => '', // 模板后缀 'view_suffix' => 'html', diff --git a/library/think/view/driver/Php.php b/library/think/view/driver/Php.php index 4f3d7e85..863a7c17 100644 --- a/library/think/view/driver/Php.php +++ b/library/think/view/driver/Php.php @@ -21,6 +21,8 @@ class Php { // 模板引擎参数 protected $config = [ + // 视图基础目录(集中式) + 'view_base' => '', // 模板起始路径 'view_path' => '', // 模板文件后缀 @@ -109,20 +111,26 @@ class Php $this->config['view_path'] = App::$modulePath . 'view' . DS; } + $request = Request::instance(); + // 获取视图根目录 if (strpos($template, '@')) { + // 跨模块调用 list($module, $template) = explode('@', $template); - $path = APP_PATH . $module . DS . 'view' . DS; + } + if ($this->config['view_base']) { + // 基础视图目录 + $module = isset($module) ? $module : $request->module(); + $path = $this->config['view_base'] . ($module ? $module . DS : ''); } else { - $path = $this->config['view_path']; + $path = isset($module) ? APP_PATH . $module . DS . 'view' . DS : $this->config['view_path']; } - // 分析模板文件规则 - $request = Request::instance(); - $controller = Loader::parseName($request->controller()); - $depr = $this->config['view_depr']; + $depr = $this->config['view_depr']; if (0 !== strpos($template, '/')) { $template = str_replace(['/', ':'], $depr, $template); } + + $controller = Loader::parseName($request->controller()); if ($controller) { if ('' == $template) { // 如果模板文件名为空 按照默认规则定位 -- Gitee From 6ba9c88c95517b1f4e019c00dc76766ae48ad54d Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 8 Dec 2016 13:34:04 +0800 Subject: [PATCH 0235/1170] =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=B1=BB=E7=9A=84c?= =?UTF-8?q?onfirm=E6=96=B9=E6=B3=95field=E5=8F=82=E6=95=B0=E5=8F=AF?= =?UTF-8?q?=E9=80=89=20=E4=BE=BF=E4=BA=8E=E9=9D=99=E6=80=81=E9=AA=8C?= =?UTF-8?q?=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index 101bb2ef..5bc1e944 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -428,7 +428,7 @@ class Validate * @param string $field 字段名 * @return bool */ - protected function confirm($value, $rule, $data, $field) + protected function confirm($value, $rule, $data, $field = '') { if ('' == $rule) { if (strpos($field, '_confirm')) { -- Gitee From 3e22f21d34acd9b4e3ebbd201283b9e6d3856926 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 8 Dec 2016 17:03:32 +0800 Subject: [PATCH 0236/1170] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E6=9B=BF=E6=8D=A2=E5=AD=97=E7=AC=A6=E4=B8=B2?= =?UTF-8?q?=20=5F=5FROOT=5F=5F=20=5F=5FSTATIC=5F=5F=20=5F=5FJS=5F=5F=20=5F?= =?UTF-8?q?=5FCSS=5F=5F=20=5F=5FURL=5F=5F=20=E9=83=BD=E4=B8=8D=E5=B8=A6?= =?UTF-8?q?=E5=9F=9F=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/View.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/library/think/View.php b/library/think/View.php index 5fb9a142..ede7cd44 100644 --- a/library/think/View.php +++ b/library/think/View.php @@ -11,6 +11,9 @@ namespace think; +use think\Loader; +use think\Request; + class View { // 视图实例 @@ -30,11 +33,25 @@ class View * @param array $engine 模板引擎参数 * @param array $replace 字符串替换参数 */ - public function __construct($engine = [], $replace = []) + public function __construct($engine = [], array $replace = []) { // 初始化模板引擎 $this->engine((array) $engine); - $this->replace = $replace; + // 基础替换字符串 + $request = Request::instance(); + $base = $request->root(); + $root = strpos($base, '.') ? dirname($base) : $base; + if ('' != $root) { + $root = '/' . $root; + } + $baseReplace = [ + '__ROOT__' => $root, + '__URL__' => $base . '/' . $request->module() . '/' . Loader::parseName($request->controller()), + '__STATIC__' => $root . '/static', + '__CSS__' => $root . '/static/css', + '__JS__' => $root . '/static/js', + ]; + $this->replace = array_merge($baseReplace, $replace); } /** -- Gitee From d585442edab553f38ac25851580c3237049f018f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 8 Dec 2016 17:08:41 +0800 Subject: [PATCH 0237/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/View.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/View.php b/library/think/View.php index ede7cd44..52aa9cd7 100644 --- a/library/think/View.php +++ b/library/think/View.php @@ -33,7 +33,7 @@ class View * @param array $engine 模板引擎参数 * @param array $replace 字符串替换参数 */ - public function __construct($engine = [], array $replace = []) + public function __construct($engine = [], $replace = []) { // 初始化模板引擎 $this->engine((array) $engine); -- Gitee From 57d78c4dbd5d619369d6df7072eb60ea71db238c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 8 Dec 2016 17:15:33 +0800 Subject: [PATCH 0238/1170] =?UTF-8?q?=E7=BB=A7=E7=BB=AD=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/View.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/View.php b/library/think/View.php index 52aa9cd7..6edd69a0 100644 --- a/library/think/View.php +++ b/library/think/View.php @@ -51,7 +51,7 @@ class View '__CSS__' => $root . '/static/css', '__JS__' => $root . '/static/js', ]; - $this->replace = array_merge($baseReplace, $replace); + $this->replace = array_merge($baseReplace, (array) $replace); } /** -- Gitee From 26e3879559b66ed5f343bced3121f25e85b0adcb Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 8 Dec 2016 22:14:06 +0800 Subject: [PATCH 0239/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BApp=E7=B1=BB?= =?UTF-8?q?=E7=9A=84initCommon=E7=9A=84=E8=BF=94=E5=9B=9E=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/think/App.php b/library/think/App.php index 367b4ae6..01af92ce 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -450,9 +450,9 @@ class App // 监听app_init Hook::listen('app_init'); - self::$init = $config; + self::$init = true; } - return self::$init; + return Config::get(); } /** -- Gitee From da4160c2f8abab34ffaacd9c871dcce1a8ae4549 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 9 Dec 2016 07:25:20 +0800 Subject: [PATCH 0240/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BValidate=E7=B1=BB?= =?UTF-8?q?=E7=9A=84=E9=9D=99=E6=80=81=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index 5bc1e944..81fc58a3 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -1255,7 +1255,7 @@ class Validate public static function __callStatic($method, $params) { - $class = new static; + $class = self::make(); if (method_exists($class, $method)) { return call_user_func_array([$class, $method], $params); } else { -- Gitee From 0dab46114c5be26c9d71af13490734017812c15a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 9 Dec 2016 11:18:27 +0800 Subject: [PATCH 0241/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3HasMany=E5=85=B3?= =?UTF-8?q?=E8=81=94=E7=9A=84has=E5=92=8ChasWhere=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/relation/HasMany.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/think/model/relation/HasMany.php b/library/think/model/relation/HasMany.php index 7d73e3a2..298083d4 100644 --- a/library/think/model/relation/HasMany.php +++ b/library/think/model/relation/HasMany.php @@ -182,7 +182,7 @@ class HasMany extends Relation * @param string $id 关联表的统计字段 * @return Query */ - public static function has($model, $operator = '>=', $count = 1, $id = '*') + public function has($model, $operator = '>=', $count = 1, $id = '*') { $table = $this->query->getTable(); return $model->db()->alias('a') @@ -198,7 +198,7 @@ class HasMany extends Relation * @param mixed $where 查询条件(数组或者闭包) * @return Query */ - public static function hasWhere($model, $where = []) + public function hasWhere($model, $where = []) { $table = $this->query->getTable(); if (is_array($where)) { -- Gitee From 74315bb894b98cfe0c06e00ab1c689228a1ee6f3 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 9 Dec 2016 11:25:24 +0800 Subject: [PATCH 0242/1170] =?UTF-8?q?HasOne=E5=85=B3=E8=81=94=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=BD=BF=E7=94=A8hasWhere=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/relation/HasOne.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/library/think/model/relation/HasOne.php b/library/think/model/relation/HasOne.php index 85ac237e..5f75afa4 100644 --- a/library/think/model/relation/HasOne.php +++ b/library/think/model/relation/HasOne.php @@ -50,4 +50,27 @@ class HasOne extends OneToOne return $this->query->where($this->foreignKey, $this->parent->$localKey)->find(); } + /** + * 根据关联条件查询当前模型 + * @access public + * @param Model $model 模型对象 + * @param mixed $where 查询条件(数组或者闭包) + * @return Query + */ + public function hasWhere($model, $where = []) + { + $table = $this->query->getTable(); + if (is_array($where)) { + foreach ($where as $key => $val) { + if (false === strpos($key, '.')) { + $where['b.' . $key] = $val; + unset($where[$key]); + } + } + } + return $model->db()->alias('a') + ->field('a.*') + ->join($table . ' b', 'a.' . $this->localKey . '=b.' . $this->foreignKey, $this->joinType) + ->where($where); + } } -- Gitee From d49b986bb8ef2b5914e960a34de6eb680d33879c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 9 Dec 2016 14:43:04 +0800 Subject: [PATCH 0243/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Relation=E4=B8=80?= =?UTF-8?q?=E5=A4=84use?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/Relation.php | 1 + 1 file changed, 1 insertion(+) diff --git a/library/think/model/Relation.php b/library/think/model/Relation.php index 22223281..39d62871 100644 --- a/library/think/model/Relation.php +++ b/library/think/model/Relation.php @@ -12,6 +12,7 @@ namespace think\model; use think\db\Query; +use think\Exception; abstract class Relation { -- Gitee From c5dbbb45daca52eb98c1c675e43a77e7f6f8da18 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 9 Dec 2016 14:52:37 +0800 Subject: [PATCH 0244/1170] =?UTF-8?q?Relation=E7=B1=BB=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/Relation.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/library/think/model/Relation.php b/library/think/model/Relation.php index 39d62871..4fc68ff2 100644 --- a/library/think/model/Relation.php +++ b/library/think/model/Relation.php @@ -13,6 +13,7 @@ namespace think\model; use think\db\Query; use think\Exception; +use think\Model; abstract class Relation { @@ -40,15 +41,27 @@ abstract class Relation /** * 获取关联的所属模型 * @access public + * @return Model */ - public function getModel() + public function getParent() { return $this->parent; } + /** + * 获取当前的关联模型类 + * @access public + * @return string + */ + public function getModel() + { + return $this->model; + } + /** * 获取关联的查询对象 * @access public + * @return Query */ public function getQuery() { -- Gitee From 308a0b9ca8ffd4c1fc9e6e3fbadc826000b1c9a2 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 9 Dec 2016 15:01:34 +0800 Subject: [PATCH 0245/1170] =?UTF-8?q?MorphMany=E5=85=B3=E8=81=94=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0save=E5=92=8Csaveall=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/relation/HasMany.php | 3 +- library/think/model/relation/MorphMany.php | 35 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/library/think/model/relation/HasMany.php b/library/think/model/relation/HasMany.php index 298083d4..416c5a5b 100644 --- a/library/think/model/relation/HasMany.php +++ b/library/think/model/relation/HasMany.php @@ -167,8 +167,7 @@ class HasMany extends Relation { $result = false; foreach ($dataSet as $key => $data) { - $data[$this->foreignKey] = $this->parent->{$this->localKey}; - $result = $this->save($data); + $result = $this->save($data); } return $result; } diff --git a/library/think/model/relation/MorphMany.php b/library/think/model/relation/MorphMany.php index cfce9b57..5a2e2e9b 100644 --- a/library/think/model/relation/MorphMany.php +++ b/library/think/model/relation/MorphMany.php @@ -141,6 +141,41 @@ class MorphMany extends Relation return $data; } + /** + * 保存(新增)当前关联数据对象 + * @access public + * @param mixed $data 数据 可以使用数组 关联模型对象 和 关联对象的主键 + * @return integer + */ + public function save($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); + } + + /** + * 批量保存当前关联数据对象 + * @access public + * @param array $dataSet 数据集 + * @return integer + */ + public function saveAll(array $dataSet) + { + $result = false; + foreach ($dataSet as $key => $data) { + $result = $this->save($data); + } + return $result; + } + /** * 执行基础查询(进执行一次) * @access protected -- Gitee From 08f648966c8bd188fda8f3d50cd9e27c8c789ee6 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 9 Dec 2016 15:11:18 +0800 Subject: [PATCH 0246/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3View=E7=B1=BB?= =?UTF-8?q?=E7=9A=84root=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/View.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/View.php b/library/think/View.php index 6edd69a0..6a96b740 100644 --- a/library/think/View.php +++ b/library/think/View.php @@ -40,7 +40,7 @@ class View // 基础替换字符串 $request = Request::instance(); $base = $request->root(); - $root = strpos($base, '.') ? dirname($base) : $base; + $root = strpos($base, '.') ? ltrim(dirname($base), '\\') : $base; if ('' != $root) { $root = '/' . $root; } -- Gitee From a223dd5affba09a89ea8a6d9c1484363c85748b3 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 9 Dec 2016 15:29:22 +0800 Subject: [PATCH 0247/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BView=E7=B1=BB?= =?UTF-8?q?=E7=9A=84root=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/View.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/think/View.php b/library/think/View.php index 6a96b740..b724ba91 100644 --- a/library/think/View.php +++ b/library/think/View.php @@ -40,9 +40,9 @@ class View // 基础替换字符串 $request = Request::instance(); $base = $request->root(); - $root = strpos($base, '.') ? ltrim(dirname($base), '\\') : $base; + $root = strpos($base, '.') ? ltrim(dirname($base), DS) : $base; if ('' != $root) { - $root = '/' . $root; + $root = '/' . ltrim($root, '/'); } $baseReplace = [ '__ROOT__' => $root, -- Gitee From b7fb12c2fbd2a4837f99a549395f4f9cb2a250e7 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 9 Dec 2016 15:33:30 +0800 Subject: [PATCH 0248/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3File=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E9=A9=B1=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/log/driver/File.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/log/driver/File.php b/library/think/log/driver/File.php index f433718d..f9358a9d 100644 --- a/library/think/log/driver/File.php +++ b/library/think/log/driver/File.php @@ -54,7 +54,7 @@ class File } $depr = $depr ? "---------------------------------------------------------------\r\n" : ''; - + $info = ''; if (App::$debug) { // 获取基本信息 if (isset($_SERVER['HTTP_HOST'])) { -- Gitee From 846553ec13fc5b5fa5ac23b0dd45edfa9d24e64f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 9 Dec 2016 17:52:09 +0800 Subject: [PATCH 0249/1170] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Query=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E7=9A=84before=5Ffind=20before=5Fselect=20after=5Fins?= =?UTF-8?q?ert=20after=5Fupdate=20after=5Fdelete=20=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 73 +++++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 12 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index f0e1ae5b..bb79ac1b 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -53,6 +53,8 @@ class Query protected $bind = []; // 数据表信息 protected static $info = []; + // 回调事件 + private static $event = []; /** * 架构函数 @@ -1774,6 +1776,9 @@ class Query // 执行操作 $result = $this->execute($sql, $bind); + if ($result) { + $this->trigger('after_insert', $this); + } if ($getLastInsID) { $sequence = $sequence ?: (isset($options['sequence']) ? $options['sequence'] : null); return $this->getLastInsID($sequence); @@ -1905,7 +1910,11 @@ class Query Cache::rm($key); } // 执行操作 - return '' == $sql ? 0 : $this->execute($sql, $bind); + $result = '' == $sql ? 0 : $this->execute($sql, $bind); + if ($result) { + $this->trigger('after_update', $this); + } + return $result; } } @@ -1954,12 +1963,15 @@ class Query // 获取实际执行的SQL语句 return $this->connection->getRealSql($sql, $bind); } - // 执行查询操作 - $resultSet = $this->query($sql, $bind, $options['master'], $options['fetch_class']); + if ($resultSet = $this->trigger('before_select', $this)) { + } else { + // 执行查询操作 + $resultSet = $this->query($sql, $bind, $options['master'], $options['fetch_class']); - if ($resultSet instanceof \PDOStatement) { - // 返回PDOStatement对象 - return $resultSet; + if ($resultSet instanceof \PDOStatement) { + // 返回PDOStatement对象 + return $resultSet; + } } if (isset($cache)) { @@ -2048,12 +2060,17 @@ class Query // 获取实际执行的SQL语句 return $this->connection->getRealSql($sql, $bind); } - // 执行查询 - $result = $this->query($sql, $bind, $options['master'], $options['fetch_class']); - if ($result instanceof \PDOStatement) { - // 返回PDOStatement对象 - return $result; + // 事件回调 + if ($result = $this->trigger('before_find', $this)) { + } else { + // 执行查询 + $result = $this->query($sql, $bind, $options['master'], $options['fetch_class']); + + if ($result instanceof \PDOStatement) { + // 返回PDOStatement对象 + return $result; + } } if (isset($cache)) { @@ -2251,7 +2268,11 @@ class Query Cache::rm($key); } // 执行操作 - return $this->execute($sql, $bind); + $result = $this->execute($sql, $bind); + if ($result) { + $this->trigger('after_delete', $this); + } + return $result; } /** @@ -2341,4 +2362,32 @@ class Query return $options; } + /** + * 注册回调方法 + * @access public + * @param string $event 事件名 + * @param callable $callback 回调方法 + * @return void + */ + public static function event($event, $callback) + { + self::$event[$event] = $callback; + } + + /** + * 触发事件 + * @access protected + * @param string $event 事件名 + * @param mixed $params 传入参数(引用) + * @return bool + */ + protected function trigger($event, &$params) + { + $result = false; + if (isset(self::$event[$event])) { + $callback = self::$event[$event]; + $result = call_user_func_array($callback, [ & $params]); + } + return $result; + } } -- Gitee From 936e4b3b044d3b7d601efeedf226322513e0cac0 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 9 Dec 2016 18:12:27 +0800 Subject: [PATCH 0250/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BBuilder=E7=B1=BB?= =?UTF-8?q?=E7=9A=84parseDateTime=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index 406da565..49b3aebe 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -437,7 +437,7 @@ abstract class Builder $info = $type[$key]; } if (isset($info)) { - if (is_numeric($value) && strtotime($value)) { + if (is_string($value)) { $value = strtotime($value) ?: $value; } -- Gitee From 9e0185411e2e06c860a15d8bea8f2bd83723872f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 9 Dec 2016 18:31:05 +0800 Subject: [PATCH 0251/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BB?= =?UTF-8?q?=E7=9A=84trigger=E6=96=B9=E6=B3=95=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index bb79ac1b..eb14638a 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1777,7 +1777,7 @@ class Query // 执行操作 $result = $this->execute($sql, $bind); if ($result) { - $this->trigger('after_insert', $this); + $this->trigger('after_insert', $options); } if ($getLastInsID) { $sequence = $sequence ?: (isset($options['sequence']) ? $options['sequence'] : null); @@ -1912,7 +1912,7 @@ class Query // 执行操作 $result = '' == $sql ? 0 : $this->execute($sql, $bind); if ($result) { - $this->trigger('after_update', $this); + $this->trigger('after_update', $options); } return $result; } @@ -1963,7 +1963,7 @@ class Query // 获取实际执行的SQL语句 return $this->connection->getRealSql($sql, $bind); } - if ($resultSet = $this->trigger('before_select', $this)) { + if ($resultSet = $this->trigger('before_select', $options)) { } else { // 执行查询操作 $resultSet = $this->query($sql, $bind, $options['master'], $options['fetch_class']); @@ -2062,7 +2062,7 @@ class Query } // 事件回调 - if ($result = $this->trigger('before_find', $this)) { + if ($result = $this->trigger('before_find', $options)) { } else { // 执行查询 $result = $this->query($sql, $bind, $options['master'], $options['fetch_class']); @@ -2270,7 +2270,7 @@ class Query // 执行操作 $result = $this->execute($sql, $bind); if ($result) { - $this->trigger('after_delete', $this); + $this->trigger('after_delete', $options); } return $result; } @@ -2378,15 +2378,15 @@ class Query * 触发事件 * @access protected * @param string $event 事件名 - * @param mixed $params 传入参数(引用) + * @param mixed $options 当前查询参数 * @return bool */ - protected function trigger($event, &$params) + protected function trigger($event, $options = []) { $result = false; if (isset(self::$event[$event])) { $callback = self::$event[$event]; - $result = call_user_func_array($callback, [ & $params]); + $result = call_user_func_array($callback, [$options, $this]); } return $result; } -- Gitee From b81a6c5d38ec7c98a35d1400745d2a3b98e93822 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 9 Dec 2016 19:01:44 +0800 Subject: [PATCH 0252/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BSession=E7=B1=BB?= =?UTF-8?q?=E7=9A=84boot=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Session.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/think/Session.php b/library/think/Session.php index 626c8c11..9bafe116 100644 --- a/library/think/Session.php +++ b/library/think/Session.php @@ -114,7 +114,9 @@ class Session if (is_null(self::$init)) { self::init(); } elseif (false === self::$init) { - session_start(); + if (PHP_SESSION_ACTIVE != session_status()) { + session_start(); + } self::$init = true; } } -- Gitee From 63a3936eb9c5fae773a97db31a338f1f7ad18b41 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 9 Dec 2016 19:18:35 +0800 Subject: [PATCH 0253/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BBtable?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index eb14638a..dc854a6c 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1111,7 +1111,6 @@ class Query if (is_string($table)) { if (strpos($table, ')')) { // 子查询 - $table = $table; } elseif (strpos($table, ',')) { $tables = explode(',', $table); $table = []; @@ -1126,7 +1125,8 @@ class Query } } elseif (strpos($table, ' ')) { list($table, $alias) = explode(' ', $table); - $table = [$table => $alias]; + + $table = [$table => $alias]; $this->alias($table); } } else { -- Gitee From c04bb1cd1e5432281faf61469d047277364bf41a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 11 Dec 2016 17:36:35 +0800 Subject: [PATCH 0254/1170] =?UTF-8?q?=E8=A7=84=E8=8C=83=E9=A2=84=E8=BD=BD?= =?UTF-8?q?=E5=85=A5=E6=96=B9=E6=B3=95=E7=9A=84=E8=B0=83=E7=94=A8=20?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E8=B0=83=E7=94=A8user=5Fprofile=20=E9=A2=84?= =?UTF-8?q?=E8=BD=BD=E5=85=A5=E4=BC=9A=E8=87=AA=E5=8A=A8=E5=AF=B9=E5=BA=94?= =?UTF-8?q?=20userProfile=E5=85=B3=E8=81=94=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 2 ++ library/think/db/Query.php | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/library/think/Model.php b/library/think/Model.php index 2b7f3ae3..52c003cc 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -1245,6 +1245,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess if (strpos($relation, '.')) { list($relation, $subRelation) = explode('.', $relation); } + $relation = Loader::parseName($relation, 1); $this->$relation()->eagerlyResultSet($resultSet, $relation, $subRelation, $closure, $class); } } @@ -1271,6 +1272,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess if (strpos($relation, '.')) { list($relation, $subRelation) = explode('.', $relation); } + $relation = Loader::parseName($relation, 1); $this->$relation()->eagerlyResult($result, $relation, $subRelation, $closure, $class); } } diff --git a/library/think/db/Query.php b/library/think/db/Query.php index dc854a6c..43a5b07c 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1653,7 +1653,8 @@ class Query } /** @var Relation $model */ - $model = $class->$relation(); + $relation = Loader::parseName($relation, 1); + $model = $class->$relation(); if ($model instanceof HasOne || $model instanceof BelongsTo) { $model->eagerly($this, $relation, $subRelation, $closure, $first); $first = false; -- Gitee From 8e8355e2d880ae5291066fd8115c8937789598d5 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 12 Dec 2016 16:54:11 +0800 Subject: [PATCH 0255/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=B1=BB=E7=9A=84=E9=94=99=E8=AF=AF=E4=BF=A1=E6=81=AF=E5=AE=9A?= =?UTF-8?q?=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/think/Validate.php b/library/think/Validate.php index 81fc58a3..cb113bc2 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -1201,6 +1201,8 @@ class Validate { if (isset($this->message[$attribute . '.' . $type])) { $msg = $this->message[$attribute . '.' . $type]; + } elseif (isset($this->message[$attribute][$type])) { + $msg = $this->message[$attribute][$type]; } elseif (isset($this->message[$attribute])) { $msg = $this->message[$attribute]; } elseif (isset(self::$typeMsg[$type])) { -- Gitee From 082b3bea816178b092e45361eb1a6a8dd747d682 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 13 Dec 2016 11:43:26 +0800 Subject: [PATCH 0256/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E4=B8=80=E5=AF=B9?= =?UTF-8?q?=E4=B8=80=E5=85=B3=E8=81=94=E9=A2=84=E8=BD=BD=E5=85=A5=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=20=E6=94=AF=E6=8C=81=E4=BD=BF=E7=94=A8IN=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=20=E4=B8=80=E5=AF=B9=E4=B8=80=E5=85=B3=E8=81=94?= =?UTF-8?q?=E7=B1=BB=E5=A2=9E=E5=8A=A0setEagerlyType=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E8=AE=BE=E7=BD=AE=E9=A2=84=E8=BD=BD=E5=85=A5?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=96=B9=E5=BC=8F=20=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E4=B8=BAJOIN=E6=96=B9=E5=BC=8F=EF=BC=8CsetEagerlyType(1)=20?= =?UTF-8?q?=E4=BD=BF=E7=94=A8IN=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Loader类的parseName方法增加第三个参数 用于驼峰法转换是否首字母大写 --- library/think/Loader.php | 8 +- library/think/Model.php | 6 +- library/think/db/Query.php | 7 +- library/think/model/relation/BelongsTo.php | 66 +++++++++++++- library/think/model/relation/HasOne.php | 65 ++++++++++++++ library/think/model/relation/OneToOne.php | 100 +++++++++++++++++---- 6 files changed, 222 insertions(+), 30 deletions(-) diff --git a/library/think/Loader.php b/library/think/Loader.php index 9f54ad3a..57f6a41f 100644 --- a/library/think/Loader.php +++ b/library/think/Loader.php @@ -494,14 +494,16 @@ class Loader * type 0 将Java风格转换为C的风格 1 将C风格转换为Java的风格 * @param string $name 字符串 * @param integer $type 转换类型 + * @param bool $ucfirst 首字母是否大写(驼峰规则) * @return string */ - public static function parseName($name, $type = 0) + public static function parseName($name, $type = 0, $ucfirst = true) { if ($type) { - return ucfirst(preg_replace_callback('/_([a-zA-Z])/', function ($match) { + $name = preg_replace_callback('/_([a-zA-Z])/', function ($match) { return strtoupper($match[1]); - }, $name)); + }, $name); + return $ucfirst ? ucfirst($name) : lcfirst($name); } else { return strtolower(trim(preg_replace("/[A-Z]/", "_\\0", $name), "_")); } diff --git a/library/think/Model.php b/library/think/Model.php index 52c003cc..d40c6218 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -414,7 +414,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess // 类型转换 $value = $this->readTransform($value, $this->type[$name]); } elseif ($notFound) { - $method = Loader::parseName($name, 1); + $method = Loader::parseName($name, 1, false); if (method_exists($this, $method) && $this->$method() instanceof Relation) { // 不存在该字段 获取关联数据 $value = $this->$method()->getRelation(); @@ -1245,7 +1245,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess if (strpos($relation, '.')) { list($relation, $subRelation) = explode('.', $relation); } - $relation = Loader::parseName($relation, 1); + $relation = Loader::parseName($relation, 1, false); $this->$relation()->eagerlyResultSet($resultSet, $relation, $subRelation, $closure, $class); } } @@ -1272,7 +1272,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess if (strpos($relation, '.')) { list($relation, $subRelation) = explode('.', $relation); } - $relation = Loader::parseName($relation, 1); + $relation = Loader::parseName($relation, 1, false); $this->$relation()->eagerlyResult($result, $relation, $subRelation, $closure, $class); } } diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 43a5b07c..ace9a90a 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -27,8 +27,7 @@ use think\exception\PDOException; use think\Loader; use think\Model; use think\model\Relation; -use think\model\relation\BelongsTo; -use think\model\relation\HasOne; +use think\model\relation\OneToOne; use think\Paginator; class Query @@ -1653,9 +1652,9 @@ class Query } /** @var Relation $model */ - $relation = Loader::parseName($relation, 1); + $relation = Loader::parseName($relation, 1, false); $model = $class->$relation(); - if ($model instanceof HasOne || $model instanceof BelongsTo) { + if ($model instanceof OneToOne && 0 == $model->getEagerlyType()) { $model->eagerly($this, $relation, $subRelation, $closure, $first); $first = false; } elseif ($closure) { diff --git a/library/think/model/relation/BelongsTo.php b/library/think/model/relation/BelongsTo.php index ffab752d..7626caf7 100644 --- a/library/think/model/relation/BelongsTo.php +++ b/library/think/model/relation/BelongsTo.php @@ -22,7 +22,7 @@ class BelongsTo extends OneToOne * @param Model $parent 上级模型对象 * @param string $model 模型名 * @param string $foreignKey 关联外键 - * @param string $otherKey 关联主键 + * @param string $localKey 关联主键 * @param array $alias 别名定义 * @param string $joinType JOIN类型 */ @@ -48,4 +48,68 @@ class BelongsTo extends OneToOne return $this->query->where($localKey, $this->parent->$foreignKey)->find(); } + /** + * 预载入关联查询(数据集) + * @access public + * @param array $resultSet 数据集 + * @param string $relation 当前关联名 + * @param string $subRelation 子关联名 + * @param \Closure $closure 闭包 + * @param string $class 数据集对象名 为空表示数组 + * @return void + */ + protected function eagerlySet(&$resultSet, $relation, $subRelation, $closure, $class) + { + $localKey = $this->localKey; + $foreignKey = $this->foreignKey; + + $range = []; + foreach ($resultSet as $result) { + // 获取关联外键列表 + if (isset($result->$foreignKey)) { + $range[] = $result->$foreignKey; + } + } + + if (!empty($range)) { + $this->where[$localKey] = ['in', $range]; + $data = $this->eagerlyWhere($this, [ + $localKey => [ + 'in', + $range, + ], + ], $localKey, $relation, $subRelation, $closure); + + // 关联数据封装 + foreach ($resultSet as $result) { + if (!isset($data[$result->$foreignKey])) { + $data[$result->$foreignKey] = []; + } + $result->setAttr($relation, $this->resultSetBuild($data[$result->$foreignKey], $class)); + } + } + } + + /** + * 预载入关联查询(数据) + * @access public + * @param Model $result 数据对象 + * @param string $relation 当前关联名 + * @param string $subRelation 子关联名 + * @param \Closure $closure 闭包 + * @param string $class 数据集对象名 为空表示数组 + * @return void + */ + protected function eagerlyOne(&$result, $relation, $subRelation, $closure, $class) + { + $localKey = $this->localKey; + $foreignKey = $this->foreignKey; + $data = $this->eagerlyWhere($this, [$localKey => $result->$foreignKey], $localKey, $relation, $subRelation, $closure); + // 关联数据封装 + if (!isset($data[$result->$foreignKey])) { + $data[$result->$foreignKey] = []; + } + $result->setAttr($relation, $this->resultSetBuild($data[$result->$foreignKey], $class)); + } + } diff --git a/library/think/model/relation/HasOne.php b/library/think/model/relation/HasOne.php index 5f75afa4..e76fbbaf 100644 --- a/library/think/model/relation/HasOne.php +++ b/library/think/model/relation/HasOne.php @@ -73,4 +73,69 @@ class HasOne extends OneToOne ->join($table . ' b', 'a.' . $this->localKey . '=b.' . $this->foreignKey, $this->joinType) ->where($where); } + + /** + * 预载入关联查询(数据集) + * @access public + * @param array $resultSet 数据集 + * @param string $relation 当前关联名 + * @param string $subRelation 子关联名 + * @param \Closure $closure 闭包 + * @param string $class 数据集对象名 为空表示数组 + * @return void + */ + protected function eagerlySet(&$resultSet, $relation, $subRelation, $closure, $class) + { + $localKey = $this->localKey; + $foreignKey = $this->foreignKey; + + $range = []; + foreach ($resultSet as $result) { + // 获取关联外键列表 + if (isset($result->$localKey)) { + $range[] = $result->$localKey; + } + } + + if (!empty($range)) { + $this->where[$foreignKey] = ['in', $range]; + $data = $this->eagerlyWhere($this, [ + $foreignKey => [ + 'in', + $range, + ], + ], $foreignKey, $relation, $subRelation, $closure); + + // 关联数据封装 + foreach ($resultSet as $result) { + if (!isset($data[$result->$localKey])) { + $data[$result->$localKey] = []; + } + $result->setAttr($relation, $this->resultSetBuild($data[$result->$localKey], $class)); + } + } + } + + /** + * 预载入关联查询(数据) + * @access public + * @param Model $result 数据对象 + * @param string $relation 当前关联名 + * @param string $subRelation 子关联名 + * @param \Closure $closure 闭包 + * @param string $class 数据集对象名 为空表示数组 + * @return void + */ + protected function eagerlyOne(&$result, $relation, $subRelation, $closure, $class) + { + $localKey = $this->localKey; + $foreignKey = $this->foreignKey; + $data = $this->eagerlyWhere($this, [$foreignKey => $result->$localKey], $foreignKey, $relation, $subRelation, $closure); + // 关联数据封装 + if (!isset($data[$result->$localKey])) { + $data[$result->$localKey] = []; + } + $result->setAttr($relation, $this->resultSetBuild($data[$result->$localKey], $class)); + } + } diff --git a/library/think/model/relation/OneToOne.php b/library/think/model/relation/OneToOne.php index 650000e9..354d718d 100644 --- a/library/think/model/relation/OneToOne.php +++ b/library/think/model/relation/OneToOne.php @@ -19,8 +19,11 @@ use think\model\relation\BelongsTo; abstract class OneToOne extends Relation { + // 预载入方式 + protected $eagerlyType = 0; + /** - * 预载入关联查询 + * 预载入关联查询(JOIN方式) * @access public * @param Query $query 查询对象 * @param string $relation 关联名 @@ -76,7 +79,7 @@ abstract class OneToOne extends Relation } /** - * 预载入关联查询 + * 预载入关联查询(数据集) * @access public * @param array $resultSet 数据集 * @param string $relation 当前关联名 @@ -85,16 +88,21 @@ abstract class OneToOne extends Relation * @param string $class 数据集对象名 为空表示数组 * @return void */ - public function eagerlyResultSet(&$resultSet, $relation) + public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class) { - foreach ($resultSet as $result) { + if (1 == $this->eagerlyType) { + // IN查询 + $this->eagerlySet($resultSet, $relation, $subRelation, $closure, $class); + } else { // 模型关联组装 - $this->match($this->model, $relation, $result); + foreach ($resultSet as $result) { + $this->match($this->model, $relation, $result); + } } } /** - * 预载入关联查询 返回模型对象 + * 预载入关联查询(数据) * @access public * @param Model $result 数据对象 * @param string $relation 当前关联名 @@ -103,10 +111,54 @@ abstract class OneToOne extends Relation * @param string $class 数据集对象名 为空表示数组 * @return void */ - public function eagerlyResult(&$result, $relation) + public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class) { - // 模型关联组装 - $this->match($this->model, $relation, $result); + if (1 == $this->eagerlyType) { + // IN查询 + $this->eagerlyOne($result, $relation, $subRelation, $closure, $class); + } else { + // 模型关联组装 + $this->match($this->model, $relation, $result); + } + } + + /** + * 保存(新增)当前关联数据对象 + * @access public + * @param mixed $data 数据 可以使用数组 关联模型对象 和 关联对象的主键 + * @return integer + */ + public function save($data) + { + if ($data instanceof Model) { + $data = $data->getData(); + } + // 保存关联表数据 + $data[$this->foreignKey] = $this->parent->{$this->localKey}; + $model = new $this->model; + return $model->save($data); + } + + /** + * 设置预载入方式 + * @access public + * @param integer $type 预载入方式 0 JOIN查询 1 IN查询 + * @return this + */ + public function setEagerlyType($type) + { + $this->eagerlyType = $type; + return $this; + } + + /** + * 获取预载入方式 + * @access public + * @return integer + */ + public function getEagerlyType() + { + return $this->eagerlyType; } /** @@ -134,20 +186,30 @@ abstract class OneToOne extends Relation } /** - * 保存(新增)当前关联数据对象 + * 一对一 关联模型预查询(IN方式) * @access public - * @param mixed $data 数据 可以使用数组 关联模型对象 和 关联对象的主键 - * @return integer + * @param object $model 关联模型对象 + * @param array $where 关联预查询条件 + * @param string $key 关联键名 + * @param string $relation 关联名 + * @param string $subRelation 子关联 + * @param bool $closure + * @return array */ - public function save($data) + protected function eagerlyWhere($model, $where, $key, $relation, $subRelation = '', $closure = false) { - if ($data instanceof Model) { - $data = $data->getData(); + // 预载入关联查询 支持嵌套预载入 + if ($closure) { + call_user_func_array($closure, [ & $model]); } - // 保存关联表数据 - $data[$this->foreignKey] = $this->parent->{$this->localKey}; - $model = new $this->model; - return $model->save($data); + $list = $model->where($where)->with($subRelation)->select(); + + // 组装模型数据 + $data = []; + foreach ($list as $set) { + $data[$set->$key][] = $set; + } + return $data; } /** -- Gitee From ebf2431a50ac6ffe8297d3d0be45412e6dfd23d4 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 13 Dec 2016 11:50:16 +0800 Subject: [PATCH 0257/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BApp=E7=B1=BB?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=99=A8=E6=B2=A1=E6=9C=89=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=80=BC=E8=BF=94=E5=9B=9E204=E7=8A=B6=E6=80=81=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/App.php b/library/think/App.php index 01af92ce..204db94d 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -175,7 +175,7 @@ class App $type = $isAjax ? Config::get('default_ajax_return') : Config::get('default_return_type'); $response = Response::create($data, $type); } else { - $response = Response::create(); + $response = Response::create('', 204); } // 监听app_end -- Gitee From 7775dd9255cc0fd320f27a892153213d04fc141b Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 13 Dec 2016 14:21:17 +0800 Subject: [PATCH 0258/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3App=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/App.php b/library/think/App.php index 204db94d..09176ba5 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -175,7 +175,7 @@ class App $type = $isAjax ? Config::get('default_ajax_return') : Config::get('default_return_type'); $response = Response::create($data, $type); } else { - $response = Response::create('', 204); + $response = Response::create('', '', 204); } // 监听app_end -- Gitee From f77a48930a8dbb253eebc8cef11a1d09d3524f3b Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 13 Dec 2016 14:29:24 +0800 Subject: [PATCH 0259/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BValidate=E7=9A=84ge?= =?UTF-8?q?tRuleMsg=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index cb113bc2..d68811f0 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -1215,7 +1215,7 @@ class Validate $msg = Lang::get(substr($msg, 2, -1)); } - if (is_string($msg) && false !== strpos($msg, ':')) { + if (is_string($msg) && is_string($rule) && false !== strpos($msg, ':')) { // 变量替换 if (strpos($rule, ',')) { $array = array_pad(explode(',', $rule), 3, ''); -- Gitee From 965e14eb76ebc0c75d91d4f79fb84b55c6329ad9 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 13 Dec 2016 14:47:43 +0800 Subject: [PATCH 0260/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BValidate=E7=B1=BB?= =?UTF-8?q?=E7=9A=84=E9=97=AD=E5=8C=85=E8=A7=84=E5=88=99=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 1 + 1 file changed, 1 insertion(+) diff --git a/library/think/Validate.php b/library/think/Validate.php index d68811f0..2053ae26 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -362,6 +362,7 @@ class Validate foreach ($rules as $key => $rule) { if ($rule instanceof \Closure) { $result = call_user_func_array($rule, [$value, $data]); + $info = is_numeric($key) ? '' : $key; } else { // 判断验证类型 if (is_numeric($key)) { -- Gitee From e36987fc5d378a24af1d248fb8ba76f287b56bdf Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 13 Dec 2016 14:48:01 +0800 Subject: [PATCH 0261/1170] =?UTF-8?q?Cookie=E7=B1=BB=E5=A2=9E=E5=8A=A0fore?= =?UTF-8?q?ver=E6=96=B9=E6=B3=95=E7=94=A8=E4=BA=8E=E6=B0=B8=E4=B9=85?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Cookie.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/library/think/Cookie.php b/library/think/Cookie.php index 648b2c60..12b5cc31 100644 --- a/library/think/Cookie.php +++ b/library/think/Cookie.php @@ -99,6 +99,22 @@ class Cookie $_COOKIE[$name] = $value; } + /** + * 永久保存Cookie数据 + * @param string $name cookie名称 + * @param mixed $value cookie值 + * @param mixed $option 可选参数 可能会是 null|integer|string + * @return void + */ + public static function forever($name, $value = '', $option = null) + { + if (is_null($option) || is_numeric($option)) { + $option = []; + } + $option['expire'] = 315360000; + self::set($name, $value, $option); + } + /** * 判断Cookie数据 * @param string $name cookie名称 -- Gitee From 381f90a7359bef6cf4f22efc67a5cd8bcf7f0077 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 13 Dec 2016 15:25:26 +0800 Subject: [PATCH 0262/1170] =?UTF-8?q?confirm=E5=92=8Cdeifferent=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E8=A7=84=E5=88=99=E9=BB=98=E8=AE=A4=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E8=B0=83=E6=95=B4=20=E6=94=AF=E6=8C=81=E4=BC=A0=E5=85=A5?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E6=AF=94=E8=BE=83=E5=AD=97=E6=AE=B5=E5=90=8D?= =?UTF-8?q?=EF=BC=8C=E4=BE=8B=E5=A6=82=EF=BC=9A=20confirm|repassword,?= =?UTF-8?q?=E7=A1=AE=E8=AE=A4=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index 2053ae26..5d838d2a 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -72,8 +72,8 @@ class Validate 'expire' => '不在有效期内 :rule', 'allowIp' => '不允许的IP访问', 'denyIp' => '禁止的IP访问', - 'confirm' => ':attribute和字段 :rule 不一致', - 'different' => ':attribute和字段 :rule 不能相同', + 'confirm' => ':attribute和确认字段:2不一致', + 'different' => ':attribute和比较字段:2不能相同', 'egt' => ':attribute必须大于等于 :rule', 'gt' => ':attribute必须大于 :rule', 'elt' => ':attribute必须小于等于 :rule', -- Gitee From 5c1c1d5f60252d305348bd48bd88e95bfb89ab8c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 13 Dec 2016 16:50:28 +0800 Subject: [PATCH 0263/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3HasManyThrough?= =?UTF-8?q?=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/relation/HasManyThrough.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/think/model/relation/HasManyThrough.php b/library/think/model/relation/HasManyThrough.php index 9339d505..56b90f4c 100644 --- a/library/think/model/relation/HasManyThrough.php +++ b/library/think/model/relation/HasManyThrough.php @@ -21,6 +21,8 @@ class HasManyThrough extends Relation { // 中间关联表外键 protected $throughKey; + // 中间表模型 + protected $through; /** * 架构函数 @@ -37,7 +39,7 @@ class HasManyThrough extends Relation { $this->parent = $parent; $this->model = $model; - $this->middle = $through; + $this->through = $through; $this->foreignKey = $foreignKey; $this->throughKey = $throughKey; $this->localKey = $localKey; @@ -90,7 +92,7 @@ class HasManyThrough extends Relation protected function baseQuery() { if (empty($this->baseQuery)) { - $through = $this->middle; + $through = $this->through; $model = $this->model; $alias = Loader::parseName(basename(str_replace('\\', '/', $model))); $throughTable = $through::getTable(); -- Gitee From 59abc177505e62b9b87474f7126377093f856a86 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 13 Dec 2016 17:42:54 +0800 Subject: [PATCH 0264/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BModel=E7=B1=BBdb?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index d40c6218..1a9677d4 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -169,10 +169,14 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $model = $this->class; if (!isset(self::$links[$model])) { // 合并数据库配置 - if (is_array($this->connection)) { - $connection = array_merge(Config::get('database'), $this->connection); + if (!empty($this->connection)) { + if (is_array($this->connection)) { + $connection = array_merge(Config::get('database'), $this->connection); + } else { + $connection = $this->connection; + } } else { - $connection = $this->connection; + $connection = []; } // 设置当前模型 确保查询返回模型对象 $query = Db::connect($connection)->model($model, $this->query); -- Gitee From 538f675cca80f9218eb8d90beca8eb56a2cead00 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 13 Dec 2016 17:58:47 +0800 Subject: [PATCH 0265/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=BD=AF=E5=88=A0?= =?UTF-8?q?=E9=99=A4destroy=E5=92=8Crestore=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/traits/model/SoftDelete.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/library/traits/model/SoftDelete.php b/library/traits/model/SoftDelete.php index 9d855c76..281c26c9 100644 --- a/library/traits/model/SoftDelete.php +++ b/library/traits/model/SoftDelete.php @@ -77,8 +77,8 @@ trait SoftDelete */ public static function destroy($data, $force = false) { - $model = new static(); - $query = $model->db(); + // 包含软删除数据 + $query = self::withTrashed(); if (is_array($data) && key($data) !== 0) { $query->where($data); $data = null; @@ -109,9 +109,13 @@ trait SoftDelete public function restore($where = []) { $name = $this->getDeleteTimeField(); + if (empty($where)) { + $pk = $this->getPk(); + $where[$pk] = $this->getData($pk); + $where[$name] = ['not null', '']; + } // 恢复删除 - return $this->isUpdate()->save([$name => null], $where); - + return $this->removeWhereField($this->getDeleteTimeField(true))->where($where)->update([$name => null]); } /** -- Gitee From 56c036635c8a0e0f7075adf7f94fb2f2246190b9 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 13 Dec 2016 18:05:41 +0800 Subject: [PATCH 0266/1170] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/traits/model/SoftDelete.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/library/traits/model/SoftDelete.php b/library/traits/model/SoftDelete.php index 281c26c9..1a69c2c5 100644 --- a/library/traits/model/SoftDelete.php +++ b/library/traits/model/SoftDelete.php @@ -2,6 +2,8 @@ namespace traits\model; +use think\db\Query; + trait SoftDelete { @@ -22,7 +24,7 @@ trait SoftDelete /** * 查询软删除数据 * @access public - * @return \think\db\Query + * @return Query */ public static function withTrashed() { @@ -34,7 +36,7 @@ trait SoftDelete /** * 只查询软删除数据 * @access public - * @return \think\db\Query + * @return Query */ public static function onlyTrashed() { @@ -115,13 +117,13 @@ trait SoftDelete $where[$name] = ['not null', '']; } // 恢复删除 - return $this->removeWhereField($this->getDeleteTimeField(true))->where($where)->update([$name => null]); + return $this->db(false)->removeWhereField($this->getDeleteTimeField(true))->where($where)->update([$name => null]); } /** * 查询默认不包含软删除数据 * @access protected - * @param \think\db\Query $query 查询对象 + * @param Query $query 查询对象 * @return void */ protected function base($query) -- Gitee From 78e598045186a70ab2506d3c216c1bedcf21b8bc Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 14 Dec 2016 13:56:19 +0800 Subject: [PATCH 0267/1170] =?UTF-8?q?=E4=B8=80=E5=AF=B9=E4=B8=80=E5=85=B3?= =?UTF-8?q?=E8=81=94=E5=AE=9A=E4=B9=89=E6=94=AF=E6=8C=81=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E5=85=B3=E8=81=94=E6=A8=A1=E5=9E=8B=E5=B1=9E=E6=80=A7=E5=88=B0?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E6=A8=A1=E5=9E=8B=20=E5=9C=A8=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=85=B3=E8=81=94=E7=9A=84=E6=97=B6=E5=80=99=E4=BD=BF?= =?UTF-8?q?=E7=94=A8bind=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lang/zh-cn.php | 1 + library/think/model/relation/BelongsTo.php | 16 +++++++- library/think/model/relation/HasOne.php | 15 +++++++- library/think/model/relation/OneToOne.php | 44 +++++++++++++++++++++- 4 files changed, 71 insertions(+), 5 deletions(-) diff --git a/lang/zh-cn.php b/lang/zh-cn.php index db43a1c4..b3fef357 100644 --- a/lang/zh-cn.php +++ b/lang/zh-cn.php @@ -62,4 +62,5 @@ return [ 'sae mc write error' => 'SAE mc 写入错误', 'route name not exists' => '路由标识不存在(或参数不够)', 'invalid request' => '非法请求', + 'bind attr has exists' => '模型的属性已经存在', ]; diff --git a/library/think/model/relation/BelongsTo.php b/library/think/model/relation/BelongsTo.php index 7626caf7..b29355a0 100644 --- a/library/think/model/relation/BelongsTo.php +++ b/library/think/model/relation/BelongsTo.php @@ -85,7 +85,13 @@ class BelongsTo extends OneToOne if (!isset($data[$result->$foreignKey])) { $data[$result->$foreignKey] = []; } - $result->setAttr($relation, $this->resultSetBuild($data[$result->$foreignKey], $class)); + $relationModel = $this->resultSetBuild($data[$result->$foreignKey], $class); + if (!empty($this->bindAttr)) { + // 绑定关联属性 + $this->bindAttr($relationModel, $result, $this->bindAttr); + } + // 设置关联属性 + $result->setAttr($relation, $relationModel); } } } @@ -109,7 +115,13 @@ class BelongsTo extends OneToOne if (!isset($data[$result->$foreignKey])) { $data[$result->$foreignKey] = []; } - $result->setAttr($relation, $this->resultSetBuild($data[$result->$foreignKey], $class)); + $relationModel = $this->resultSetBuild($data[$result->$foreignKey], $class); + if (!empty($this->bindAttr)) { + // 绑定关联属性 + $this->bindAttr($relationModel, $result, $this->bindAttr); + } + // 设置关联属性 + $result->setAttr($relation, $relationModel); } } diff --git a/library/think/model/relation/HasOne.php b/library/think/model/relation/HasOne.php index e76fbbaf..fbfc8042 100644 --- a/library/think/model/relation/HasOne.php +++ b/library/think/model/relation/HasOne.php @@ -111,7 +111,13 @@ class HasOne extends OneToOne if (!isset($data[$result->$localKey])) { $data[$result->$localKey] = []; } - $result->setAttr($relation, $this->resultSetBuild($data[$result->$localKey], $class)); + $relationModel = $this->resultSetBuild($data[$result->$localKey], $class); + if (!empty($this->bindAttr)) { + // 绑定关联属性 + $this->bindAttr($relationModel, $result, $this->bindAttr); + } + // 设置关联属性 + $result->setAttr($relation, $relationModel); } } } @@ -135,7 +141,12 @@ class HasOne extends OneToOne if (!isset($data[$result->$localKey])) { $data[$result->$localKey] = []; } - $result->setAttr($relation, $this->resultSetBuild($data[$result->$localKey], $class)); + $relationModel = $this->resultSetBuild($data[$result->$localKey], $class); + if (!empty($this->bindAttr)) { + // 绑定关联属性 + $this->bindAttr($relationModel, $result, $this->bindAttr); + } + $result->setAttr($relation, $relationModel); } } diff --git a/library/think/model/relation/OneToOne.php b/library/think/model/relation/OneToOne.php index 354d718d..fb36591f 100644 --- a/library/think/model/relation/OneToOne.php +++ b/library/think/model/relation/OneToOne.php @@ -12,6 +12,7 @@ namespace think\model\relation; use think\db\Query; +use think\Exception; use think\Loader; use think\Model; use think\model\Relation; @@ -21,6 +22,8 @@ abstract class OneToOne extends Relation { // 预载入方式 protected $eagerlyType = 0; + // 要绑定的属性 + protected $bindAttr = []; /** * 预载入关联查询(JOIN方式) @@ -161,6 +164,21 @@ abstract class OneToOne extends Relation return $this->eagerlyType; } + /** + * 绑定关联表的属性到父模型属性 + * @access public + * @param mixed $attr 要绑定的属性列表 + * @return this + */ + public function bind($attr) + { + if (is_string($attr)) { + $attr = explode(',', $attr); + } + $this->bindAttr = $attr; + return $this; + } + /** * 一对一 关联模型预查询拼装 * @access public @@ -181,8 +199,32 @@ abstract class OneToOne extends Relation } } } + if (isset($list[$relation])) { + $relationModel = new $model($list[$relation]); + if (!empty($this->bindAttr)) { + $this->bindAttr($relationModel, $result, $this->bindAttr); + } + } + $result->setAttr($relation, !isset($relationModel) ? null : $relationModel->isUpdate(true)); + } - $result->setAttr($relation, !isset($list[$relation]) ? null : (new $model($list[$relation]))->isUpdate(true)); + /** + * 绑定关联属性到父模型 + * @access protected + * @param Model $model 关联模型对象 + * @param Model $result 父模型对象 + * @param array $bindAttr 绑定属性 + * @return void + */ + protected function bindAttr($model, &$result, $bindAttr) + { + foreach ($bindAttr as $key => $attr) { + if (!isset($result->$attr)) { + $result->setAttr(is_numeric($key) ? $attr : $key, $model->$attr); + } else { + throw new Exception('bind attr has exists:' . $attr); + } + } } /** -- Gitee From 5ba052d94fb749cfc60373441ba553e5f7711c9f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 14 Dec 2016 14:23:20 +0800 Subject: [PATCH 0268/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/relation/OneToOne.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/library/think/model/relation/OneToOne.php b/library/think/model/relation/OneToOne.php index fb36591f..0165314f 100644 --- a/library/think/model/relation/OneToOne.php +++ b/library/think/model/relation/OneToOne.php @@ -219,10 +219,11 @@ abstract class OneToOne extends Relation protected function bindAttr($model, &$result, $bindAttr) { foreach ($bindAttr as $key => $attr) { - if (!isset($result->$attr)) { - $result->setAttr(is_numeric($key) ? $attr : $key, $model->$attr); + $key = is_numeric($key) ? $attr : $key; + if (isset($result->$key)) { + throw new Exception('bind attr has exists:' . $key); } else { - throw new Exception('bind attr has exists:' . $attr); + $result->setAttr($key, $model->$attr); } } } -- Gitee From c0b858073824797100c317fc068b29b56ec0e9ee Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 14 Dec 2016 15:03:00 +0800 Subject: [PATCH 0269/1170] =?UTF-8?q?Model=E7=B1=BB=E5=A2=9E=E5=8A=A0appen?= =?UTF-8?q?dRelationAttr=E6=96=B9=E6=B3=95=E7=94=A8=E4=BA=8E=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=E5=85=B3=E8=81=94=E6=A8=A1=E5=9E=8B=E7=9A=84=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E5=88=B0=E5=BD=93=E5=89=8D=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/library/think/Model.php b/library/think/Model.php index 1a9677d4..7e00d60a 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -500,6 +500,28 @@ abstract class Model implements \JsonSerializable, \ArrayAccess return $this; } + /** + * 设置附加关联对象的属性 + * @access public + * @param string $relation 关联方法 + * @param string|array $append 追加属性名 + * @return $this + */ + public function appendRelationAttr($relation, $append) + { + if (is_string($append)) { + $append = explode(',', $append); + } + $model = $this->getAttr($relation); + if ($model instanceof Model) { + foreach ($append as $key => $attr) { + $key = is_numeric($key) ? $attr : $key; + $this->setAttr($key, $model->$attr); + } + } + return $this; + } + /** * 设置需要隐藏的输出属性 * @access public -- Gitee From 08c3be7c4c31d779dfbeaae351715cfaa3190dff Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 14 Dec 2016 15:08:07 +0800 Subject: [PATCH 0270/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E5=85=B3=E8=81=94=E6=A8=A1=E5=9E=8B=E5=B1=9E=E6=80=A7=E7=9A=84?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/think/Model.php b/library/think/Model.php index 7e00d60a..1d34a366 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -516,7 +516,11 @@ abstract class Model implements \JsonSerializable, \ArrayAccess if ($model instanceof Model) { foreach ($append as $key => $attr) { $key = is_numeric($key) ? $attr : $key; - $this->setAttr($key, $model->$attr); + if ($this->__isset($key)) { + throw new Exception('bind attr has exists:' . $key); + } else { + $this->setAttr($key, $model->$attr); + } } } return $this; -- Gitee From d96c39cb1cd145eab52458494296c9e6c7de0631 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 14 Dec 2016 16:57:15 +0800 Subject: [PATCH 0271/1170] =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=B1=BB=E7=9A=84?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E6=96=B9=E6=B3=95=E6=94=AF=E6=8C=81=E7=AC=AC?= =?UTF-8?q?=E4=BA=94=E4=B8=AAtitle=E5=8F=82=E6=95=B0=E4=BC=A0=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index 5d838d2a..f97813c1 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -390,7 +390,7 @@ class Validate // 验证类型 $callback = isset(self::$type[$type]) ? self::$type[$type] : [$this, $type]; // 验证数据 - $result = call_user_func_array($callback, [$value, $rule, $data, $field]); + $result = call_user_func_array($callback, [$value, $rule, $data, $field, $title]); } else { $result = true; } -- Gitee From 0fe0edb80e5dba5b99d2e2bd04d76a70762133a3 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 14 Dec 2016 21:57:58 +0800 Subject: [PATCH 0272/1170] =?UTF-8?q?=E5=9B=9E=E9=80=80=E4=B8=80=E4=B8=AAA?= =?UTF-8?q?pp=E7=B1=BB=E7=9A=84=E6=9B=B4=E8=B5=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/App.php b/library/think/App.php index 09176ba5..01af92ce 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -175,7 +175,7 @@ class App $type = $isAjax ? Config::get('default_ajax_return') : Config::get('default_return_type'); $response = Response::create($data, $type); } else { - $response = Response::create('', '', 204); + $response = Response::create(); } // 监听app_end -- Gitee From ce590c2e5345ceaee62f002aa6ec111e60ed4700 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 15 Dec 2016 12:29:51 +0800 Subject: [PATCH 0273/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BRequest=E7=B1=BB?= =?UTF-8?q?=E7=9A=84accept=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Request.php b/library/think/Request.php index a30180a8..3974d893 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -455,7 +455,7 @@ class Request */ public function type() { - $accept = isset($this->server['HTTP_ACCEPT']) ? $this->server['HTTP_ACCEPT'] : $_SERVER['HTTP_ACCEPT']; + $accept = $this->server('HTTP_ACCEPT'); if (empty($accept)) { return false; } -- Gitee From 3cfd718c3808f06c377db2f33d4c3c34b45b3280 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 16 Dec 2016 14:34:44 +0800 Subject: [PATCH 0274/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E8=A1=8C=E6=A8=A1=E5=BC=8F=E4=B8=8B=20=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E5=86=99=E5=85=A5=E5=87=BA=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 12 ++++++------ library/think/log/driver/File.php | 2 +- library/think/log/driver/Socket.php | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/library/think/Request.php b/library/think/Request.php index 3974d893..086e366e 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -257,7 +257,7 @@ class Request } /** - * 获取当前包含协议的域名 + * 设置或获取当前包含协议的域名 * @access public * @param string $domain 域名 * @return string @@ -274,7 +274,7 @@ class Request } /** - * 获取当前完整URL 包括QUERY_STRING + * 设置或获取当前完整URL 包括QUERY_STRING * @access public * @param string|true $url URL地址 true 带域名获取 * @return string @@ -301,7 +301,7 @@ class Request } /** - * 获取当前URL 不含QUERY_STRING + * 设置或获取当前URL 不含QUERY_STRING * @access public * @param string $url URL地址 * @return string @@ -319,7 +319,7 @@ class Request } /** - * 获取当前执行的文件 SCRIPT_NAME + * 设置或获取当前执行的文件 SCRIPT_NAME * @access public * @param string $file 当前执行的文件 * @return string @@ -351,7 +351,7 @@ class Request } /** - * 获取URL访问根地址 + * 设置或获取URL访问根地址 * @access public * @param string $url URL地址 * @return string @@ -602,7 +602,7 @@ class Request } /** - * 设置获取获取当前请求的参数 + * 获取获取当前请求的参数 * @access public * @param string|array $name 变量名 * @param mixed $default 默认值 diff --git a/library/think/log/driver/File.php b/library/think/log/driver/File.php index f9358a9d..b639fd04 100644 --- a/library/think/log/driver/File.php +++ b/library/think/log/driver/File.php @@ -63,7 +63,7 @@ class File $current_uri = "cmd:" . implode(' ', $_SERVER['argv']); } - $runtime = number_format(microtime(true) - THINK_START_TIME, 10); + $runtime = round(microtime(true) - THINK_START_TIME, 10); $reqs = $runtime > 0 ? number_format(1 / $runtime, 2) : '∞'; $time_str = ' [运行时间:' . number_format($runtime, 6) . 's][吞吐率:' . $reqs . 'req/s]'; $memory_use = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2); diff --git a/library/think/log/driver/Socket.php b/library/think/log/driver/Socket.php index cc4a8e12..018c211b 100644 --- a/library/think/log/driver/Socket.php +++ b/library/think/log/driver/Socket.php @@ -65,7 +65,7 @@ class Socket } $trace = []; if (App::$debug) { - $runtime = number_format(microtime(true) - THINK_START_TIME, 10); + $runtime = round(microtime(true) - THINK_START_TIME, 10); $reqs = $runtime > 0 ? number_format(1 / $runtime, 2) : '∞'; $time_str = ' [运行时间:' . number_format($runtime, 6) . 's][吞吐率:' . $reqs . 'req/s]'; $memory_use = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2); -- Gitee From 0bef3d8944870208380ae091561be1aa23752e6c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 16 Dec 2016 14:44:52 +0800 Subject: [PATCH 0275/1170] =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/thinkphp/library/think/requestTest.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/thinkphp/library/think/requestTest.php b/tests/thinkphp/library/think/requestTest.php index ef5f8e98..7d89fa36 100644 --- a/tests/thinkphp/library/think/requestTest.php +++ b/tests/thinkphp/library/think/requestTest.php @@ -90,12 +90,14 @@ class requestTest extends \PHPUnit_Framework_TestCase public function testType() { - $request = Request::instance(); - $_SERVER['HTTP_ACCEPT'] = 'application/json'; + $request = Request::instance(); + $request->server(['HTTP_ACCEPT' => 'application/json']); + $this->assertEquals('json', $request->type()); $request->mimeType('test', 'application/test'); $request->mimeType(['test' => 'application/test']); - $_SERVER['HTTP_ACCEPT'] = 'application/test'; + $request->server(['HTTP_ACCEPT' => 'application/test']); + $this->assertEquals('test', $request->type()); } -- Gitee From 1aa60c7d71442697affdfe1d8554a5a83ecf152e Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 16 Dec 2016 16:03:04 +0800 Subject: [PATCH 0276/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3socket=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E9=A9=B1=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/log/driver/Socket.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/think/log/driver/Socket.php b/library/think/log/driver/Socket.php index 018c211b..612a9021 100644 --- a/library/think/log/driver/Socket.php +++ b/library/think/log/driver/Socket.php @@ -11,6 +11,8 @@ namespace think\log\driver; +use think\App; + /** * github: https://github.com/luofei614/SocketLog * @author luofei614 -- Gitee From 4d21d3c953aaf82881b75dad69868891cf4e8285 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 16 Dec 2016 18:04:11 +0800 Subject: [PATCH 0277/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9Bsession=E9=A9=B1?= =?UTF-8?q?=E5=8A=A8=E7=9A=84read=E6=96=B9=E6=B3=95=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=80=BC=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/session/driver/Memcache.php | 2 +- library/think/session/driver/Memcached.php | 2 +- library/think/session/driver/Redis.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/think/session/driver/Memcache.php b/library/think/session/driver/Memcache.php index 4ef044a4..78320864 100644 --- a/library/think/session/driver/Memcache.php +++ b/library/think/session/driver/Memcache.php @@ -79,7 +79,7 @@ class Memcache extends SessionHandler */ public function read($sessID) { - return $this->handler->get($this->config['session_name'] . $sessID); + return (string) $this->handler->get($this->config['session_name'] . $sessID); } /** diff --git a/library/think/session/driver/Memcached.php b/library/think/session/driver/Memcached.php index 01d0f1e0..c5df23dc 100644 --- a/library/think/session/driver/Memcached.php +++ b/library/think/session/driver/Memcached.php @@ -87,7 +87,7 @@ class Memcached extends SessionHandler */ public function read($sessID) { - return $this->handler->get($this->config['session_name'] . $sessID); + return (string) $this->handler->get($this->config['session_name'] . $sessID); } /** diff --git a/library/think/session/driver/Redis.php b/library/think/session/driver/Redis.php index 52f14ab7..b1632f9e 100644 --- a/library/think/session/driver/Redis.php +++ b/library/think/session/driver/Redis.php @@ -81,11 +81,11 @@ class Redis extends SessionHandler * 读取Session * @access public * @param string $sessID - * @return bool|string + * @return string */ public function read($sessID) { - return $this->handler->get($this->config['session_name'] . $sessID); + return (string) $this->handler->get($this->config['session_name'] . $sessID); } /** -- Gitee From 157c26a7aaea46d78c6baa6089ce096898e03375 Mon Sep 17 00:00:00 2001 From: chunice Date: Fri, 16 Dec 2016 19:41:11 +0800 Subject: [PATCH 0278/1170] =?UTF-8?q?=E5=88=9B=E5=BB=BADb=E7=B1=BB?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/thinkphp/library/think/dbTest.php | 328 +++++++++++++++++++++++- 1 file changed, 327 insertions(+), 1 deletion(-) diff --git a/tests/thinkphp/library/think/dbTest.php b/tests/thinkphp/library/think/dbTest.php index 9019917e..f44b6b6c 100644 --- a/tests/thinkphp/library/think/dbTest.php +++ b/tests/thinkphp/library/think/dbTest.php @@ -11,6 +11,7 @@ /** * Db类测试 + * @author: 刘志淳 */ namespace tests\thinkphp\library\think; @@ -19,9 +20,334 @@ use \think\Db; class dbTest extends \PHPUnit_Framework_TestCase { + // 获取测试数据库配置 + private function getConfig() + { + return [ + // 数据库类型 + 'type' => 'mysql', + // 服务器地址 + 'hostname' => '127.0.0.1', + // 数据库名 + 'database' => 'test', + // 用户名 + 'username' => 'root', + // 密码 + 'password' => '', + // 端口 + 'hostport' => '', + // 连接dsn + 'dsn' => '', + // 数据库连接参数 + 'params' => [], + // 数据库编码默认采用utf8 + 'charset' => 'utf8', + // 数据库表前缀 + 'prefix' => 'tp_', + // 数据库调试模式 + 'debug' => true, + // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) + 'deploy' => 0, + // 数据库读写是否分离 主从式有效 + 'rw_separate' => false, + // 读写分离后 主服务器数量 + 'master_num' => 1, + // 指定从服务器序号 + 'slave_no' => '', + // 是否严格检查字段是否存在 + 'fields_strict' => true, + // 数据集返回类型 array 数组 collection Collection对象 + 'resultset_type' => 'array', + // 是否自动写入时间戳字段 + 'auto_timestamp' => false, + // 是否需要进行SQL性能分析 + 'sql_explain' => false, + ]; + } + + // 获取创建数据库 SQL + private function getCreateTableSql() + { + $sql[] = <<execute('show databases'); + $config = $this->getConfig(); + $result = Db::connect($config)->execute('show databases'); + $this->assertNotEmpty($result); + } + + public function testExecute() + { + $config = $this->getConfig(); + $sql = $this->getCreateTableSql(); + foreach ($sql as $one) { + Db::connect($config)->execute($one); + } + $tableNum = Db::connect($config)->execute("show tables;"); + $this->assertEquals(4, $tableNum); + } + + public function testQuery() + { + $config = $this->getConfig(); + $sql = $this->getCreateTableSql(); + Db::connect($config)->batchQuery($sql); + + $tableQueryResult = Db::connect($config)->query("show tables;"); + + $this->assertTrue(is_array($tableQueryResult)); + + $tableNum = count($tableQueryResult); + $this->assertEquals(4, $tableNum); + } + + public function testBatchQuery() + { + $config = $this->getConfig(); + $sql = $this->getCreateTableSql(); + Db::connect($config)->batchQuery($sql); + + $tableNum = Db::connect($config)->execute("show tables;"); + $this->assertEquals(4, $tableNum); + } + + public function testTable() + { + $config = $this->getConfig(); + $tableName = 'tp_user'; + $result = Db::connect($config)->table($tableName); + $this->assertEquals($tableName, $result->getOptions()['table']); + } + + public function testName() + { + $config = $this->getConfig(); + $tableName = 'user'; + $result = Db::connect($config)->name($tableName); + $this->assertEquals($config['prefix'] . $tableName, $result->getOptions()['table']); + } + + public function testInsert() + { + $config = $this->getConfig(); + $data = [ + 'username' => 'chunice', + 'password' => md5('chunice'), + 'status' => 1, + 'create_time' => time() + ]; + $result = Db::connect($config)->name('user')->insert($data); + $this->assertEquals(1, $result); + } + + public function testUpdate() + { + $config = $this->getConfig(); + $data = [ + 'username' => 'chunice_update', + 'password' => md5('chunice'), + 'status' => 1, + 'create_time' => time() + ]; + $result = Db::connect($config)->name('user')->where('username', 'chunice')->update($data); + $this->assertEquals(1, $result); + } + + public function testFind() + { + $config = $this->getConfig(); + $mustFind = Db::connect($config)->name('user')->where('username', 'chunice_update')->find(); + $this->assertNotEmpty($mustFind); + $mustNotFind = Db::connect($config)->name('user')->where('username', 'chunice')->find(); + $this->assertEmpty($mustNotFind); + } + + public function testInsertAll() + { + $config = $this->getConfig(); + + $data = [ + ['username' => 'foo', 'password' => md5('foo'), 'status' => 1, 'create_time' => time()], + ['username' => 'bar', 'password' => md5('bar'), 'status' => 1, 'create_time' => time()] + ]; + + $insertNum = Db::connect($config)->name('user')->insertAll($data); + $this->assertEquals(count($data), $insertNum); + } + + public function testSelect() + { + $config = $this->getConfig(); + $mustFound = Db::connect($config)->name('user')->where('status', 1)->select(); + $this->assertNotEmpty($mustFound); + $mustNotFound = Db::connect($config)->name('user')->where('status', 0)->select(); + $this->assertEmpty($mustNotFound); + } + + public function testValue() + { + $config = $this->getConfig(); + $username = Db::connect($config)->name('user')->where('id', 1)->value('username'); + $this->assertEquals('chunice_update', $username); + $usernameNull = Db::connect($config)->name('user')->where('id', 0)->value('username'); + $this->assertEmpty($usernameNull); } + public function testColumn() + { + $config = $this->getConfig(); + $username = Db::connect($config)->name('user')->where('status', 1)->column('username'); + $this->assertNotEmpty($username); + $usernameNull = Db::connect($config)->name('user')->where('status', 0)->column('username'); + $this->assertEmpty($usernameNull); + + } + + public function testInsertGetId() + { + $config = $this->getConfig(); + $id = Db::connect($config)->name('user')->order('id', 'desc')->value('id'); + + $data = [ + 'username' => uniqid(), + 'password' => md5('chunice'), + 'status' => 1, + 'create_time' => time() + ]; + $lastId = Db::connect($config)->name('user')->insertGetId($data); + $this->assertEquals($id + 1, $lastId); + + } + + public function testGetLastInsId() + { + $config = $this->getConfig(); + $data = [ + 'username' => uniqid(), + 'password' => md5('chunice'), + 'status' => 1, + 'create_time' => time() + ]; + $lastId = Db::connect($config)->name('user')->insertGetId($data); + + $lastInsId = Db::connect($config)->name('user')->getLastInsID(); + $this->assertEquals($lastId, $lastInsId); + } + + public function testSetField() + { + $config = $this->getConfig(); + + $setFieldNum = Db::connect($config)->name('user')->where('id', 1)->setField('username', 'chunice_setField'); + $this->assertEquals(1, $setFieldNum); + + $setFieldNum = Db::connect($config)->name('user')->where('id', 1)->setField('username', 'chunice_setField'); + $this->assertEquals(0, $setFieldNum); + } + + public function testSetInc() + { + $config = $this->getConfig(); + $originCreateTime = Db::connect($config)->name('user')->where('id', 1)->value('create_time'); + Db::connect($config)->name('user')->where('id', 1)->setInc('create_time'); + $newCreateTime = Db::connect($config)->name('user')->where('id', 1)->value('create_time'); + $this->assertEquals($originCreateTime + 1, $newCreateTime); + + } + + public function testSetDec() + { + $config = $this->getConfig(); + $originCreateTime = Db::connect($config)->name('user')->where('id', 1)->value('create_time'); + Db::connect($config)->name('user')->where('id', 1)->setDec('create_time'); + $newCreateTime = Db::connect($config)->name('user')->where('id', 1)->value('create_time'); + $this->assertEquals($originCreateTime - 1, $newCreateTime); + } + + public function testDelete() + { + $config = $this->getConfig(); + Db::connect($config)->name('user')->where('id', 1)->delete(); + $result = Db::connect($config)->name('user')->where('id', 1)->find(); + $this->assertEmpty($result); + } + + public function testChunk() + { + // todo 暂未想到测试方法 + } + + public function testCache() + { + $config = $this->getConfig(); + $result = Db::connect($config)->name('user')->where('id', 1)->cache('key', 60)->select(); + $cache = \think\Cache::get('key'); + $this->assertEquals($result, $cache); + + $updateCache = Db::connect($config)->name('user')->cache('key')->find(2); + $this->assertNotEquals($cache, $updateCache); + } + + } -- Gitee From e2ab86b9623ccd4dff3d0aa6f72f282547b5a6dd Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 18 Dec 2016 08:21:35 +0800 Subject: [PATCH 0279/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BHook=E7=B1=BB=20?= =?UTF-8?q?=E6=94=B9=E8=BF=9BModel=E7=B1=BB=E6=97=B6=E9=97=B4=E6=88=B3?= =?UTF-8?q?=E5=86=99=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Hook.php | 208 ++++++++++++++++++++-------------------- library/think/Model.php | 3 +- 2 files changed, 107 insertions(+), 104 deletions(-) diff --git a/library/think/Hook.php b/library/think/Hook.php index 062ac962..f247c621 100644 --- a/library/think/Hook.php +++ b/library/think/Hook.php @@ -1,5 +1,4 @@ $behavior) { - self::add($tag, $behavior); - } - } else { - self::$tags = $tags + self::$tags; - } - } + /** + * 批量导入插件 + * @param array $tags 插件信息 + * @param boolean $recursive 是否递归合并 + */ + public static function import(array $tags, $recursive = true) + { + if ($recursive) { + foreach ($tags as $tag => $behavior) { + self::add($tag, $behavior); + } + } else { + self::$tags = $tags + self::$tags; + } + } - /** - * 获取插件信息 - * @param string $tag 插件位置 留空获取全部 - * @return array - */ - public static function get($tag = '') - { - if (empty($tag)) {//获取全部的插件信息 - return self::$tags; - } else { - return array_key_exists($tag, self::$tags) ? self::$tags[$tag] : []; - } - } + /** + * 获取插件信息 + * @param string $tag 插件位置 留空获取全部 + * @return array + */ + public static function get($tag = '') + { + if (empty($tag)) { + //获取全部的插件信息 + return self::$tags; + } else { + return array_key_exists($tag, self::$tags) ? self::$tags[$tag] : []; + } + } - /** - * 监听标签的行为 - * @param string $tag 标签名称 - * @param mixed $params 传入参数 - * @param mixed $extra 额外参数 - * @param bool $once 只获取一个有效返回值 - * @return mixed - */ - public static function listen($tag, &$params = null, $extra = null, $once = false) - { - $results = []; - $tags = static::get($tag); - foreach ($tags as $key => $name) { - $results[$key] = self::exec($name, $tag, $params, $extra); - if (false === $results[$key]) {// 如果返回false 则中断行为执行 - break; - } elseif (!is_null($results[$key]) && $once) { - break; - } - } - return $once ? end($results) : $results; - } + /** + * 监听标签的行为 + * @param string $tag 标签名称 + * @param mixed $params 传入参数 + * @param mixed $extra 额外参数 + * @param bool $once 只获取一个有效返回值 + * @return mixed + */ + public static function listen($tag, &$params = null, $extra = null, $once = false) + { + $results = []; + $tags = static::get($tag); + foreach ($tags as $key => $name) { + $results[$key] = self::exec($name, $tag, $params, $extra); + if (false === $results[$key]) { + // 如果返回false 则中断行为执行 + break; + } elseif (!is_null($results[$key]) && $once) { + break; + } + } + return $once ? end($results) : $results; + } - /** - * 执行某个行为 - * @param mixed $class 要执行的行为 - * @param string $tag 方法名(标签名) - * @param Mixed $params 传人的参数 - * @param mixed $extra 额外参数 - * @return mixed - */ - public static function exec($class, $tag = '', &$params = null, $extra = null) - { - App::$debug && Debug::remark('behavior_start', 'time'); - if (is_callable($class)) { - $result = call_user_func_array($class, [ & $params, $extra]); - $class = 'Closure'; - } elseif (is_object($class)) { - $result = call_user_func_array([$class, $tag], [ & $params, $extra]); - $class = get_class($class); - } else { - $obj = new $class(); - $result = ($tag && is_callable([$obj, $tag])) ? $obj->$tag($params, $extra) : $obj->run($params, $extra); - } - if (App::$debug) { - Debug::remark('behavior_end', 'time'); - Log::record('[ BEHAVIOR ] Run ' . $class . ' @' . $tag . ' [ RunTime:' . Debug::getRangeTime('behavior_start', 'behavior_end') . 's ]', 'info'); - } - return $result; - } + /** + * 执行某个行为 + * @param mixed $class 要执行的行为 + * @param string $tag 方法名(标签名) + * @param Mixed $params 传人的参数 + * @param mixed $extra 额外参数 + * @return mixed + */ + public static function exec($class, $tag = '', &$params = null, $extra = null) + { + App::$debug && Debug::remark('behavior_start', 'time'); + if (is_callable($class)) { + $result = call_user_func_array($class, [ & $params, $extra]); + $class = 'Closure'; + } elseif (is_object($class)) { + $result = $class->$tag($params, $extra); + $class = get_class($class); + } else { + $obj = new $class(); + $method = ($tag && is_callable([$obj, $tag])) ? $tag : 'run'; + $result = $obj->$method($params, $extra); + } + if (App::$debug) { + Debug::remark('behavior_end', 'time'); + Log::record('[ BEHAVIOR ] Run ' . $class . ' @' . $tag . ' [ RunTime:' . Debug::getRangeTime('behavior_start', 'behavior_end') . 's ]', 'info'); + } + return $result; + } } diff --git a/library/think/Model.php b/library/think/Model.php index 1d34a366..80c224a3 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -326,7 +326,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $value = date($format, $_SERVER['REQUEST_TIME']); break; case 'timestamp': - case 'int': + case 'integer': + default: $value = $_SERVER['REQUEST_TIME']; break; } -- Gitee From efd34d53fda1ceae5a4c3ba0ddf31f2b607cd229 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 18 Dec 2016 09:44:26 +0800 Subject: [PATCH 0280/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BHook=E7=B1=BBexec?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E6=94=AF=E6=8C=81=E6=8C=87=E5=AE=9A=E7=B1=BB?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E6=B3=95=E6=89=A7=E8=A1=8C=20=E5=8C=85?= =?UTF-8?q?=E6=8B=AC=E9=9D=99=E6=80=81=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Hook.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/library/think/Hook.php b/library/think/Hook.php index f247c621..4d69ca54 100644 --- a/library/think/Hook.php +++ b/library/think/Hook.php @@ -13,6 +13,7 @@ namespace think; use think\App; use think\Debug; +use think\Loader; use think\Log; class Hook @@ -111,15 +112,23 @@ class Hook public static function exec($class, $tag = '', &$params = null, $extra = null) { App::$debug && Debug::remark('behavior_start', 'time'); - if (is_callable($class)) { + $method = Loader::parseName($tag, 1, false); + if ($class instanceof \Closure) { $result = call_user_func_array($class, [ & $params, $extra]); $class = 'Closure'; + } elseif (is_array($class)) { + list($class, $method) = $class; + + $result = (new $class())->$method($params, $extra); + $class = $class . '->' . $method; } elseif (is_object($class)) { - $result = $class->$tag($params, $extra); + $result = $class->$method($params, $extra); $class = get_class($class); + } elseif (strpos($class, '::')) { + $result = call_user_func_array($class, [ & $params, $extra]); } else { $obj = new $class(); - $method = ($tag && is_callable([$obj, $tag])) ? $tag : 'run'; + $method = ($tag && is_callable([$obj, $method])) ? $method : 'run'; $result = $obj->$method($params, $extra); } if (App::$debug) { -- Gitee From 33b9ba4a9c800d2c26496cadfaf74ee310eb2270 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 19 Dec 2016 08:55:11 +0800 Subject: [PATCH 0281/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BValidate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index f97813c1..93440cd7 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -417,7 +417,7 @@ class Validate $i++; } } - return true !== $result ? $result : true; + return $result; } /** -- Gitee From c197b1f040482bd72a52621551a7850cd1fd87d0 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 19 Dec 2016 09:00:05 +0800 Subject: [PATCH 0282/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BValidate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 116 ++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index 93440cd7..28f7c350 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -317,7 +317,12 @@ class Validate $value = $this->getDataValue($data, $key); // 字段验证 - $result = $this->checkItem($key, $value, $rule, $data, $title, $msg); + if ($rule instanceof \Closure) { + // 匿名函数验证 支持传入当前字段和所有字段两个数据 + $result = call_user_func_array($rule, [$value, $data]); + } else { + $result = $this->checkItem($key, $value, $rule, $data, $title, $msg); + } if (true !== $result) { // 没有返回true 则表示验证失败 @@ -350,72 +355,67 @@ class Validate */ protected function checkItem($field, $value, $rules, $data, $title = '', $msg = []) { - if ($rules instanceof \Closure) { - // 匿名函数验证 支持传入当前字段和所有字段两个数据 - $result = call_user_func_array($rules, [$value, $data]); - } else { - // 支持多规则验证 require|in:a,b,c|... 或者 ['require','in'=>'a,b,c',...] - if (is_string($rules)) { - $rules = explode('|', $rules); - } - $i = 0; - foreach ($rules as $key => $rule) { - if ($rule instanceof \Closure) { - $result = call_user_func_array($rule, [$value, $data]); - $info = is_numeric($key) ? '' : $key; - } else { - // 判断验证类型 - if (is_numeric($key)) { - if (strpos($rule, ':')) { - list($type, $rule) = explode(':', $rule, 2); - if (isset($this->alias[$type])) { - // 判断别名 - $type = $this->alias[$type]; - } - $info = $type; - } elseif (method_exists($this, $rule)) { - $type = $rule; - $info = $rule; - $rule = ''; - } else { - $type = 'is'; - $info = $rule; + // 支持多规则验证 require|in:a,b,c|... 或者 ['require','in'=>'a,b,c',...] + if (is_string($rules)) { + $rules = explode('|', $rules); + } + $i = 0; + foreach ($rules as $key => $rule) { + if ($rule instanceof \Closure) { + $result = call_user_func_array($rule, [$value, $data]); + $info = is_numeric($key) ? '' : $key; + } else { + // 判断验证类型 + if (is_numeric($key)) { + if (strpos($rule, ':')) { + list($type, $rule) = explode(':', $rule, 2); + if (isset($this->alias[$type])) { + // 判断别名 + $type = $this->alias[$type]; } + $info = $type; + } elseif (method_exists($this, $rule)) { + $type = $rule; + $info = $rule; + $rule = ''; } else { - $info = $type = $key; + $type = 'is'; + $info = $rule; } + } else { + $info = $type = $key; + } - // 如果不是require 有数据才会行验证 - if (0 === strpos($info, 'require') || (!is_null($value) && '' !== $value)) { - // 验证类型 - $callback = isset(self::$type[$type]) ? self::$type[$type] : [$this, $type]; - // 验证数据 - $result = call_user_func_array($callback, [$value, $rule, $data, $field, $title]); - } else { - $result = true; - } + // 如果不是require 有数据才会行验证 + if (0 === strpos($info, 'require') || (!is_null($value) && '' !== $value)) { + // 验证类型 + $callback = isset(self::$type[$type]) ? self::$type[$type] : [$this, $type]; + // 验证数据 + $result = call_user_func_array($callback, [$value, $rule, $data, $field, $title]); + } else { + $result = true; } + } - if (false === $result) { - // 验证失败 返回错误信息 - if (isset($msg[$i])) { - $message = $msg[$i]; - if (is_string($message) && strpos($message, '{%') === 0) { - $message = Lang::get(substr($message, 2, -1)); - } - } else { - $message = $this->getRuleMsg($field, $title, $info, $rule); - } - return $message; - } elseif (true !== $result) { - // 返回自定义错误信息 - if (is_string($result) && false !== strpos($result, ':')) { - $result = str_replace([':attribute', ':rule'], [$title, (string) $rule], $result); + if (false === $result) { + // 验证失败 返回错误信息 + if (isset($msg[$i])) { + $message = $msg[$i]; + if (is_string($message) && strpos($message, '{%') === 0) { + $message = Lang::get(substr($message, 2, -1)); } - return $result; + } else { + $message = $this->getRuleMsg($field, $title, $info, $rule); + } + return $message; + } elseif (true !== $result) { + // 返回自定义错误信息 + if (is_string($result) && false !== strpos($result, ':')) { + $result = str_replace([':attribute', ':rule'], [$title, (string) $rule], $result); } - $i++; + return $result; } + $i++; } return $result; } -- Gitee From 573eefba3dd0b1fbb1b5c89d8256d3999474b0c5 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 19 Dec 2016 15:18:51 +0800 Subject: [PATCH 0283/1170] =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E6=B8=B2=E6=9F=93?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=9B=B4=E6=8E=A5=E6=B8=B2=E6=9F=93=E6=A0=B9?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E4=B8=8B=E9=9D=A2=E7=9A=84=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=20=E4=BE=8B=E5=A6=82=20$this->fetch('/name');?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Template.php | 2 ++ library/think/view/driver/Php.php | 21 +++++++++++---------- library/think/view/driver/Think.php | 22 ++++++++++++---------- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/library/think/Template.php b/library/think/Template.php index e73bbcf8..667eac74 100644 --- a/library/think/Template.php +++ b/library/think/Template.php @@ -1067,6 +1067,8 @@ class Template } if (0 !== strpos($template, '/')) { $template = str_replace(['/', ':'], $this->config['view_depr'], $template); + } else { + $template = str_replace(['/', ':'], $this->config['view_depr'], substr($template, 1)); } if ($this->config['view_base']) { $module = isset($module) ? $module : Request::instance()->module(); diff --git a/library/think/view/driver/Php.php b/library/think/view/driver/Php.php index 863a7c17..b7028c2d 100644 --- a/library/think/view/driver/Php.php +++ b/library/think/view/driver/Php.php @@ -127,17 +127,18 @@ class Php $depr = $this->config['view_depr']; if (0 !== strpos($template, '/')) { - $template = str_replace(['/', ':'], $depr, $template); - } - - $controller = Loader::parseName($request->controller()); - if ($controller) { - if ('' == $template) { - // 如果模板文件名为空 按照默认规则定位 - $template = str_replace('.', DS, $controller) . $depr . $request->action(); - } elseif (false === strpos($template, $depr)) { - $template = str_replace('.', DS, $controller) . $depr . $template; + $template = str_replace(['/', ':'], $depr, $template); + $controller = Loader::parseName($request->controller()); + if ($controller) { + if ('' == $template) { + // 如果模板文件名为空 按照默认规则定位 + $template = str_replace('.', DS, $controller) . $depr . $request->action(); + } elseif (false === strpos($template, $depr)) { + $template = str_replace('.', DS, $controller) . $depr . $template; + } } + } else { + $template = str_replace(['/', ':'], $depr, substr($template, 1)); } return $path . ltrim($template, '/') . '.' . ltrim($this->config['view_suffix'], '.'); } diff --git a/library/think/view/driver/Think.php b/library/think/view/driver/Think.php index 8e673fde..e5336b41 100644 --- a/library/think/view/driver/Think.php +++ b/library/think/view/driver/Think.php @@ -120,18 +120,20 @@ class Think $path = isset($module) ? APP_PATH . $module . DS . 'view' . DS : $this->config['view_path']; } - $controller = Loader::parseName($request->controller()); - $depr = $this->config['view_depr']; + $depr = $this->config['view_depr']; if (0 !== strpos($template, '/')) { - $template = str_replace(['/', ':'], $depr, $template); - } - if ($controller) { - if ('' == $template) { - // 如果模板文件名为空 按照默认规则定位 - $template = str_replace('.', DS, $controller) . $depr . $request->action(); - } elseif (false === strpos($template, $depr)) { - $template = str_replace('.', DS, $controller) . $depr . $template; + $template = str_replace(['/', ':'], $depr, $template); + $controller = Loader::parseName($request->controller()); + if ($controller) { + if ('' == $template) { + // 如果模板文件名为空 按照默认规则定位 + $template = str_replace('.', DS, $controller) . $depr . $request->action(); + } elseif (false === strpos($template, $depr)) { + $template = str_replace('.', DS, $controller) . $depr . $template; + } } + } else { + $template = str_replace(['/', ':'], $depr, substr($template, 1)); } return $path . ltrim($template, '/') . '.' . ltrim($this->config['view_suffix'], '.'); } -- Gitee From c695397733a707d4434fa8f8c070c9caf1f1f369 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 20 Dec 2016 08:28:50 +0800 Subject: [PATCH 0284/1170] =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base.php b/base.php index dc43b26b..01ee13c4 100644 --- a/base.php +++ b/base.php @@ -9,7 +9,7 @@ // | Author: liu21st // +---------------------------------------------------------------------- -define('THINK_VERSION', '5.0.4beta'); +define('THINK_VERSION', '5.0.4'); define('THINK_START_TIME', microtime(true)); define('THINK_START_MEM', memory_get_usage()); define('EXT', '.php'); -- Gitee From 2ee49f5dcb8c951a92fc53ba7675b28c217a231e Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 20 Dec 2016 14:41:27 +0800 Subject: [PATCH 0285/1170] =?UTF-8?q?unique=E9=AA=8C=E8=AF=81=E8=A7=84?= =?UTF-8?q?=E5=88=99=E6=94=AF=E6=8C=81=E6=8C=87=E5=AE=9A=E5=AE=8C=E6=95=B4?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E7=B1=BB=20=E5=B9=B6=E4=B8=94=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E4=BC=9A=E4=BC=98=E5=85=88=E6=A3=80=E6=B5=8B=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E7=B1=BB=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8=20?= =?UTF-8?q?=E4=B8=8D=E5=AD=98=E5=9C=A8=E5=88=99=E6=A3=80=E6=B5=8B=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index 28f7c350..ff9a32ea 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -13,6 +13,7 @@ namespace think; use think\File; use think\Lang; +use think\Loader; use think\Request; use think\Session; @@ -812,7 +813,17 @@ class Validate if (is_string($rule)) { $rule = explode(',', $rule); } - $db = Db::name($rule[0]); + if (false !== strpos($rule[0], '\\')) { + // 指定模型类 + $db = new $rule[0]; + } else { + $model = Loader::parseClass(Request::instance()->module, 'model', $rule[0]); + if (class_exists($model)) { + $db = new $model; + } else { + $db = Db::name($rule[0]); + } + } $key = isset($rule[1]) ? $rule[1] : $field; if (strpos($key, '^')) { -- Gitee From 8b463414a4171f75e0620568b1ad9b050865b735 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 20 Dec 2016 14:50:15 +0800 Subject: [PATCH 0286/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9Bunique=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index ff9a32ea..dc2457a4 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -11,6 +11,7 @@ namespace think; +use think\exception\ClassNotFoundException; use think\File; use think\Lang; use think\Loader; @@ -817,10 +818,9 @@ class Validate // 指定模型类 $db = new $rule[0]; } else { - $model = Loader::parseClass(Request::instance()->module, 'model', $rule[0]); - if (class_exists($model)) { - $db = new $model; - } else { + try { + $db = Loader::model($rule[0]); + } catch (ClassNotFoundException $e) { $db = Db::name($rule[0]); } } -- Gitee From c83020f3875715c1b33386e596e56d9ef248701b Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 20 Dec 2016 14:53:17 +0800 Subject: [PATCH 0287/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 1 + 1 file changed, 1 insertion(+) diff --git a/library/think/Validate.php b/library/think/Validate.php index dc2457a4..1fe27d1f 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -11,6 +11,7 @@ namespace think; +use think\Db; use think\exception\ClassNotFoundException; use think\File; use think\Lang; -- Gitee From 6d85645d7935e15b8e2814491981aa22b51040aa Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 20 Dec 2016 16:03:41 +0800 Subject: [PATCH 0288/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E5=88=B0=E6=8E=A7=E5=88=B6=E5=99=A8=E7=B1=BB=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95=20=E5=AF=B9=20=E9=BB=98=E8=AE=A4=E6=B8=B2=E6=9F=93?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E7=9A=84=E5=BD=B1=E5=93=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/think/Route.php b/library/think/Route.php index d3272071..41da4652 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1493,6 +1493,10 @@ class Route $route = substr($route, 1); list($route, $var) = self::parseUrlPath($route); $result = ['type' => 'controller', 'controller' => implode('/', $route), 'var' => $var]; + $request->action(array_pop($route)); + $request->controller($route ? array_pop($route) : Config::get('default_controller')); + $request->module($route ? array_pop($route) : Config::get('default_module')); + App::$modulePath = APP_PATH . (Config::get('app_multi_module') ? $request->module() . DS : ''); } else { // 路由到模块/控制器/操作 $result = self::parseModule($route); -- Gitee From 55ca76ccaeb0653e95afafb4bf57ee0cfcbf3015 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 20 Dec 2016 22:36:17 +0800 Subject: [PATCH 0289/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BLoader=E7=B1=BB?= =?UTF-8?q?=E7=9A=84model=20controller=20=E5=92=8C=20validate=E6=96=B9?= =?UTF-8?q?=E6=B3=95=20=E6=94=AF=E6=8C=81=E7=9B=B4=E6=8E=A5=E4=BC=A0?= =?UTF-8?q?=E5=85=A5=E7=B1=BB=E5=90=8D=E5=AE=9E=E4=BE=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Loader.php | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/library/think/Loader.php b/library/think/Loader.php index 57f6a41f..effd3f4a 100644 --- a/library/think/Loader.php +++ b/library/think/Loader.php @@ -369,12 +369,16 @@ class Loader if (isset(self::$instance[$guid])) { return self::$instance[$guid]; } - if (strpos($name, '/')) { - list($module, $name) = explode('/', $name, 2); + if (strpos($name, '\\')) { + $class = $name; } else { - $module = Request::instance()->module(); + if (strpos($name, '/')) { + list($module, $name) = explode('/', $name, 2); + } else { + $module = Request::instance()->module(); + } + $class = self::parseClass($module, $layer, $name, $appendSuffix); } - $class = self::parseClass($module, $layer, $name, $appendSuffix); if (class_exists($class)) { $model = new $class(); } else { @@ -400,12 +404,16 @@ class Loader */ public static function controller($name, $layer = 'controller', $appendSuffix = false, $empty = '') { - if (strpos($name, '/')) { - list($module, $name) = explode('/', $name); + if (strpos($name, '\\')) { + $class = $name; } else { - $module = Request::instance()->module(); + if (strpos($name, '/')) { + list($module, $name) = explode('/', $name); + } else { + $module = Request::instance()->module(); + } + $class = self::parseClass($module, $layer, $name, $appendSuffix); } - $class = self::parseClass($module, $layer, $name, $appendSuffix); if (class_exists($class)) { return App::invokeClass($class); } elseif ($empty && class_exists($emptyClass = self::parseClass($module, $layer, $empty, $appendSuffix))) { @@ -432,12 +440,16 @@ class Loader if (isset(self::$instance[$guid])) { return self::$instance[$guid]; } - if (strpos($name, '/')) { - list($module, $name) = explode('/', $name); + if (strpos($name, '\\')) { + $class = $name; } else { - $module = Request::instance()->module(); + if (strpos($name, '/')) { + list($module, $name) = explode('/', $name); + } else { + $module = Request::instance()->module(); + } + $class = self::parseClass($module, $layer, $name, $appendSuffix); } - $class = self::parseClass($module, $layer, $name, $appendSuffix); if (class_exists($class)) { $validate = new $class; } else { -- Gitee From c1107d3a858bc2ce7829b6a9567ed48628598a9f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 21 Dec 2016 11:09:45 +0800 Subject: [PATCH 0290/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=81=9A=E5=90=88?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/Merge.php | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/library/think/model/Merge.php b/library/think/model/Merge.php index de8d9e1a..e9498595 100644 --- a/library/think/model/Merge.php +++ b/library/think/model/Merge.php @@ -12,6 +12,7 @@ namespace think\model; use think\Db; +use think\db\Query; use think\Model; class Merge extends Model @@ -174,6 +175,7 @@ class Merge extends Model $db = $this->db(); $db->startTrans(); + $pk = $this->getPk(); try { if ($this->isUpdate) { // 自动写入 @@ -187,19 +189,15 @@ class Merge extends Model $where = $this->updateWhere; } - if (!empty($where)) { - $pk = $this->getPk(); - - if (isset($this->mapFields[$pk])) { - $pk = $this->mapFields[$pk]; - } - if (isset($where[$pk])) { - unset($where[$pk]); - } - } - // 处理模型数据 $data = $this->parseData($this->name, $this->data); + if (is_string($pk) && isset($data[$pk])) { + if (!isset($where[$pk])) { + unset($where); + $where[$pk] = $data[$pk]; + } + unset($data[$pk]); + } // 写入主表数据 $result = $db->strict(false)->where($where)->update($data); @@ -209,7 +207,7 @@ class Merge extends Model $table = is_int($key) ? $db->getTable($model) : $model; // 处理关联模型数据 $data = $this->parseData($name, $this->data); - $query = clone $db; + $query = new Query; if ($query->table($table)->strict(false)->where($this->fk, $this->data[$this->getPk()])->update($data)) { $result = 1; } @@ -238,7 +236,6 @@ class Merge extends Model if ($result) { $insertId = $db->getLastInsID($sequence); // 写入外键数据 - $pk = $this->getPk(); if ($insertId) { if (is_string($pk)) { $this->data[$pk] = $insertId; @@ -259,7 +256,7 @@ class Merge extends Model $table = is_int($key) ? $db->getTable($model) : $model; // 处理关联模型数据 $data = $this->parseData($name, $source, true); - $query = clone $db; + $query = new Query; $query->table($table)->strict(false)->insert($data); } } -- Gitee From 8f2ed014ccb7417f548afe7e80b781518f694ef4 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 21 Dec 2016 11:22:36 +0800 Subject: [PATCH 0291/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BRequest=E7=B1=BB?= =?UTF-8?q?=E7=9A=84domain=E6=96=B9=E6=B3=95=20=E5=8C=85=E5=90=AB=E7=AB=AF?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/think/Request.php b/library/think/Request.php index 086e366e..2b0fda30 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -25,7 +25,7 @@ class Request protected $method; /** - * @var string 域名 + * @var string 域名(含协议和端口) */ protected $domain; @@ -270,6 +270,9 @@ class Request } elseif (!$this->domain) { $this->domain = $this->scheme() . '://' . $this->host(); } + if (80 != $this->port()) { + $this->domain .= ':' . $this->port(); + } return $this->domain; } -- Gitee From d898ab35de7140f5a9d0836baedd8e3fefa6541d Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 21 Dec 2016 12:06:09 +0800 Subject: [PATCH 0292/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BRequest=E7=B1=BBdom?= =?UTF-8?q?ain=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/think/Request.php b/library/think/Request.php index 2b0fda30..9cd4ccf1 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -269,9 +269,9 @@ class Request return $this; } elseif (!$this->domain) { $this->domain = $this->scheme() . '://' . $this->host(); - } - if (80 != $this->port()) { - $this->domain .= ':' . $this->port(); + if (!in_array($this->port(), ['80', '443'])) { + $this->domain .= ':' . $this->port(); + } } return $this->domain; } -- Gitee From 6bd6d03440eefffe34f7b114665164ee16133cfe Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 21 Dec 2016 12:14:37 +0800 Subject: [PATCH 0293/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Model=E7=B1=BB?= =?UTF-8?q?=E7=9A=84useGlobalScope=E6=96=B9=E6=B3=95=E6=97=A0=E6=95=88?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 80c224a3..dc7002d7 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -151,7 +151,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess if (is_null($this->autoWriteTimestamp)) { // 自动写入时间戳 - $this->autoWriteTimestamp = $this->db()->getConfig('auto_timestamp'); + $this->autoWriteTimestamp = $this->db(false)->getConfig('auto_timestamp'); } // 执行初始化操作 @@ -634,10 +634,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess public function getPk($name = '') { if (!empty($name)) { - $table = $this->db()->getTable($name); - return $this->db()->getPk($table); + $table = $this->db(false)->getTable($name); + return $this->db(false)->getPk($table); } elseif (empty($this->pk)) { - $this->pk = $this->db()->getPk(); + $this->pk = $this->db(false)->getPk(); } return $this->pk; } @@ -834,7 +834,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess public function allowField($field) { if (true === $field) { - $field = $this->db()->getTableInfo('', 'fields'); + $field = $this->db(false)->getTableInfo('', 'fields'); } $this->field = $field; return $this; @@ -1402,7 +1402,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess // 记录当前关联信息 $model = $this->parseModel($model); $name = Loader::parseName(basename(str_replace('\\', '/', $model))); - $table = $table ?: $this->db()->getTable(Loader::parseName($this->name) . '_' . $name); + $table = $table ?: $this->db(false)->getTable(Loader::parseName($this->name) . '_' . $name); $foreignKey = $foreignKey ?: $name . '_id'; $localKey = $localKey ?: Loader::parseName($this->name) . '_id'; return new BelongsToMany($this, $model, $table, $foreignKey, $localKey, $alias); @@ -1459,7 +1459,11 @@ abstract class Model implements \JsonSerializable, \ArrayAccess public function __call($method, $args) { - $query = $this->db(); + if (isset(static::$db)) { + $query = static::$db; + } else { + $query = $this->db(); + } if (method_exists($this, 'scope' . $method)) { // 动态调用命名范围 $method = 'scope' . $method; -- Gitee From a981277c665dabc19f47e569ccbb6256fbb3d4a2 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 21 Dec 2016 12:22:24 +0800 Subject: [PATCH 0294/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BModel=E7=B1=BB?= =?UTF-8?q?=E7=9A=84useGlobalScope=E6=96=B9=E6=B3=95=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E5=90=8E=E7=9A=84=E5=85=A8=E5=B1=80=E5=BD=B1=E5=93=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index dc7002d7..52f46516 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -1187,8 +1187,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess */ public static function useGlobalScope($use) { - $model = new static(); - self::$db = $model->db($use); + $model = new static(); + static::$db = $model->db($use); return $model; } @@ -1460,10 +1460,12 @@ abstract class Model implements \JsonSerializable, \ArrayAccess public function __call($method, $args) { if (isset(static::$db)) { - $query = static::$db; + $query = static::$db; + static::$db = null; } else { $query = $this->db(); } + if (method_exists($this, 'scope' . $method)) { // 动态调用命名范围 $method = 'scope' . $method; @@ -1478,7 +1480,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess public static function __callStatic($method, $params) { if (isset(static::$db)) { - $query = static::$db; + $query = static::$db; + static::$db = null; } else { $query = (new static())->db(); } -- Gitee From f417aa66626578207b42c99eebde535050a510e8 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 21 Dec 2016 17:18:04 +0800 Subject: [PATCH 0295/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=81=9A=E5=90=88?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E7=9A=84delete=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/Merge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/model/Merge.php b/library/think/model/Merge.php index e9498595..3cf5c3f6 100644 --- a/library/think/model/Merge.php +++ b/library/think/model/Merge.php @@ -297,7 +297,7 @@ class Merge extends Model // 删除关联数据 foreach ($this->relationModel as $key => $model) { $table = is_int($key) ? $db->getTable($model) : $model; - $query = clone $db; + $query = new Query; $query->table($table)->where($this->fk, $pk)->delete(); } } -- Gitee From 565222cfeaf9801103e0683adf13a4d920378597 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 21 Dec 2016 18:11:37 +0800 Subject: [PATCH 0296/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BRequest=E7=B1=BB?= =?UTF-8?q?=E7=9A=84post=E5=92=8Cput=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/think/Request.php b/library/think/Request.php index 9cd4ccf1..cbf294ce 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -691,7 +691,7 @@ class Request if (empty($this->post)) { $content = $this->input; if (empty($_POST) && strpos($content, '":')) { - $this->post = json_decode($content, true); + $this->post = (array) json_decode($content, true); } else { $this->post = $_POST; } @@ -716,7 +716,7 @@ class Request if (is_null($this->put)) { $content = $this->input; if (strpos($content, '":')) { - $this->put = json_decode($content, true); + $this->put = (array) json_decode($content, true); } else { parse_str($content, $this->put); } -- Gitee From 83c13a741ca7f1386daa7e6c0c91e23efb15ba7d Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 22 Dec 2016 10:50:44 +0800 Subject: [PATCH 0297/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BRequest=E7=B1=BB?= =?UTF-8?q?=E7=9A=84create=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/library/think/Request.php b/library/think/Request.php index cbf294ce..2e770a8d 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -226,8 +226,9 @@ class Request if (!isset($info['path'])) { $info['path'] = '/'; } - $options = []; - $queryString = ''; + $options = []; + $options[strtolower($method)] = $params; + $queryString = ''; if (isset($info['query'])) { parse_str(html_entity_decode($info['query']), $query); if (!empty($params)) { @@ -240,6 +241,11 @@ class Request } elseif (!empty($params)) { $queryString = http_build_query($params, '', '&'); } + if ($queryString) { + parse_str($queryString, $get); + $options['get'] = isset($options['get']) ? array_merge($get, $options['get']) : $get; + } + $server['REQUEST_URI'] = $info['path'] . ('' !== $queryString ? '?' . $queryString : ''); $server['QUERY_STRING'] = $queryString; $options['cookie'] = $cookie; -- Gitee From cd57d97f36767019902e9ce525b649c78080db4d Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 22 Dec 2016 12:22:44 +0800 Subject: [PATCH 0298/1170] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=85=B3=E8=81=94?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 23 +++++++++++++++++++ library/think/db/Query.php | 22 +++++++++++++++++- .../think/model/relation/BelongsToMany.php | 20 ++++++++++++++++ library/think/model/relation/HasMany.php | 21 +++++++++++++++++ library/think/model/relation/MorphMany.php | 23 +++++++++++++++++++ 5 files changed, 108 insertions(+), 1 deletion(-) diff --git a/library/think/Model.php b/library/think/Model.php index 52f46516..a1523914 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -1308,6 +1308,29 @@ abstract class Model implements \JsonSerializable, \ArrayAccess } } + /** + * 关联统计 + * @access public + * @param Model $result 数据对象 + * @param string|array $relation 关联名 + * @return void + */ + public function relationCount(&$result, $relation) + { + $relations = is_string($relation) ? explode(',', $relation) : $relation; + + foreach ($relations as $key => $relation) { + $closure = false; + if ($relation instanceof \Closure) { + $closure = $relation; + $relation = $key; + } + $relation = Loader::parseName($relation, 1, false); + $count = $this->$relation()->relationCount($result, $closure); + $result->setAttr(Loader::parseName($relation) . '_count', $count); + } + } + /** * HAS ONE 关联定义 * @access public diff --git a/library/think/db/Query.php b/library/think/db/Query.php index ace9a90a..116b7070 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1666,6 +1666,18 @@ class Query return $this; } + /** + * 关联统计 + * @access public + * @param string|array $relation 关联方法名 + * @return $this + */ + public function withCount($relation) + { + $this->options['with_count'] = $relation; + return $this; + } + /** * 关联预加载中 获取关联指定字段值 * example: @@ -1997,6 +2009,10 @@ class Query if (!empty($options['relation'])) { $result->relationQuery($options['relation']); } + // 关联统计 + if (!empty($options['with_count'])) { + $result->relationCount($result, $options['with_count']); + } $resultSet[$key] = $result; } if (!empty($options['with'])) { @@ -2095,10 +2111,14 @@ class Query if (!empty($options['relation'])) { $data->relationQuery($options['relation']); } + // 预载入查询 if (!empty($options['with'])) { - // 预载入 $data->eagerlyResult($data, $options['with'], is_object($result) ? get_class($result) : ''); } + // 关联统计 + if (!empty($options['with_count'])) { + $data->relationCount($data, $options['with_count']); + } } } elseif (!empty($options['fail'])) { $this->throwNotFound($options); diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index b5d21680..cf831f1b 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -145,6 +145,26 @@ class BelongsToMany extends Relation } } + /** + * 关联统计 + * @access public + * @param Model $result 数据对象 + * @param \Closure $closure 闭包 + * @return integer + */ + public function relationCount($result, $closure) + { + $localKey = $this->localKey; + $foreignKey = $this->foreignKey; + $pk = $result->getPk(); + $count = 0; + if (isset($result->$pk)) { + $pk = $result->$pk; + $count = $this->belongsToManyQuery($this->middle, $foreignKey, $localKey, ['pivot.' . $localKey => $pk])->count(); + } + return $count; + } + /** * 多对多 关联模型预查询 * @access public diff --git a/library/think/model/relation/HasMany.php b/library/think/model/relation/HasMany.php index 416c5a5b..08e1e81e 100644 --- a/library/think/model/relation/HasMany.php +++ b/library/think/model/relation/HasMany.php @@ -113,6 +113,27 @@ class HasMany extends Relation } } + /** + * 关联统计 + * @access public + * @param Model $result 数据对象 + * @param \Closure $closure 闭包 + * @return integer + */ + public function relationCount($result, $closure) + { + $localKey = $this->localKey; + $foreignKey = $this->foreignKey; + $count = 0; + if (isset($result->$localKey)) { + if ($closure) { + call_user_func_array($closure, [ & $this->query]); + } + $count = $this->query->where([$foreignKey => $result->$localKey])->count(); + } + return $count; + } + /** * 一对多 关联模型预查询 * @access public diff --git a/library/think/model/relation/MorphMany.php b/library/think/model/relation/MorphMany.php index 5a2e2e9b..b2e21013 100644 --- a/library/think/model/relation/MorphMany.php +++ b/library/think/model/relation/MorphMany.php @@ -116,6 +116,29 @@ class MorphMany extends Relation } } + /** + * 关联统计 + * @access public + * @param Model $result 数据对象 + * @param \Closure $closure 闭包 + * @return integer + */ + public function relationCount($result, $closure) + { + $morphType = $this->morphType; + $morphKey = $this->morphKey; + $type = $this->type; + $pk = $result->getPk(); + $count = 0; + if (isset($result->$pk)) { + if ($closure) { + call_user_func_array($closure, [ & $this->query]); + } + $count = $this->query->where([$morphKey => $result->$pk, $morphType => $type])->count(); + } + return $count; + } + /** * 多态一对多 关联模型预查询 * @access public -- Gitee From 9657ee01b1dcb89984e1e5e5cf0ebe20b0bcfd9c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 22 Dec 2016 12:52:13 +0800 Subject: [PATCH 0299/1170] =?UTF-8?q?=E5=85=B3=E8=81=94=E9=A2=84=E8=BD=BD?= =?UTF-8?q?=E5=85=A5=E6=9F=A5=E8=AF=A2=E6=94=AF=E6=8C=81=E5=85=B3=E8=81=94?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 10 ++++++---- library/think/db/Query.php | 12 +++++++----- library/think/model/relation/BelongsToMany.php | 16 +++++++++++++--- library/think/model/relation/HasMany.php | 15 +++++++++++++-- library/think/model/relation/MorphMany.php | 15 +++++++++++++-- 5 files changed, 52 insertions(+), 16 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index a1523914..0848a108 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -1261,9 +1261,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @param array $resultSet 数据集 * @param string $relation 关联名 * @param string $class 数据集对象名 为空表示数组 + * @param bool $count 是否统计 * @return array */ - public function eagerlyResultSet(&$resultSet, $relation, $class = '') + public function eagerlyResultSet(&$resultSet, $relation, $class = '', $count = false) { $relations = is_string($relation) ? explode(',', $relation) : $relation; foreach ($relations as $key => $relation) { @@ -1277,7 +1278,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess list($relation, $subRelation) = explode('.', $relation); } $relation = Loader::parseName($relation, 1, false); - $this->$relation()->eagerlyResultSet($resultSet, $relation, $subRelation, $closure, $class); + $this->$relation()->eagerlyResultSet($resultSet, $relation, $subRelation, $closure, $class, $count); } } @@ -1287,9 +1288,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @param Model $result 数据对象 * @param string $relation 关联名 * @param string $class 数据集对象名 为空表示数组 + * @param bool $count 是否统计 * @return Model */ - public function eagerlyResult(&$result, $relation, $class = '') + public function eagerlyResult(&$result, $relation, $class = '', $count = false) { $relations = is_string($relation) ? explode(',', $relation) : $relation; @@ -1304,7 +1306,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess list($relation, $subRelation) = explode('.', $relation); } $relation = Loader::parseName($relation, 1, false); - $this->$relation()->eagerlyResult($result, $relation, $subRelation, $closure, $class); + $this->$relation()->eagerlyResult($result, $relation, $subRelation, $closure, $class, $count); } } diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 116b7070..79a30eb7 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1620,10 +1620,11 @@ class Query /** * 设置关联查询JOIN预查询 * @access public - * @param string|array $with 关联方法名称 + * @param string|array $with 关联方法名称 + * @param bool $count 是否统计 * @return $this */ - public function with($with) + public function with($with, $count = false) { if (empty($with)) { return $this; @@ -1662,7 +1663,8 @@ class Query } } $this->via(); - $this->options['with'] = $with; + $this->options['with'] = $with; + $this->options['count'] = $count; return $this; } @@ -2017,7 +2019,7 @@ class Query } if (!empty($options['with'])) { // 预载入 - $result->eagerlyResultSet($resultSet, $options['with'], is_object($resultSet) ? get_class($resultSet) : ''); + $result->eagerlyResultSet($resultSet, $options['with'], is_object($resultSet) ? get_class($resultSet) : '', !empty($options['count']) ? true : false); } } // 模型数据集转换 @@ -2113,7 +2115,7 @@ class Query } // 预载入查询 if (!empty($options['with'])) { - $data->eagerlyResult($data, $options['with'], is_object($result) ? get_class($result) : ''); + $data->eagerlyResult($data, $options['with'], is_object($result) ? get_class($result) : '', !empty($options['count']) ? true : false); } // 关联统计 if (!empty($options['with_count'])) { diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index cf831f1b..a83ac53b 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -13,6 +13,7 @@ namespace think\model\relation; use think\Db; use think\db\Query; +use think\Loader; use think\Model; use think\model\Pivot; use think\model\Relation; @@ -80,9 +81,10 @@ class BelongsToMany extends Relation * @param string $subRelation 子关联名 * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 + * @param bool $count 是否统计 * @return void */ - public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class) + public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class, $count) { $localKey = $this->localKey; $foreignKey = $this->foreignKey; @@ -110,7 +112,10 @@ class BelongsToMany extends Relation if (!isset($data[$result->$pk])) { $data[$result->$pk] = []; } - + if ($count) { + // 关联统计 + $result->setAttr(Loader::parseName($relation) . '_count', count($data[$result->$pk])); + } $result->setAttr($relation, $this->resultSetBuild($data[$result->$pk], $class)); } } @@ -124,9 +129,10 @@ class BelongsToMany extends Relation * @param string $subRelation 子关联名 * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 + * @param bool $count 是否统计 * @return void */ - public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class) + public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class, $count) { $localKey = $this->localKey; $foreignKey = $this->foreignKey; @@ -141,6 +147,10 @@ class BelongsToMany extends Relation if (!isset($data[$pk])) { $data[$pk] = []; } + if ($count) { + // 关联统计 + $result->setAttr(Loader::parseName($relation) . '_count', count($data[$pk])); + } $result->setAttr($relation, $this->resultSetBuild($data[$pk], $class)); } } diff --git a/library/think/model/relation/HasMany.php b/library/think/model/relation/HasMany.php index 08e1e81e..ed5fb0be 100644 --- a/library/think/model/relation/HasMany.php +++ b/library/think/model/relation/HasMany.php @@ -13,6 +13,7 @@ namespace think\model\relation; use think\Db; use think\db\Query; +use think\Loader; use think\Model; use think\model\Relation; @@ -54,9 +55,10 @@ class HasMany extends Relation * @param string $subRelation 子关联名 * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 + * @param bool $count 是否统计 * @return void */ - public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class) + public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class, $count) { $localKey = $this->localKey; $foreignKey = $this->foreignKey; @@ -83,6 +85,10 @@ class HasMany extends Relation if (!isset($data[$result->$localKey])) { $data[$result->$localKey] = []; } + if ($count) { + // 关联统计 + $result->setAttr(Loader::parseName($relation) . '_count', count($data[$result->$localKey])); + } $result->setAttr($relation, $this->resultSetBuild($data[$result->$localKey], $class)); } } @@ -96,9 +102,10 @@ class HasMany extends Relation * @param string $subRelation 子关联名 * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 + * @param bool $count 是否统计 * @return void */ - public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class) + public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class, $count) { $localKey = $this->localKey; $foreignKey = $this->foreignKey; @@ -109,6 +116,10 @@ class HasMany extends Relation if (!isset($data[$result->$localKey])) { $data[$result->$localKey] = []; } + if ($count) { + // 关联统计 + $result->setAttr(Loader::parseName($relation) . '_count', count($data[$result->$localKey])); + } $result->setAttr($relation, $this->resultSetBuild($data[$result->$localKey], $class)); } } diff --git a/library/think/model/relation/MorphMany.php b/library/think/model/relation/MorphMany.php index b2e21013..9340bc42 100644 --- a/library/think/model/relation/MorphMany.php +++ b/library/think/model/relation/MorphMany.php @@ -13,6 +13,7 @@ namespace think\model\relation; use think\Db; use think\db\Query; +use think\Loader; use think\Model; use think\model\Relation; @@ -60,9 +61,10 @@ class MorphMany extends Relation * @param string $subRelation 子关联名 * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 + * @param bool $count 是否统计 * @return void */ - public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class) + public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class, $count) { $morphType = $this->morphType; $morphKey = $this->morphKey; @@ -89,6 +91,10 @@ class MorphMany extends Relation if (!isset($data[$result->$pk])) { $data[$result->$pk] = []; } + if ($count) { + // 关联统计 + $result->setAttr(Loader::parseName($relation) . '_count', count($data[$result->$pk])); + } $result->setAttr($relation, $this->resultSetBuild($data[$result->$pk], $class)); } } @@ -102,9 +108,10 @@ class MorphMany extends Relation * @param string $subRelation 子关联名 * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 + * @param bool $count 是否统计 * @return void */ - public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class) + public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class, $count) { $morphType = $this->morphType; $morphKey = $this->morphKey; @@ -112,6 +119,10 @@ class MorphMany extends Relation $pk = $result->getPk(); if (isset($result->$pk)) { $data = $this->eagerlyMorphToMany([$morphKey => $result->$pk, $morphType => $type], $relation, $subRelation, $closure); + if ($count) { + // 关联统计 + $result->setAttr(Loader::parseName($relation) . '_count', count($data[$result->$pk])); + } $result->setAttr($relation, $this->resultSetBuild($data[$result->$pk], $class)); } } -- Gitee From bde2607442b8aebf7b5096ff67ae8a8996943ce7 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 22 Dec 2016 13:30:43 +0800 Subject: [PATCH 0300/1170] =?UTF-8?q?Revert=20"=E5=85=B3=E8=81=94=E9=A2=84?= =?UTF-8?q?=E8=BD=BD=E5=85=A5=E6=9F=A5=E8=AF=A2=E6=94=AF=E6=8C=81=E5=85=B3?= =?UTF-8?q?=E8=81=94=E7=BB=9F=E8=AE=A1"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 9657ee01b1dcb89984e1e5e5cf0ebe20b0bcfd9c. --- library/think/Model.php | 10 ++++------ library/think/db/Query.php | 12 +++++------- library/think/model/relation/BelongsToMany.php | 16 +++------------- library/think/model/relation/HasMany.php | 15 ++------------- library/think/model/relation/MorphMany.php | 15 ++------------- 5 files changed, 16 insertions(+), 52 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 0848a108..a1523914 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -1261,10 +1261,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @param array $resultSet 数据集 * @param string $relation 关联名 * @param string $class 数据集对象名 为空表示数组 - * @param bool $count 是否统计 * @return array */ - public function eagerlyResultSet(&$resultSet, $relation, $class = '', $count = false) + public function eagerlyResultSet(&$resultSet, $relation, $class = '') { $relations = is_string($relation) ? explode(',', $relation) : $relation; foreach ($relations as $key => $relation) { @@ -1278,7 +1277,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess list($relation, $subRelation) = explode('.', $relation); } $relation = Loader::parseName($relation, 1, false); - $this->$relation()->eagerlyResultSet($resultSet, $relation, $subRelation, $closure, $class, $count); + $this->$relation()->eagerlyResultSet($resultSet, $relation, $subRelation, $closure, $class); } } @@ -1288,10 +1287,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @param Model $result 数据对象 * @param string $relation 关联名 * @param string $class 数据集对象名 为空表示数组 - * @param bool $count 是否统计 * @return Model */ - public function eagerlyResult(&$result, $relation, $class = '', $count = false) + public function eagerlyResult(&$result, $relation, $class = '') { $relations = is_string($relation) ? explode(',', $relation) : $relation; @@ -1306,7 +1304,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess list($relation, $subRelation) = explode('.', $relation); } $relation = Loader::parseName($relation, 1, false); - $this->$relation()->eagerlyResult($result, $relation, $subRelation, $closure, $class, $count); + $this->$relation()->eagerlyResult($result, $relation, $subRelation, $closure, $class); } } diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 79a30eb7..116b7070 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1620,11 +1620,10 @@ class Query /** * 设置关联查询JOIN预查询 * @access public - * @param string|array $with 关联方法名称 - * @param bool $count 是否统计 + * @param string|array $with 关联方法名称 * @return $this */ - public function with($with, $count = false) + public function with($with) { if (empty($with)) { return $this; @@ -1663,8 +1662,7 @@ class Query } } $this->via(); - $this->options['with'] = $with; - $this->options['count'] = $count; + $this->options['with'] = $with; return $this; } @@ -2019,7 +2017,7 @@ class Query } if (!empty($options['with'])) { // 预载入 - $result->eagerlyResultSet($resultSet, $options['with'], is_object($resultSet) ? get_class($resultSet) : '', !empty($options['count']) ? true : false); + $result->eagerlyResultSet($resultSet, $options['with'], is_object($resultSet) ? get_class($resultSet) : ''); } } // 模型数据集转换 @@ -2115,7 +2113,7 @@ class Query } // 预载入查询 if (!empty($options['with'])) { - $data->eagerlyResult($data, $options['with'], is_object($result) ? get_class($result) : '', !empty($options['count']) ? true : false); + $data->eagerlyResult($data, $options['with'], is_object($result) ? get_class($result) : ''); } // 关联统计 if (!empty($options['with_count'])) { diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index a83ac53b..cf831f1b 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -13,7 +13,6 @@ namespace think\model\relation; use think\Db; use think\db\Query; -use think\Loader; use think\Model; use think\model\Pivot; use think\model\Relation; @@ -81,10 +80,9 @@ class BelongsToMany extends Relation * @param string $subRelation 子关联名 * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 - * @param bool $count 是否统计 * @return void */ - public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class, $count) + public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class) { $localKey = $this->localKey; $foreignKey = $this->foreignKey; @@ -112,10 +110,7 @@ class BelongsToMany extends Relation if (!isset($data[$result->$pk])) { $data[$result->$pk] = []; } - if ($count) { - // 关联统计 - $result->setAttr(Loader::parseName($relation) . '_count', count($data[$result->$pk])); - } + $result->setAttr($relation, $this->resultSetBuild($data[$result->$pk], $class)); } } @@ -129,10 +124,9 @@ class BelongsToMany extends Relation * @param string $subRelation 子关联名 * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 - * @param bool $count 是否统计 * @return void */ - public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class, $count) + public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class) { $localKey = $this->localKey; $foreignKey = $this->foreignKey; @@ -147,10 +141,6 @@ class BelongsToMany extends Relation if (!isset($data[$pk])) { $data[$pk] = []; } - if ($count) { - // 关联统计 - $result->setAttr(Loader::parseName($relation) . '_count', count($data[$pk])); - } $result->setAttr($relation, $this->resultSetBuild($data[$pk], $class)); } } diff --git a/library/think/model/relation/HasMany.php b/library/think/model/relation/HasMany.php index ed5fb0be..08e1e81e 100644 --- a/library/think/model/relation/HasMany.php +++ b/library/think/model/relation/HasMany.php @@ -13,7 +13,6 @@ namespace think\model\relation; use think\Db; use think\db\Query; -use think\Loader; use think\Model; use think\model\Relation; @@ -55,10 +54,9 @@ class HasMany extends Relation * @param string $subRelation 子关联名 * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 - * @param bool $count 是否统计 * @return void */ - public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class, $count) + public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class) { $localKey = $this->localKey; $foreignKey = $this->foreignKey; @@ -85,10 +83,6 @@ class HasMany extends Relation if (!isset($data[$result->$localKey])) { $data[$result->$localKey] = []; } - if ($count) { - // 关联统计 - $result->setAttr(Loader::parseName($relation) . '_count', count($data[$result->$localKey])); - } $result->setAttr($relation, $this->resultSetBuild($data[$result->$localKey], $class)); } } @@ -102,10 +96,9 @@ class HasMany extends Relation * @param string $subRelation 子关联名 * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 - * @param bool $count 是否统计 * @return void */ - public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class, $count) + public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class) { $localKey = $this->localKey; $foreignKey = $this->foreignKey; @@ -116,10 +109,6 @@ class HasMany extends Relation if (!isset($data[$result->$localKey])) { $data[$result->$localKey] = []; } - if ($count) { - // 关联统计 - $result->setAttr(Loader::parseName($relation) . '_count', count($data[$result->$localKey])); - } $result->setAttr($relation, $this->resultSetBuild($data[$result->$localKey], $class)); } } diff --git a/library/think/model/relation/MorphMany.php b/library/think/model/relation/MorphMany.php index 9340bc42..b2e21013 100644 --- a/library/think/model/relation/MorphMany.php +++ b/library/think/model/relation/MorphMany.php @@ -13,7 +13,6 @@ namespace think\model\relation; use think\Db; use think\db\Query; -use think\Loader; use think\Model; use think\model\Relation; @@ -61,10 +60,9 @@ class MorphMany extends Relation * @param string $subRelation 子关联名 * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 - * @param bool $count 是否统计 * @return void */ - public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class, $count) + public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class) { $morphType = $this->morphType; $morphKey = $this->morphKey; @@ -91,10 +89,6 @@ class MorphMany extends Relation if (!isset($data[$result->$pk])) { $data[$result->$pk] = []; } - if ($count) { - // 关联统计 - $result->setAttr(Loader::parseName($relation) . '_count', count($data[$result->$pk])); - } $result->setAttr($relation, $this->resultSetBuild($data[$result->$pk], $class)); } } @@ -108,10 +102,9 @@ class MorphMany extends Relation * @param string $subRelation 子关联名 * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 - * @param bool $count 是否统计 * @return void */ - public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class, $count) + public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class) { $morphType = $this->morphType; $morphKey = $this->morphKey; @@ -119,10 +112,6 @@ class MorphMany extends Relation $pk = $result->getPk(); if (isset($result->$pk)) { $data = $this->eagerlyMorphToMany([$morphKey => $result->$pk, $morphType => $type], $relation, $subRelation, $closure); - if ($count) { - // 关联统计 - $result->setAttr(Loader::parseName($relation) . '_count', count($data[$result->$pk])); - } $result->setAttr($relation, $this->resultSetBuild($data[$result->$pk], $class)); } } -- Gitee From 91e089b7e7295732f94ac22857ca0b4ca99ea34c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 22 Dec 2016 13:52:41 +0800 Subject: [PATCH 0301/1170] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=85=B3=E8=81=94?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=20=E9=81=BF=E5=85=8D=E4=B8=80=E5=AF=B9?= =?UTF-8?q?=E4=B8=80=E5=85=B3=E8=81=94=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../think/model/relation/BelongsToMany.php | 21 ++++++---------- library/think/model/relation/HasMany.php | 24 ++++++++----------- .../think/model/relation/HasManyThrough.php | 16 +++++++++---- library/think/model/relation/MorphMany.php | 16 ++++--------- library/think/model/relation/MorphTo.php | 10 ++++++++ library/think/model/relation/OneToOne.php | 10 ++++++++ 6 files changed, 54 insertions(+), 43 deletions(-) diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index cf831f1b..93df01cf 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -128,14 +128,11 @@ class BelongsToMany extends Relation */ public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class) { - $localKey = $this->localKey; - $foreignKey = $this->foreignKey; - $pk = $result->getPk(); if (isset($result->$pk)) { $pk = $result->$pk; // 查询管理数据 - $data = $this->eagerlyManyToMany(['pivot.' . $localKey => $pk], $relation, $subRelation); + $data = $this->eagerlyManyToMany(['pivot.' . $this->localKey => $pk], $relation, $subRelation); // 关联数据封装 if (!isset($data[$pk])) { @@ -154,13 +151,11 @@ class BelongsToMany extends Relation */ public function relationCount($result, $closure) { - $localKey = $this->localKey; - $foreignKey = $this->foreignKey; - $pk = $result->getPk(); - $count = 0; + $pk = $result->getPk(); + $count = 0; if (isset($result->$pk)) { $pk = $result->$pk; - $count = $this->belongsToManyQuery($this->middle, $foreignKey, $localKey, ['pivot.' . $localKey => $pk])->count(); + $count = $this->belongsToManyQuery($this->middle, $this->foreignKey, $this->localKey, ['pivot.' . $this->localKey => $pk])->count(); } return $count; } @@ -175,10 +170,8 @@ class BelongsToMany extends Relation */ protected function eagerlyManyToMany($where, $relation, $subRelation = '') { - $foreignKey = $this->foreignKey; - $localKey = $this->localKey; // 预载入关联查询 支持嵌套预载入 - $list = $this->belongsToManyQuery($this->middle, $foreignKey, $localKey, $where)->with($subRelation)->select(); + $list = $this->belongsToManyQuery($this->middle, $this->foreignKey, $this->localKey, $where)->with($subRelation)->select(); // 组装模型数据 $data = []; @@ -193,8 +186,8 @@ class BelongsToMany extends Relation } } } - $set->pivot = new Pivot($pivot, $this->middle); - $data[$pivot[$localKey]][] = $set; + $set->pivot = new Pivot($pivot, $this->middle); + $data[$pivot[$this->localKey]][] = $set; } return $data; } diff --git a/library/think/model/relation/HasMany.php b/library/think/model/relation/HasMany.php index 08e1e81e..f6455d6b 100644 --- a/library/think/model/relation/HasMany.php +++ b/library/think/model/relation/HasMany.php @@ -58,10 +58,8 @@ class HasMany extends Relation */ public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class) { - $localKey = $this->localKey; - $foreignKey = $this->foreignKey; - - $range = []; + $localKey = $this->localKey; + $range = []; foreach ($resultSet as $result) { // 获取关联外键列表 if (isset($result->$localKey)) { @@ -70,9 +68,9 @@ class HasMany extends Relation } if (!empty($range)) { - $this->where[$foreignKey] = ['in', $range]; - $data = $this->eagerlyOneToMany($this, [ - $foreignKey => [ + $this->where[$this->foreignKey] = ['in', $range]; + $data = $this->eagerlyOneToMany($this, [ + $this->foreignKey => [ 'in', $range, ], @@ -100,11 +98,10 @@ class HasMany extends Relation */ public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class) { - $localKey = $this->localKey; - $foreignKey = $this->foreignKey; + $localKey = $this->localKey; if (isset($result->$localKey)) { - $data = $this->eagerlyOneToMany($this, [$foreignKey => $result->$localKey], $relation, $subRelation, $closure); + $data = $this->eagerlyOneToMany($this, [$this->foreignKey => $result->$localKey], $relation, $subRelation, $closure); // 关联数据封装 if (!isset($data[$result->$localKey])) { $data[$result->$localKey] = []; @@ -122,14 +119,13 @@ class HasMany extends Relation */ public function relationCount($result, $closure) { - $localKey = $this->localKey; - $foreignKey = $this->foreignKey; - $count = 0; + $localKey = $this->localKey; + $count = 0; if (isset($result->$localKey)) { if ($closure) { call_user_func_array($closure, [ & $this->query]); } - $count = $this->query->where([$foreignKey => $result->$localKey])->count(); + $count = $this->query->where([$this->foreignKey => $result->$localKey])->count(); } return $count; } diff --git a/library/think/model/relation/HasManyThrough.php b/library/think/model/relation/HasManyThrough.php index 56b90f4c..79a822f3 100644 --- a/library/think/model/relation/HasManyThrough.php +++ b/library/think/model/relation/HasManyThrough.php @@ -67,8 +67,7 @@ class HasManyThrough extends Relation * @return void */ public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class) - { - } + {} /** * 预载入关联查询 返回模型对象 @@ -81,8 +80,17 @@ class HasManyThrough extends Relation * @return void */ public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class) - { - } + {} + + /** + * 关联统计 + * @access public + * @param Model $result 数据对象 + * @param \Closure $closure 闭包 + * @return integer + */ + public function relationCount($result, $closure) + {} /** * 执行基础查询(进执行一次) diff --git a/library/think/model/relation/MorphMany.php b/library/think/model/relation/MorphMany.php index b2e21013..44c344cd 100644 --- a/library/think/model/relation/MorphMany.php +++ b/library/think/model/relation/MorphMany.php @@ -106,12 +106,9 @@ class MorphMany extends Relation */ public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class) { - $morphType = $this->morphType; - $morphKey = $this->morphKey; - $type = $this->type; - $pk = $result->getPk(); + $pk = $result->getPk(); if (isset($result->$pk)) { - $data = $this->eagerlyMorphToMany([$morphKey => $result->$pk, $morphType => $type], $relation, $subRelation, $closure); + $data = $this->eagerlyMorphToMany([$this->morphKey => $result->$pk, $this->morphType => $this->type], $relation, $subRelation, $closure); $result->setAttr($relation, $this->resultSetBuild($data[$result->$pk], $class)); } } @@ -125,16 +122,13 @@ class MorphMany extends Relation */ public function relationCount($result, $closure) { - $morphType = $this->morphType; - $morphKey = $this->morphKey; - $type = $this->type; - $pk = $result->getPk(); - $count = 0; + $pk = $result->getPk(); + $count = 0; if (isset($result->$pk)) { if ($closure) { call_user_func_array($closure, [ & $this->query]); } - $count = $this->query->where([$morphKey => $result->$pk, $morphType => $type])->count(); + $count = $this->query->where([$this->morphKey => $result->$pk, $this->morphType => $this->type])->count(); } return $count; } diff --git a/library/think/model/relation/MorphTo.php b/library/think/model/relation/MorphTo.php index 6de1d4f4..fa691489 100644 --- a/library/think/model/relation/MorphTo.php +++ b/library/think/model/relation/MorphTo.php @@ -136,6 +136,16 @@ class MorphTo extends Relation $this->eagerlyMorphToOne($model, $relation, $result, $subRelation); } + /** + * 关联统计 + * @access public + * @param Model $result 数据对象 + * @param \Closure $closure 闭包 + * @return integer + */ + public function relationCount($result, $closure) + {} + /** * 多态MorphTo 关联模型预查询 * @access public diff --git a/library/think/model/relation/OneToOne.php b/library/think/model/relation/OneToOne.php index 0165314f..a5a5de9d 100644 --- a/library/think/model/relation/OneToOne.php +++ b/library/think/model/relation/OneToOne.php @@ -179,6 +179,16 @@ abstract class OneToOne extends Relation return $this; } + /** + * 关联统计 + * @access public + * @param Model $result 数据对象 + * @param \Closure $closure 闭包 + * @return integer + */ + public function relationCount($result, $closure) + {} + /** * 一对一 关联模型预查询拼装 * @access public -- Gitee From 6eedbc5a0a6e35b77c0bcae854ead10abd9b7150 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 22 Dec 2016 17:37:52 +0800 Subject: [PATCH 0302/1170] =?UTF-8?q?Model=E7=B1=BB=E7=9A=84autoWriteTimes?= =?UTF-8?q?tamp=E5=B1=9E=E6=80=A7=E5=92=8C=E7=B1=BB=E5=9E=8B=E8=BD=AC?= =?UTF-8?q?=E5=8C=96=E7=B1=BB=E5=9E=8B=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E4=B8=BA=E7=B1=BB=E5=90=8D=20dateFormat=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=9C=A8=E6=95=B0=E6=8D=AE=E5=BA=93=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E4=B8=AD=E8=AE=BE=E7=BD=AEdatetime=5Fformat=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base.php | 2 +- library/think/Model.php | 20 ++++++++++++++- library/think/db/Connection.php | 44 +++++++++++++++++---------------- 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/base.php b/base.php index 01ee13c4..85ac946b 100644 --- a/base.php +++ b/base.php @@ -9,7 +9,7 @@ // | Author: liu21st // +---------------------------------------------------------------------- -define('THINK_VERSION', '5.0.4'); +define('THINK_VERSION', '5.0.5beta'); define('THINK_START_TIME', microtime(true)); define('THINK_START_MEM', memory_get_usage()); define('EXT', '.php'); diff --git a/library/think/Model.php b/library/think/Model.php index a1523914..4290cf68 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -96,7 +96,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess // 更新时间字段 protected $updateTime = 'update_time'; // 时间字段取出后的默认时间格式 - protected $dateFormat = 'Y-m-d H:i:s'; + protected $dateFormat; // 字段类型或者格式转换 protected $type = []; // 是否为更新数据 @@ -154,6 +154,11 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $this->autoWriteTimestamp = $this->db(false)->getConfig('auto_timestamp'); } + if (is_null($this->dateFormat)) { + // 设置时间戳格式 + $this->dateFormat = $this->db(false)->getConfig('datetime_format'); + } + // 执行初始化操作 $this->initialize(); } @@ -329,12 +334,21 @@ abstract class Model implements \JsonSerializable, \ArrayAccess case 'integer': default: $value = $_SERVER['REQUEST_TIME']; + if (strpos($type, '\\')) { + // 传入类名 + $value = new $type($value); + } break; } } elseif (is_string($this->autoWriteTimestamp) && in_array(strtolower($this->autoWriteTimestamp), ['datetime', 'date', 'timestamp'])) { $value = date($this->dateFormat, $_SERVER['REQUEST_TIME']); } else { $value = $_SERVER['REQUEST_TIME']; + if (is_string($this->autoWriteTimestamp) && strpos($this->autoWriteTimestamp, '\\')) { + // 传入类名 + $class = $this->autoWriteTimestamp; + $value = new $class($value); + } } return $value; } @@ -484,6 +498,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess case 'serialize': $value = unserialize($value); break; + default: + if (strpos($type, '\\')) { + $value = new $type($value); + } } return $value; } diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index f7d33161..f3138421 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -65,47 +65,49 @@ abstract class Connection // 数据库连接参数配置 protected $config = [ // 数据库类型 - 'type' => '', + 'type' => '', // 服务器地址 - 'hostname' => '', + 'hostname' => '', // 数据库名 - 'database' => '', + 'database' => '', // 用户名 - 'username' => '', + 'username' => '', // 密码 - 'password' => '', + 'password' => '', // 端口 - 'hostport' => '', + 'hostport' => '', // 连接dsn - 'dsn' => '', + 'dsn' => '', // 数据库连接参数 - 'params' => [], + 'params' => [], // 数据库编码默认采用utf8 - 'charset' => 'utf8', + 'charset' => 'utf8', // 数据库表前缀 - 'prefix' => '', + 'prefix' => '', // 数据库调试模式 - 'debug' => false, + 'debug' => false, // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) - 'deploy' => 0, + 'deploy' => 0, // 数据库读写是否分离 主从式有效 - 'rw_separate' => false, + 'rw_separate' => false, // 读写分离后 主服务器数量 - 'master_num' => 1, + 'master_num' => 1, // 指定从服务器序号 - 'slave_no' => '', + 'slave_no' => '', // 是否严格检查字段是否存在 - 'fields_strict' => true, + 'fields_strict' => true, // 数据集返回类型 - 'resultset_type' => 'array', + 'resultset_type' => 'array', // 自动写入时间戳字段 - 'auto_timestamp' => false, + 'auto_timestamp' => false, + // 时间戳格式 + 'datetime_format' => 'Y-m-d H:i:s', // 是否需要进行SQL性能分析 - 'sql_explain' => false, + 'sql_explain' => false, // Builder类 - 'builder' => '', + 'builder' => '', // Query类 - 'query' => '\\think\\db\\Query', + 'query' => '\\think\\db\\Query', ]; // PDO连接参数 -- Gitee From 3a78c93d11198c0e4de7ea06e9358165532309c9 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 22 Dec 2016 17:55:35 +0800 Subject: [PATCH 0303/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BRoute=E7=B1=BBsetRu?= =?UTF-8?q?le=E6=96=B9=E6=B3=95=20=E4=BF=AE=E6=AD=A3BelongsToMany=E7=B1=BB?= =?UTF-8?q?=E7=9A=84attach=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 6 ++++-- library/think/model/relation/BelongsToMany.php | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index 41da4652..735e6ef0 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -296,12 +296,14 @@ class Route } elseif ('$' == substr($rule, -1, 1)) { // 是否完整匹配 $option['complete_match'] = true; - $rule = substr($rule, 0, -1); } } elseif (empty($option['complete_match']) && '$' == substr($rule, -1, 1)) { // 是否完整匹配 $option['complete_match'] = true; - $rule = substr($rule, 0, -1); + } + + if (true == $option['complete_match'] && '$' == substr($rule, -1, 1)) { + $rule = substr($rule, 0, -1); } if ('/' != $rule || $group) { diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index 93df01cf..a07de2d7 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -13,6 +13,7 @@ namespace think\model\relation; use think\Db; use think\db\Query; +use think\Exception; use think\Model; use think\model\Pivot; use think\model\Relation; @@ -269,7 +270,7 @@ class BelongsToMany extends Relation $pk = $this->parent->getPk(); $pivot[$this->localKey] = $this->parent->$pk; $pivot[$this->foreignKey] = $id; - return $this->query->table($this->middle)->insert($pivot); + return $this->query->table($this->middle)->insert($pivot, true); } else { throw new Exception('miss relation data'); } -- Gitee From c2fff2b45d777a2cef2940b2989f1362f4206c81 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 22 Dec 2016 18:06:01 +0800 Subject: [PATCH 0304/1170] =?UTF-8?q?BelongsToMany=E7=B1=BB=E7=9A=84attach?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E6=94=B9=E8=BF=9B=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E5=86=99=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../think/model/relation/BelongsToMany.php | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index a07de2d7..53f344a6 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -252,10 +252,14 @@ class BelongsToMany extends Relation public function attach($data, $pivot = []) { if (is_array($data)) { - // 保存关联表数据 - $model = new $this->model; - $model->save($data); - $id = $model->getLastInsID(); + if (key($data) === 0) { + $id = $data; + } else { + // 保存关联表数据 + $model = new $this->model; + $model->save($data); + $id = $model->getLastInsID(); + } } elseif (is_numeric($data) || is_string($data)) { // 根据关联表主键直接写入中间表 $id = $data; @@ -267,10 +271,14 @@ class BelongsToMany extends Relation if ($id) { // 保存中间表数据 - $pk = $this->parent->getPk(); - $pivot[$this->localKey] = $this->parent->$pk; - $pivot[$this->foreignKey] = $id; - return $this->query->table($this->middle)->insert($pivot, true); + $pk = $this->parent->getPk(); + $pivot[$this->localKey] = $this->parent->$pk; + $ids = (array) $id; + foreach ($ids as $id) { + $pivot[$this->foreignKey] = $id; + $result = $this->query->table($this->middle)->insert($pivot, true); + } + return $result; } else { throw new Exception('miss relation data'); } -- Gitee From 340abd05e5cc8febbcbb362277b7498522b21242 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 22 Dec 2016 18:12:33 +0800 Subject: [PATCH 0305/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BBelongsToMany?= =?UTF-8?q?=E7=B1=BB=E7=9A=84saveall=E6=96=B9=E6=B3=95=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=AC=AC=E4=B8=89=E4=B8=AA=E5=8F=82=E6=95=B0=20?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E6=8C=87=E5=AE=9A=E9=A2=9D=E5=A4=96=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E6=98=AF=E5=90=A6=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/relation/BelongsToMany.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index 53f344a6..55daceba 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -231,13 +231,17 @@ class BelongsToMany extends Relation * @access public * @param array $dataSet 数据集 * @param array $pivot 中间表额外数据 + * @param bool $samePivot 额外数据是否相同 * @return integer */ - public function saveAll(array $dataSet, array $pivot = []) + public function saveAll(array $dataSet, array $pivot = [], $samePivot = false) { $result = false; foreach ($dataSet as $key => $data) { - $result = $this->attach($data, !empty($pivot) ? $pivot[$key] : []); + if (!$samePivot) { + $pivot = !empty($pivot) ? $pivot[$key] : []; + } + $result = $this->attach($data, $pivot); } return $result; } -- Gitee From 35d2c6552c043e47c44d8f981b201e401a508107 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 22 Dec 2016 18:17:09 +0800 Subject: [PATCH 0306/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Route=E7=B1=BB?= =?UTF-8?q?=E4=B8=80=E5=A4=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Route.php b/library/think/Route.php index 735e6ef0..6a6bac81 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -302,7 +302,7 @@ class Route $option['complete_match'] = true; } - if (true == $option['complete_match'] && '$' == substr($rule, -1, 1)) { + if ('$' == substr($rule, -1, 1)) { $rule = substr($rule, 0, -1); } -- Gitee From 6433f8fdca2931cd7232b857b4a7d91f61f19da3 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 22 Dec 2016 23:40:15 +0800 Subject: [PATCH 0307/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/relation/BelongsToMany.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index 55daceba..a832c5d5 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -239,7 +239,7 @@ class BelongsToMany extends Relation $result = false; foreach ($dataSet as $key => $data) { if (!$samePivot) { - $pivot = !empty($pivot) ? $pivot[$key] : []; + $pivot = isset($pivot[$key]) ? $pivot[$key] : []; } $result = $this->attach($data, $pivot); } -- Gitee From 4b6a39f6d3d95c36bd31ff56a125927f6c18f4b6 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 22 Dec 2016 23:57:47 +0800 Subject: [PATCH 0308/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/relation/BelongsToMany.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index a832c5d5..37d07eec 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -239,9 +239,11 @@ class BelongsToMany extends Relation $result = false; foreach ($dataSet as $key => $data) { if (!$samePivot) { - $pivot = isset($pivot[$key]) ? $pivot[$key] : []; + $pivotData = isset($pivot[$key]) ? $pivot[$key] : []; + } else { + $pivotData = $pivot; } - $result = $this->attach($data, $pivot); + $result = $this->attach($data, $pivotData); } return $result; } -- Gitee From a996640c7ebbcbdb526f78b4cde5aab8051cac6d Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 23 Dec 2016 10:23:54 +0800 Subject: [PATCH 0309/1170] =?UTF-8?q?=E5=86=99=E5=85=A5=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E4=B8=BA=E5=AF=B9=E8=B1=A1=E7=9A=84=E6=97=B6=E5=80=99=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E6=98=AF=E5=90=A6=E6=9C=89=5F=5FtoString=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Builder.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index 49b3aebe..9aa61cdc 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -118,6 +118,9 @@ abstract class Builder $this->query->bind($key, $val, isset($bind[$key]) ? $bind[$key] : PDO::PARAM_STR); $result[$item] = ':' . $key; } + } elseif (is_object($val) && method_exists($val, '__toString')) { + // 对象数据写入 + $result[$item] = $val->__toString(); } } return $result; -- Gitee From d07c5eff8317f022107d080994d3a29d33c7aef4 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 23 Dec 2016 10:56:37 +0800 Subject: [PATCH 0310/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BModel=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=88=B3=E5=AD=97=E6=AE=B5=E5=86=99=E5=85=A5?= =?UTF-8?q?=E5=92=8C=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 43 ++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 4290cf68..13ed8fc1 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -328,31 +328,44 @@ abstract class Model implements \JsonSerializable, \ArrayAccess case 'datetime': case 'date': $format = !empty($param) ? $param : $this->dateFormat; - $value = date($format, $_SERVER['REQUEST_TIME']); + $value = $this->formatDateTime($_SERVER['REQUEST_TIME'], $format); break; case 'timestamp': case 'integer': default: $value = $_SERVER['REQUEST_TIME']; - if (strpos($type, '\\')) { + if (false !== strpos($type, '\\')) { // 传入类名 $value = new $type($value); } break; } } elseif (is_string($this->autoWriteTimestamp) && in_array(strtolower($this->autoWriteTimestamp), ['datetime', 'date', 'timestamp'])) { - $value = date($this->dateFormat, $_SERVER['REQUEST_TIME']); + $value = $this->formatDateTime($_SERVER['REQUEST_TIME'], $this->dateFormat); } else { - $value = $_SERVER['REQUEST_TIME']; - if (is_string($this->autoWriteTimestamp) && strpos($this->autoWriteTimestamp, '\\')) { - // 传入类名 - $class = $this->autoWriteTimestamp; - $value = new $class($value); - } + $value = $this->formatDateTime($value, $this->dateFormat, true); } return $value; } + /** + * 时间日期字段格式化处理 + * @access public + * @param mixed $time 时间日期表达式 + * @param mixed $format 日期格式 + * @param bool $timestamp 是否进行时间戳转换 + * @return mixed + */ + protected function formatDateTime($time, $format, $timestamp = false) + { + if (false !== strpos($format, '\\')) { + $time = new $format($time); + } elseif (!$timestamp) { + $time = date($format, $time); + } + return $time; + } + /** * 数据写入 类型转换 * @access public @@ -388,7 +401,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess break; case 'datetime': $format = !empty($param) ? $param : $this->dateFormat; - $value = date($format, is_numeric($value) ? $value : strtotime($value)); + if (false === strpos($format, '\\')) { + $value = date($format, is_numeric($value) ? $value : strtotime($value)); + } break; case 'object': if (is_object($value)) { @@ -404,6 +419,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess case 'serialize': $value = serialize($value); break; + } return $value; } @@ -477,13 +493,13 @@ abstract class Model implements \JsonSerializable, \ArrayAccess case 'timestamp': if (!is_null($value)) { $format = !empty($param) ? $param : $this->dateFormat; - $value = date($format, $value); + $value = $this->formatDateTime($value, $format); } break; case 'datetime': if (!is_null($value)) { $format = !empty($param) ? $param : $this->dateFormat; - $value = date($format, strtotime($value)); + $value = $this->formatDateTime(strtotime($value), $format); } break; case 'json': @@ -499,7 +515,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $value = unserialize($value); break; default: - if (strpos($type, '\\')) { + if (false !== strpos($type, '\\')) { + // 对象类型 $value = new $type($value); } } -- Gitee From 0210d3a1fb8f8a76138f2acbb624692289173643 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 23 Dec 2016 11:17:34 +0800 Subject: [PATCH 0311/1170] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 13ed8fc1..f917adf2 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -334,10 +334,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess case 'integer': default: $value = $_SERVER['REQUEST_TIME']; - if (false !== strpos($type, '\\')) { - // 传入类名 - $value = new $type($value); - } break; } } elseif (is_string($this->autoWriteTimestamp) && in_array(strtolower($this->autoWriteTimestamp), ['datetime', 'date', 'timestamp'])) { -- Gitee From 44402ae1a3d0b393376e662cefea512c052b1650 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 23 Dec 2016 11:30:48 +0800 Subject: [PATCH 0312/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BModel=E7=B1=BBwrite?= =?UTF-8?q?Transform=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index f917adf2..fb2f5abf 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -397,9 +397,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess break; case 'datetime': $format = !empty($param) ? $param : $this->dateFormat; - if (false === strpos($format, '\\')) { - $value = date($format, is_numeric($value) ? $value : strtotime($value)); - } + $value = is_numeric($value) ? $value : strtotime($value); + $value = $this->formatDateTime($value, $format); break; case 'object': if (is_object($value)) { -- Gitee From c33cc2991b6280f1ad63a9d5eb5d80f8143cadd6 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 23 Dec 2016 11:37:34 +0800 Subject: [PATCH 0313/1170] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=88=B3=E8=87=AA=E5=8A=A8=E5=86=99=E5=85=A5=E7=9A=84=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 4 ++-- library/think/model/Merge.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index fb2f5abf..d8e76ce6 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -726,7 +726,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $this->autoCompleteData($this->auto); // 自动写入更新时间 - if ($this->autoWriteTimestamp && $this->updateTime) { + if ($this->autoWriteTimestamp && $this->updateTime && !isset($this->data[$this->updateTime])) { $this->setAttr($this->updateTime, null); } @@ -783,7 +783,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $this->autoCompleteData($this->insert); // 自动写入创建时间 - if ($this->autoWriteTimestamp && $this->createTime) { + if ($this->autoWriteTimestamp && $this->createTime && !isset($this->data[$this->createTime])) { $this->setAttr($this->createTime, null); } diff --git a/library/think/model/Merge.php b/library/think/model/Merge.php index 3cf5c3f6..5edb2a45 100644 --- a/library/think/model/Merge.php +++ b/library/think/model/Merge.php @@ -169,7 +169,7 @@ class Merge extends Model $this->autoCompleteData($this->auto); // 自动写入更新时间 - if ($this->autoWriteTimestamp && $this->updateTime) { + if ($this->autoWriteTimestamp && $this->updateTime && !isset($this->data[$this->updateTime])) { $this->setAttr($this->updateTime, null); } @@ -221,7 +221,7 @@ class Merge extends Model $this->autoCompleteData($this->insert); // 自动写入创建时间 - if ($this->autoWriteTimestamp && $this->createTime) { + if ($this->autoWriteTimestamp && $this->createTime && !isset($this->data[$this->createTime])) { $this->setAttr($this->createTime, null); } -- Gitee From 2c03514d98d55847e379957b1934a1449e90f30a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 23 Dec 2016 14:47:28 +0800 Subject: [PATCH 0314/1170] =?UTF-8?q?Query=E7=B1=BB=E7=9A=84order=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E6=94=AF=E6=8C=81=E5=A4=9A=E6=AC=A1=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 116b7070..e2f9ef7a 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1181,7 +1181,14 @@ class Query } } } - $this->options['order'] = $field; + if (!isset($this->options['order'])) { + $this->options['order'] = []; + } + if (is_array($field)) { + $this->options['order'] = array_merge($this->options['order'], $field); + } else { + $this->options['order'][] = $field; + } } return $this; } -- Gitee From c8712192bef8908c9d75f1d9c9d2ba35109f0746 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 23 Dec 2016 15:36:22 +0800 Subject: [PATCH 0315/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BRequest=E7=B1=BB?= =?UTF-8?q?=E7=9A=84domain=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/library/think/Request.php b/library/think/Request.php index 2e770a8d..49f39610 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -275,9 +275,6 @@ class Request return $this; } elseif (!$this->domain) { $this->domain = $this->scheme() . '://' . $this->host(); - if (!in_array($this->port(), ['80', '443'])) { - $this->domain .= ':' . $this->port(); - } } return $this->domain; } -- Gitee From d1637a9e51d0574655f4b3d3eefe7e3feea3ea47 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 24 Dec 2016 09:12:55 +0800 Subject: [PATCH 0316/1170] =?UTF-8?q?Route=E7=B1=BB=E7=9A=84rest=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E6=94=AF=E6=8C=81=E8=A6=86=E7=9B=96=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index 6a6bac81..a37f0e17 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -663,14 +663,14 @@ class Route /** * rest方法定义和修改 * @access public - * @param string $name 方法名称 - * @param array $resource 资源 + * @param string $name 方法名称 + * @param array|bool $resource 资源 * @return void */ public static function rest($name, $resource = []) { if (is_array($name)) { - self::$rest = array_merge(self::$rest, $name); + self::$rest = $resource ? $name : array_merge(self::$rest, $name); } else { self::$rest[$name] = $resource; } -- Gitee From 822359cfbce62f29e46b1bc3b1f7af1f9f6307b9 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 24 Dec 2016 09:22:05 +0800 Subject: [PATCH 0317/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9Bloader=E7=B1=BBacti?= =?UTF-8?q?on=E7=9A=84=E5=8F=82=E6=95=B0=E6=B1=A1=E6=9F=93=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 21 +++++++++++++-------- library/think/Loader.php | 5 +++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/library/think/App.php b/library/think/App.php index 01af92ce..5f7107b0 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -142,7 +142,7 @@ class App case 'controller': // 执行控制器操作 $vars = Request::instance()->param(); - $data = Loader::action($dispatch['controller'], array_merge($vars, $dispatch['var'])); + $data = Loader::action($dispatch['controller'], array_merge($vars, $dispatch['var']), $config['url_controller_layer'], $config['controller_suffix'], true); break; case 'method': // 执行回调方法 @@ -217,9 +217,10 @@ class App * @access public * @param string|array $method 方法 * @param array $vars 变量 + * @param bool $filter 是否全局过滤 * @return mixed */ - public static function invokeMethod($method, $vars = []) + public static function invokeMethod($method, $vars = [], $filter = true) { if (is_array($method)) { $class = is_object($method[0]) ? $method[0] : self::invokeClass($method[0]); @@ -228,7 +229,7 @@ class App // 静态方法 $reflect = new \ReflectionMethod($method); } - $args = self::bindParams($reflect, $vars); + $args = self::bindParams($reflect, $vars, $filter); self::$debug && Log::record('[ RUN ] ' . $reflect->class . '->' . $reflect->name . '[ ' . $reflect->getFileName() . ' ]', 'info'); return $reflect->invokeArgs(isset($class) ? $class : null, $args); @@ -239,14 +240,15 @@ class App * @access public * @param string $class 类名 * @param array $vars 变量 + * @param bool $filter 是否全局过滤 * @return mixed */ - public static function invokeClass($class, $vars = []) + public static function invokeClass($class, $vars = [], $filter = true) { $reflect = new \ReflectionClass($class); $constructor = $reflect->getConstructor(); if ($constructor) { - $args = self::bindParams($constructor, $vars); + $args = self::bindParams($constructor, $vars, $filter); } else { $args = []; } @@ -257,10 +259,11 @@ class App * 绑定参数 * @access public * @param \ReflectionMethod|\ReflectionFunction $reflect 反射类 - * @param array $vars 变量 + * @param array $vars 变量 + * @param bool $filter 是否全局过滤 * @return array */ - private static function bindParams($reflect, $vars = []) + private static function bindParams($reflect, $vars = [], $filter = true) { if (empty($vars)) { // 自动获取请求变量 @@ -305,7 +308,9 @@ class App } } // 全局过滤 - array_walk_recursive($args, [Request::instance(), 'filterExp']); + if ($filter) { + array_walk_recursive($args, [Request::instance(), 'filterExp']); + } } return $args; } diff --git a/library/think/Loader.php b/library/think/Loader.php index effd3f4a..951d5227 100644 --- a/library/think/Loader.php +++ b/library/think/Loader.php @@ -481,9 +481,10 @@ class Loader * @param string|array $vars 调用参数 支持字符串和数组 * @param string $layer 要调用的控制层名称 * @param bool $appendSuffix 是否添加类名后缀 + * @param bool $filter 是否全局过滤 * @return mixed */ - public static function action($url, $vars = [], $layer = 'controller', $appendSuffix = false) + public static function action($url, $vars = [], $layer = 'controller', $appendSuffix = false, $filter = false) { $info = pathinfo($url); $action = $info['basename']; @@ -497,7 +498,7 @@ class Loader $vars = [$vars]; } } - return App::invokeMethod([$class, $action . Config::get('action_suffix')], $vars); + return App::invokeMethod([$class, $action . Config::get('action_suffix')], $vars, $filter); } } -- Gitee From 5fe605705d06ff46133c0aadab75f3ffc8682487 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 24 Dec 2016 09:39:40 +0800 Subject: [PATCH 0318/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 25 +++++++++---------------- library/think/Loader.php | 5 ++--- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/library/think/App.php b/library/think/App.php index 5f7107b0..dc22cbe1 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -141,13 +141,13 @@ class App break; case 'controller': // 执行控制器操作 - $vars = Request::instance()->param(); - $data = Loader::action($dispatch['controller'], array_merge($vars, $dispatch['var']), $config['url_controller_layer'], $config['controller_suffix'], true); + $vars = array_merge(Request::instance()->param(), $dispatch['var']); + $data = Loader::action($dispatch['controller'], $vars, $config['url_controller_layer'], $config['controller_suffix']); break; case 'method': // 执行回调方法 - $vars = Request::instance()->param(); - $data = self::invokeMethod($dispatch['method'], array_merge($vars, $dispatch['var'])); + $vars = array_merge(Request::instance()->param(), $dispatch['var']); + $data = self::invokeMethod($dispatch['method'], $vars); break; case 'function': // 执行闭包 @@ -217,10 +217,9 @@ class App * @access public * @param string|array $method 方法 * @param array $vars 变量 - * @param bool $filter 是否全局过滤 * @return mixed */ - public static function invokeMethod($method, $vars = [], $filter = true) + public static function invokeMethod($method, $vars = []) { if (is_array($method)) { $class = is_object($method[0]) ? $method[0] : self::invokeClass($method[0]); @@ -229,7 +228,7 @@ class App // 静态方法 $reflect = new \ReflectionMethod($method); } - $args = self::bindParams($reflect, $vars, $filter); + $args = self::bindParams($reflect, $vars); self::$debug && Log::record('[ RUN ] ' . $reflect->class . '->' . $reflect->name . '[ ' . $reflect->getFileName() . ' ]', 'info'); return $reflect->invokeArgs(isset($class) ? $class : null, $args); @@ -240,15 +239,14 @@ class App * @access public * @param string $class 类名 * @param array $vars 变量 - * @param bool $filter 是否全局过滤 * @return mixed */ - public static function invokeClass($class, $vars = [], $filter = true) + public static function invokeClass($class, $vars = []) { $reflect = new \ReflectionClass($class); $constructor = $reflect->getConstructor(); if ($constructor) { - $args = self::bindParams($constructor, $vars, $filter); + $args = self::bindParams($constructor, $vars); } else { $args = []; } @@ -260,10 +258,9 @@ class App * @access public * @param \ReflectionMethod|\ReflectionFunction $reflect 反射类 * @param array $vars 变量 - * @param bool $filter 是否全局过滤 * @return array */ - private static function bindParams($reflect, $vars = [], $filter = true) + private static function bindParams($reflect, $vars = []) { if (empty($vars)) { // 自动获取请求变量 @@ -307,10 +304,6 @@ class App throw new \InvalidArgumentException('method param miss:' . $name); } } - // 全局过滤 - if ($filter) { - array_walk_recursive($args, [Request::instance(), 'filterExp']); - } } return $args; } diff --git a/library/think/Loader.php b/library/think/Loader.php index 951d5227..effd3f4a 100644 --- a/library/think/Loader.php +++ b/library/think/Loader.php @@ -481,10 +481,9 @@ class Loader * @param string|array $vars 调用参数 支持字符串和数组 * @param string $layer 要调用的控制层名称 * @param bool $appendSuffix 是否添加类名后缀 - * @param bool $filter 是否全局过滤 * @return mixed */ - public static function action($url, $vars = [], $layer = 'controller', $appendSuffix = false, $filter = false) + public static function action($url, $vars = [], $layer = 'controller', $appendSuffix = false) { $info = pathinfo($url); $action = $info['basename']; @@ -498,7 +497,7 @@ class Loader $vars = [$vars]; } } - return App::invokeMethod([$class, $action . Config::get('action_suffix')], $vars, $filter); + return App::invokeMethod([$class, $action . Config::get('action_suffix')], $vars); } } -- Gitee From 3c19637ac41fa508b6ce0ed14d1c9e9ef0e81185 Mon Sep 17 00:00:00 2001 From: 7IN0SAN9 Date: Sat, 24 Dec 2016 14:36:02 +0800 Subject: [PATCH 0319/1170] =?UTF-8?q?=E7=AE=80=E5=8C=96CI=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 2 -- composer.json | 6 ++---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 96a9dffc..f74ffca1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,8 +36,6 @@ install: script: ## LINT - find . -path ./vendor -prune -o -type f -name \*.php -exec php -l {} \; - ## PHP_CodeSniffer - - vendor/bin/phpcs --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 --standard=PSR2 --ignore="vendor/*" ./ ## PHP Copy/Paste Detector - vendor/bin/phpcpd --verbose --exclude vendor ./ || true ## PHPLOC diff --git a/composer.json b/composer.json index 9552f0de..98f9e405 100644 --- a/composer.json +++ b/composer.json @@ -24,13 +24,11 @@ "johnkary/phpunit-speedtrap": "^1.0", "mikey179/vfsStream": "~1.6", "phploc/phploc": "2.*", - "sebastian/phpcpd": "2.*", - "squizlabs/php_codesniffer": "2.*", - "phpdocumentor/reflection-docblock": "^2.0" + "sebastian/phpcpd": "2.*" }, "autoload": { "psr-4": { "think\\": "library/think" } - } + } } -- Gitee From 43eacbb0c671e755429d255ce4784f85b6ca2366 Mon Sep 17 00:00:00 2001 From: 7IN0SAN9 Date: Sat, 24 Dec 2016 14:38:50 +0800 Subject: [PATCH 0320/1170] =?UTF-8?q?=E4=BE=9D=E8=B5=96=20reflection-docbl?= =?UTF-8?q?ock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 98f9e405..c546e114 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ "johnkary/phpunit-speedtrap": "^1.0", "mikey179/vfsStream": "~1.6", "phploc/phploc": "2.*", - "sebastian/phpcpd": "2.*" + "sebastian/phpcpd": "2.*", + "phpdocumentor/reflection-docblock": "^2.0" }, "autoload": { "psr-4": { -- Gitee From 7625aa9321a654ec2def6dc06ab9272999910e84 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 24 Dec 2016 20:23:15 +0800 Subject: [PATCH 0321/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Url=E7=B1=BBbuild?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=AE=9A=E4=B9=89=E8=B7=AF=E7=94=B1=E5=88=AB?= =?UTF-8?q?=E5=90=8D=E5=90=8E=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Url.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/library/think/Url.php b/library/think/Url.php index d8730743..9ea900d8 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -89,7 +89,8 @@ class Url throw new \InvalidArgumentException('route name not exists:' . $name); } else { // 检查别名路由 - $alias = Route::rules('alias'); + $alias = Route::rules('alias'); + $matchAlias = false; if ($alias) { // 别名路由解析 foreach ($alias as $key => $val) { @@ -97,11 +98,13 @@ class Url $val = $val[0]; } if (0 === strpos($url, $val)) { - $url = $key . substr($url, strlen($val)); + $url = $key . substr($url, strlen($val)); + $matchAlias = true; break; } } - } else { + } + if (!$matchAlias) { // 路由标识不存在 直接解析 $url = self::parseUrl($url, $domain); } -- Gitee From 43b364e2867132cd8735cd261153bbbdc9946f12 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 24 Dec 2016 21:37:05 +0800 Subject: [PATCH 0322/1170] =?UTF-8?q?=E8=A7=84=E8=8C=83=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 10 -- library/think/Cache.php | 2 - library/think/Collection.php | 6 +- library/think/Console.php | 2 +- library/think/Controller.php | 1 - library/think/Cookie.php | 2 +- library/think/Db.php | 2 - library/think/Debug.php | 6 +- library/think/Hook.php | 5 - library/think/Lang.php | 4 - library/think/Model.php | 6 - library/think/Paginator.php | 14 +-- library/think/Process.php | 112 +++++++++--------- library/think/Request.php | 7 +- library/think/Response.php | 5 - library/think/Route.php | 7 -- library/think/Session.php | 1 - library/think/Template.php | 5 +- library/think/Url.php | 5 - library/think/Validate.php | 6 - library/think/View.php | 3 - library/think/cache/Driver.php | 2 +- library/think/cache/driver/Memcache.php | 1 - library/think/cache/driver/Sqlite.php | 1 - library/think/cache/driver/Wincache.php | 3 +- library/think/cache/driver/Xcache.php | 1 - library/think/console/Input.php | 2 +- library/think/console/command/Help.php | 3 +- .../think/console/command/optimize/Schema.php | 2 +- .../think/console/output/driver/Console.php | 14 +-- library/think/db/Builder.php | 3 - library/think/db/Connection.php | 1 - library/think/db/Query.php | 2 - library/think/exception/PDOException.php | 2 - .../exception/RouteNotFoundException.php | 2 - library/think/log/driver/Socket.php | 6 +- library/think/model/relation/BelongsTo.php | 1 - library/think/model/relation/HasOne.php | 1 - library/think/model/relation/OneToOne.php | 1 - library/think/process/Builder.php | 7 +- library/think/process/Utils.php | 4 +- .../exception/{Faild.php => Failed.php} | 1 - library/think/process/pipes/Unix.php | 20 ++-- library/think/process/pipes/Windows.php | 8 +- library/traits/think/Instance.php | 2 +- 45 files changed, 106 insertions(+), 195 deletions(-) rename library/think/process/exception/{Faild.php => Failed.php} (99%) diff --git a/library/think/App.php b/library/think/App.php index dc22cbe1..a7e1ddfa 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -11,19 +11,9 @@ namespace think; -use think\Config; -use think\Env; -use think\Exception; use think\exception\HttpException; use think\exception\HttpResponseException; use think\exception\RouteNotFoundException; -use think\Hook; -use think\Lang; -use think\Loader; -use think\Log; -use think\Request; -use think\Response; -use think\Route; /** * App 应用管理 diff --git a/library/think/Cache.php b/library/think/Cache.php index 208190be..372da705 100644 --- a/library/think/Cache.php +++ b/library/think/Cache.php @@ -11,8 +11,6 @@ namespace think; -use think\App; - class Cache { protected static $instance = []; diff --git a/library/think/Collection.php b/library/think/Collection.php index 8315268a..cf2888d5 100644 --- a/library/think/Collection.php +++ b/library/think/Collection.php @@ -225,11 +225,11 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria $result = []; foreach ($this->items as $row) { - $key = $value = null; + $key = $value = null; $keySet = $valueSet = false; if (null !== $index_key && array_key_exists($index_key, $row)) { $keySet = true; - $key = (string)$row[$index_key]; + $key = (string) $row[$index_key]; } if (null === $column_key) { $valueSet = true; @@ -368,6 +368,6 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria if ($items instanceof self) { return $items->all(); } - return (array)$items; + return (array) $items; } } diff --git a/library/think/Console.php b/library/think/Console.php index ab8e0211..233489b5 100644 --- a/library/think/Console.php +++ b/library/think/Console.php @@ -317,7 +317,7 @@ class Console if (!$command->isEnabled()) { $command->setConsole(null); - return null; + return; } if (null === $command->getDefinition()) { diff --git a/library/think/Controller.php b/library/think/Controller.php index fe4efae2..e9d6829b 100644 --- a/library/think/Controller.php +++ b/library/think/Controller.php @@ -13,7 +13,6 @@ namespace think; \think\Loader::import('controller/Jump', TRAIT_PATH, EXT); -use think\Exception; use think\exception\ValidateException; class Controller diff --git a/library/think/Cookie.php b/library/think/Cookie.php index 12b5cc31..f1c2426a 100644 --- a/library/think/Cookie.php +++ b/library/think/Cookie.php @@ -149,7 +149,7 @@ class Cookie } return $value; } else { - return null; + return; } } diff --git a/library/think/Db.php b/library/think/Db.php index c67cba6f..4998469f 100644 --- a/library/think/Db.php +++ b/library/think/Db.php @@ -11,8 +11,6 @@ namespace think; -use think\App; -use think\Collection; use think\db\Query; use think\paginator\Collection as PaginatorCollection; diff --git a/library/think/Debug.php b/library/think/Debug.php index e36a764e..24acd3d3 100644 --- a/library/think/Debug.php +++ b/library/think/Debug.php @@ -11,11 +11,7 @@ namespace think; -use think\Config; use think\exception\ClassNotFoundException; -use think\Log; -use think\Request; -use think\Response; use think\response\Redirect; class Debug @@ -179,7 +175,7 @@ class Debug } if ($echo) { echo ($output); - return null; + return; } else { return $output; } diff --git a/library/think/Hook.php b/library/think/Hook.php index 4d69ca54..4559cd30 100644 --- a/library/think/Hook.php +++ b/library/think/Hook.php @@ -11,11 +11,6 @@ namespace think; -use think\App; -use think\Debug; -use think\Loader; -use think\Log; - class Hook { diff --git a/library/think/Lang.php b/library/think/Lang.php index e064ae45..551481f1 100644 --- a/library/think/Lang.php +++ b/library/think/Lang.php @@ -11,10 +11,6 @@ namespace think; -use think\App; -use think\Cookie; -use think\Log; - class Lang { // 语言数据 diff --git a/library/think/Model.php b/library/think/Model.php index d8e76ce6..71fbfc69 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -12,14 +12,8 @@ namespace think; use InvalidArgumentException; -use think\Cache; -use think\Collection; -use think\Config; -use think\Db; use think\db\Query; -use think\Exception; use think\Exception\ValidateException; -use think\Loader; use think\model\Relation; use think\model\relation\BelongsTo; use think\model\relation\BelongsToMany; diff --git a/library/think/Paginator.php b/library/think/Paginator.php index 7385ebb0..dc4cdeeb 100644 --- a/library/think/Paginator.php +++ b/library/think/Paginator.php @@ -12,7 +12,6 @@ namespace think; use think\paginator\Collection as PaginatorCollection; -use think\Request; abstract class Paginator { @@ -42,14 +41,14 @@ abstract class Paginator 'var_page' => 'page', 'path' => '/', 'query' => [], - 'fragment' => '' + 'fragment' => '', ]; protected function __construct($items, $listRows, $currentPage = null, $total = null, $simple = false, $options = []) { $this->options = array_merge($this->options, $options); - $this->options['path'] = $this->options['path'] != '/' ? rtrim($this->options['path'], '/') : $this->options['path']; + $this->options['path'] = '/' != $this->options['path'] ? rtrim($this->options['path'], '/') : $this->options['path']; $this->simple = $simple; $this->listRows = $listRows; @@ -63,7 +62,7 @@ abstract class Paginator $items = $items->slice(0, $this->listRows); } else { $this->total = $total; - $this->lastPage = (int)ceil($total / $listRows); + $this->lastPage = (int) ceil($total / $listRows); $this->currentPage = $this->setCurrentPage($currentPage); $this->hasMore = $this->currentPage < $this->lastPage; } @@ -134,7 +133,7 @@ abstract class Paginator { $page = Request::instance()->request($varPage); - if (filter_var($page, FILTER_VALIDATE_INT) !== false && (int)$page >= 1) { + if (filter_var($page, FILTER_VALIDATE_INT) !== false && (int) $page >= 1) { return $page; } @@ -182,7 +181,7 @@ abstract class Paginator */ public function hasPages() { - return !($this->currentPage == 1 && !$this->hasMore); + return !(1 == $this->currentPage && !$this->hasMore); } /** @@ -239,7 +238,6 @@ abstract class Paginator return $this; } - /** * 构造锚点字符串 * @@ -255,4 +253,4 @@ abstract class Paginator * @return mixed */ abstract public function render(); -} \ No newline at end of file +} diff --git a/library/think/Process.php b/library/think/Process.php index 1982de24..6f3faa31 100644 --- a/library/think/Process.php +++ b/library/think/Process.php @@ -14,9 +14,9 @@ namespace think; use think\process\exception\Failed as ProcessFailedException; use think\process\exception\Timeout as ProcessTimeoutException; use think\process\pipes\Pipes; -use think\process\Utils; use think\process\pipes\Unix as UnixPipes; use think\process\pipes\Windows as WindowsPipes; +use think\process\Utils; class Process { @@ -47,10 +47,10 @@ class Process private $exitcode; private $fallbackExitcode; private $processInformation; - private $outputDisabled = false; + private $outputDisabled = false; private $stdout; private $stderr; - private $enhanceWindowsCompatibility = true; + private $enhanceWindowsCompatibility = true; private $enhanceSigchildCompatibility; private $process; private $status = self::STATUS_READY; @@ -147,7 +147,7 @@ class Process $this->enhanceSigchildCompatibility = '\\' !== DS && $this->isSigchildEnabled(); $this->options = array_replace([ 'suppress_errors' => true, - 'binary_pipes' => true + 'binary_pipes' => true, ], $options); } @@ -490,7 +490,7 @@ class Process public function getExitCodeText() { if (null === $exitcode = $this->getExitCode()) { - return null; + return; } return isset(self::$exitCodes[$exitcode]) ? self::$exitCodes[$exitcode] : 'Unknown error'; @@ -586,7 +586,7 @@ class Process */ public function isStarted() { - return $this->status != self::STATUS_READY; + return self::STATUS_READY != $this->status; } /** @@ -597,7 +597,7 @@ class Process { $this->updateStatus(false); - return $this->status == self::STATUS_TERMINATED; + return self::STATUS_TERMINATED == $this->status; } /** @@ -645,7 +645,7 @@ class Process * @param string $line */ public function addOutput($line) - { +{ $this->lastOutputTime = microtime(true); $this->stdout .= $line; } @@ -655,7 +655,7 @@ class Process * @param string $line */ public function addErrorOutput($line) - { +{ $this->lastOutputTime = microtime(true); $this->stderr .= $line; } @@ -665,7 +665,7 @@ class Process * @return string */ public function getCommandLine() - { +{ return $this->commandline; } @@ -675,7 +675,7 @@ class Process * @return self */ public function setCommandLine($commandline) - { +{ $this->commandline = $commandline; return $this; @@ -686,7 +686,7 @@ class Process * @return float|null */ public function getTimeout() - { +{ return $this->timeout; } @@ -695,7 +695,7 @@ class Process * @return float|null */ public function getIdleTimeout() - { +{ return $this->idleTimeout; } @@ -705,7 +705,7 @@ class Process * @return self */ public function setTimeout($timeout) - { +{ $this->timeout = $this->validateTimeout($timeout); return $this; @@ -717,7 +717,7 @@ class Process * @return self */ public function setIdleTimeout($timeout) - { +{ if (null !== $timeout && $this->outputDisabled) { throw new \LogicException('Idle timeout can not be set while the output is disabled.'); } @@ -733,7 +733,7 @@ class Process * @return self */ public function setTty($tty) - { +{ if ('\\' === DS && $tty) { throw new \RuntimeException('TTY mode is not supported on Windows platform.'); } @@ -741,7 +741,7 @@ class Process throw new \RuntimeException('TTY mode requires /dev/tty to be readable.'); } - $this->tty = (bool)$tty; + $this->tty = (bool) $tty; return $this; } @@ -751,7 +751,7 @@ class Process * @return bool */ public function isTty() - { +{ return $this->tty; } @@ -761,8 +761,8 @@ class Process * @return self */ public function setPty($bool) - { - $this->pty = (bool)$bool; +{ + $this->pty = (bool) $bool; return $this; } @@ -772,7 +772,7 @@ class Process * @return bool */ public function isPty() - { +{ return $this->pty; } @@ -781,7 +781,7 @@ class Process * @return string|null */ public function getWorkingDirectory() - { +{ if (null === $this->cwd) { return getcwd() ?: null; } @@ -795,7 +795,7 @@ class Process * @return self */ public function setWorkingDirectory($cwd) - { +{ $this->cwd = $cwd; return $this; @@ -806,7 +806,7 @@ class Process * @return array */ public function getEnv() - { +{ return $this->env; } @@ -816,14 +816,14 @@ class Process * @return self */ public function setEnv(array $env) - { +{ $env = array_filter($env, function ($value) { return !is_array($value); }); $this->env = []; foreach ($env as $key => $value) { - $this->env[(binary)$key] = (binary)$value; + $this->env[(binary) $key] = (binary) $value; } return $this; @@ -834,7 +834,7 @@ class Process * @return null|string */ public function getInput() - { +{ return $this->input; } @@ -844,7 +844,7 @@ class Process * @return self */ public function setInput($input) - { +{ if ($this->isRunning()) { throw new \LogicException('Input can not be set while the process is running.'); } @@ -859,7 +859,7 @@ class Process * @return array */ public function getOptions() - { +{ return $this->options; } @@ -869,7 +869,7 @@ class Process * @return self */ public function setOptions(array $options) - { +{ $this->options = $options; return $this; @@ -880,7 +880,7 @@ class Process * @return bool */ public function getEnhanceWindowsCompatibility() - { +{ return $this->enhanceWindowsCompatibility; } @@ -890,8 +890,8 @@ class Process * @return self */ public function setEnhanceWindowsCompatibility($enhance) - { - $this->enhanceWindowsCompatibility = (bool)$enhance; +{ + $this->enhanceWindowsCompatibility = (bool) $enhance; return $this; } @@ -901,7 +901,7 @@ class Process * @return bool */ public function getEnhanceSigchildCompatibility() - { +{ return $this->enhanceSigchildCompatibility; } @@ -911,8 +911,8 @@ class Process * @return self */ public function setEnhanceSigchildCompatibility($enhance) - { - $this->enhanceSigchildCompatibility = (bool)$enhance; +{ + $this->enhanceSigchildCompatibility = (bool) $enhance; return $this; } @@ -921,8 +921,8 @@ class Process * 是否超时 */ public function checkTimeout() - { - if ($this->status !== self::STATUS_STARTED) { +{ + if (self::STATUS_STARTED !== $this->status) { return; } @@ -944,7 +944,7 @@ class Process * @return bool */ public static function isPtySupported() - { +{ static $result; if (null !== $result) { @@ -970,7 +970,7 @@ class Process * @return array */ private function getDescriptors() - { +{ if ('\\' === DS) { $this->processPipes = WindowsPipes::create($this, $this->input); } else { @@ -994,7 +994,7 @@ class Process * @return callable */ protected function buildCallback($callback) - { +{ $out = self::OUT; $callback = function ($type, $data) use ($callback, $out) { if ($out == $type) { @@ -1016,7 +1016,7 @@ class Process * @param bool $blocking */ protected function updateStatus($blocking) - { +{ if (self::STATUS_STARTED !== $this->status) { return; } @@ -1036,7 +1036,7 @@ class Process * @return bool */ protected function isSigchildEnabled() - { +{ if (null !== self::$sigchild) { return self::$sigchild; } @@ -1057,8 +1057,8 @@ class Process * @return float|null */ private function validateTimeout($timeout) - { - $timeout = (float)$timeout; +{ + $timeout = (float) $timeout; if (0.0 === $timeout) { $timeout = null; @@ -1075,15 +1075,15 @@ class Process * @param bool $close */ private function readPipes($blocking, $close) - { +{ $result = $this->processPipes->readAndWrite($blocking, $close); $callback = $this->callback; foreach ($result as $type => $data) { if (3 == $type) { - $this->fallbackExitcode = (int)$data; + $this->fallbackExitcode = (int) $data; } else { - $callback($type === self::STDOUT ? self::OUT : self::ERR, $data); + $callback(self::STDOUT === $type ? self::OUT : self::ERR, $data); } } } @@ -1092,7 +1092,7 @@ class Process * 捕获退出码 */ private function captureExitCode() - { +{ if (isset($this->processInformation['exitcode']) && -1 != $this->processInformation['exitcode']) { $this->exitcode = $this->processInformation['exitcode']; } @@ -1103,7 +1103,7 @@ class Process * @return int 退出码 */ private function close() - { +{ $this->processPipes->close(); if (is_resource($this->process)) { $exitcode = proc_close($this->process); @@ -1117,7 +1117,7 @@ class Process if (-1 === $this->exitcode && null !== $this->fallbackExitcode) { $this->exitcode = $this->fallbackExitcode; } elseif (-1 === $this->exitcode && $this->processInformation['signaled'] - && 0 < $this->processInformation['termsig'] + && 0 < $this->processInformation['termsig'] ) { $this->exitcode = 128 + $this->processInformation['termsig']; } @@ -1129,7 +1129,7 @@ class Process * 重置数据 */ private function resetProcessData() - { +{ $this->starttime = null; $this->callback = null; $this->exitcode = null; @@ -1151,7 +1151,7 @@ class Process * @return bool */ private function doSignal($signal, $throwException) - { +{ if (!$this->isRunning()) { if ($throwException) { throw new \LogicException('Can not send signal on a non running process.'); @@ -1186,7 +1186,7 @@ class Process * @param string $functionName */ private function requireProcessIsStarted($functionName) - { +{ if (!$this->isStarted()) { throw new \LogicException(sprintf('Process must be started before calling %s.', $functionName)); } @@ -1197,9 +1197,9 @@ class Process * @param string $functionName */ private function requireProcessIsTerminated($functionName) - { +{ if (!$this->isTerminated()) { throw new \LogicException(sprintf('Process must be terminated before calling %s.', $functionName)); } } -} \ No newline at end of file +} diff --git a/library/think/Request.php b/library/think/Request.php index 49f39610..a806dd87 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -11,11 +11,6 @@ namespace think; -use think\Config; -use think\Exception; -use think\File; -use think\Session; - class Request { /** @@ -891,7 +886,7 @@ class Request return $array[$name]; } } - return null; + return; } /** diff --git a/library/think/Response.php b/library/think/Response.php index a7ebecf7..8b107589 100644 --- a/library/think/Response.php +++ b/library/think/Response.php @@ -11,11 +11,6 @@ namespace think; -use think\Cache; -use think\Config; -use think\Debug; -use think\Env; -use think\Request; use think\response\Json as JsonResponse; use think\response\Jsonp as JsonpResponse; use think\response\Redirect as RedirectResponse; diff --git a/library/think/Route.php b/library/think/Route.php index a37f0e17..7a31659a 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -11,14 +11,7 @@ namespace think; -use think\App; -use think\Config; use think\exception\HttpException; -use think\Hook; -use think\Loader; -use think\Log; -use think\Request; -use think\Response; class Route { diff --git a/library/think/Session.php b/library/think/Session.php index 9bafe116..6870e164 100644 --- a/library/think/Session.php +++ b/library/think/Session.php @@ -11,7 +11,6 @@ namespace think; -use think\App; use think\exception\ClassNotFoundException; class Session diff --git a/library/think/Template.php b/library/think/Template.php index 667eac74..072cc80c 100644 --- a/library/think/Template.php +++ b/library/think/Template.php @@ -12,7 +12,6 @@ namespace think; use think\exception\TemplateNotFoundException; -use think\Request; /** * ThinkPHP分离出来的模板引擎 @@ -130,7 +129,7 @@ class Template } elseif (isset($this->config[$config])) { return $this->config[$config]; } else { - return null; + return; } } @@ -669,7 +668,7 @@ class Template $content = str_replace($matches[0], '', $content); return explode(',', $matches['name']); } - return null; + return; } /** diff --git a/library/think/Url.php b/library/think/Url.php index 9ea900d8..75fffac6 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -11,11 +11,6 @@ namespace think; -use think\Config; -use think\Loader; -use think\Request; -use think\Route; - class Url { // 生成URL地址的root diff --git a/library/think/Validate.php b/library/think/Validate.php index 1fe27d1f..528861b4 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -11,13 +11,7 @@ namespace think; -use think\Db; use think\exception\ClassNotFoundException; -use think\File; -use think\Lang; -use think\Loader; -use think\Request; -use think\Session; class Validate { diff --git a/library/think/View.php b/library/think/View.php index b724ba91..1be47f4e 100644 --- a/library/think/View.php +++ b/library/think/View.php @@ -11,9 +11,6 @@ namespace think; -use think\Loader; -use think\Request; - class View { // 视图实例 diff --git a/library/think/cache/Driver.php b/library/think/cache/Driver.php index a2a57795..f21da7bf 100644 --- a/library/think/cache/Driver.php +++ b/library/think/cache/Driver.php @@ -105,7 +105,7 @@ abstract class Driver $this->rm($name); return $result; } else { - return null; + return; } } diff --git a/library/think/cache/driver/Memcache.php b/library/think/cache/driver/Memcache.php index bddf7157..ca2f8aa8 100644 --- a/library/think/cache/driver/Memcache.php +++ b/library/think/cache/driver/Memcache.php @@ -12,7 +12,6 @@ namespace think\cache\driver; use think\cache\Driver; -use think\Exception; class Memcache extends Driver { diff --git a/library/think/cache/driver/Sqlite.php b/library/think/cache/driver/Sqlite.php index 6dbd41fe..907f93df 100644 --- a/library/think/cache/driver/Sqlite.php +++ b/library/think/cache/driver/Sqlite.php @@ -12,7 +12,6 @@ namespace think\cache\driver; use think\cache\Driver; -use think\Exception; /** * Sqlite缓存驱动 diff --git a/library/think/cache/driver/Wincache.php b/library/think/cache/driver/Wincache.php index a9cc7d22..11d059e4 100644 --- a/library/think/cache/driver/Wincache.php +++ b/library/think/cache/driver/Wincache.php @@ -12,7 +12,6 @@ namespace think\cache\driver; use think\cache\Driver; -use think\Exception; /** * Wincache缓存驱动 @@ -28,7 +27,7 @@ class Wincache extends Driver /** * 架构函数 * @param array $options 缓存参数 - * @throws Exception + * @throws \BadFunctionCallException * @access public */ public function __construct($options = []) diff --git a/library/think/cache/driver/Xcache.php b/library/think/cache/driver/Xcache.php index 6b18b3fc..e790ef7c 100644 --- a/library/think/cache/driver/Xcache.php +++ b/library/think/cache/driver/Xcache.php @@ -12,7 +12,6 @@ namespace think\cache\driver; use think\cache\Driver; -use think\Exception; /** * Xcache缓存驱动 diff --git a/library/think/console/Input.php b/library/think/console/Input.php index 269196eb..2482dfdc 100644 --- a/library/think/console/Input.php +++ b/library/think/console/Input.php @@ -252,7 +252,7 @@ class Input return $token; } - return null; + return; } /** diff --git a/library/think/console/command/Help.php b/library/think/console/command/Help.php index eb0858a3..bae2c653 100644 --- a/library/think/console/command/Help.php +++ b/library/think/console/command/Help.php @@ -16,7 +16,6 @@ use think\console\Input; use think\console\input\Argument as InputArgument; use think\console\input\Option as InputOption; use think\console\Output; -use think\console\helper\Descriptor as DescriptorHelper; class Help extends Command { @@ -67,4 +66,4 @@ EOF $this->command = null; } -} \ No newline at end of file +} diff --git a/library/think/console/command/optimize/Schema.php b/library/think/console/command/optimize/Schema.php index a1f40cd9..6ac38a36 100644 --- a/library/think/console/command/optimize/Schema.php +++ b/library/think/console/command/optimize/Schema.php @@ -50,7 +50,7 @@ class Schema extends Command } $output->writeln('Succeed!'); return; - } else if ($input->hasOption('table')) { + } elseif ($input->hasOption('table')) { $table = $input->getOption('table'); if (!strpos($table, '.')) { $dbName = Db::getConfig('database'); diff --git a/library/think/console/output/driver/Console.php b/library/think/console/output/driver/Console.php index af4341b7..a6e89218 100644 --- a/library/think/console/output/driver/Console.php +++ b/library/think/console/output/driver/Console.php @@ -196,7 +196,7 @@ class Console private function getSttyColumns() { if (!function_exists('proc_open')) { - return null; + return; } $descriptorspec = [1 => ['pipe', 'w'], 2 => ['pipe', 'w']]; @@ -209,7 +209,7 @@ class Console return $info; } - return null; + return; } /** @@ -234,7 +234,7 @@ class Console return $matches[2] . 'x' . $matches[1]; } } - return null; + return; } private function stringWidth($string) @@ -356,10 +356,10 @@ class Console { if (DIRECTORY_SEPARATOR === '\\') { return - '10.0.10586' === PHP_WINDOWS_VERSION_MAJOR . '.' . PHP_WINDOWS_VERSION_MINOR . '.' . PHP_WINDOWS_VERSION_BUILD - || false !== getenv('ANSICON') - || 'ON' === getenv('ConEmuANSI') - || 'xterm' === getenv('TERM'); + '10.0.10586' === PHP_WINDOWS_VERSION_MAJOR . '.' . PHP_WINDOWS_VERSION_MINOR . '.' . PHP_WINDOWS_VERSION_BUILD + || false !== getenv('ANSICON') + || 'ON' === getenv('ConEmuANSI') + || 'xterm' === getenv('TERM'); } return function_exists('posix_isatty') && @posix_isatty($stream); diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index 9aa61cdc..fb315057 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -12,9 +12,6 @@ namespace think\db; use PDO; -use think\Db; -use think\db\Connection; -use think\db\Query; use think\Exception; abstract class Builder diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index f3138421..3b6d92c8 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -16,7 +16,6 @@ use PDOStatement; use think\Collection; use think\Db; use think\db\exception\BindParamException; -use think\db\Query; use think\Debug; use think\Exception; use think\exception\PDOException; diff --git a/library/think/db/Query.php b/library/think/db/Query.php index e2f9ef7a..6daa6f67 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -16,8 +16,6 @@ use think\Cache; use think\Collection; use think\Config; use think\Db; -use think\db\Builder; -use think\db\Connection; use think\db\exception\BindParamException; use think\db\exception\DataNotFoundException; use think\db\exception\ModelNotFoundException; diff --git a/library/think/exception/PDOException.php b/library/think/exception/PDOException.php index 677092b9..1d88e9f6 100644 --- a/library/think/exception/PDOException.php +++ b/library/think/exception/PDOException.php @@ -11,8 +11,6 @@ namespace think\exception; -use think\exception\DbException; - /** * PDO异常处理类 * 重新封装了系统的\PDOException类 diff --git a/library/think/exception/RouteNotFoundException.php b/library/think/exception/RouteNotFoundException.php index 6ee2f7b6..f85a3c4b 100644 --- a/library/think/exception/RouteNotFoundException.php +++ b/library/think/exception/RouteNotFoundException.php @@ -11,8 +11,6 @@ namespace think\exception; -use think\exception\HttpException; - class RouteNotFoundException extends HttpException { diff --git a/library/think/log/driver/Socket.php b/library/think/log/driver/Socket.php index 612a9021..08fd8ace 100644 --- a/library/think/log/driver/Socket.php +++ b/library/think/log/driver/Socket.php @@ -209,19 +209,19 @@ class Socket } if (!isset($_SERVER[$key])) { - return null; + return; } if (empty($args)) { if (!preg_match('/SocketLog\((.*?)\)/', $_SERVER[$key], $match)) { $args = ['tabid' => null]; - return null; + return; } parse_str($match[1], $args); } if (isset($args[$name])) { return $args[$name]; } - return null; + return; } /** diff --git a/library/think/model/relation/BelongsTo.php b/library/think/model/relation/BelongsTo.php index b29355a0..0f1f0c73 100644 --- a/library/think/model/relation/BelongsTo.php +++ b/library/think/model/relation/BelongsTo.php @@ -12,7 +12,6 @@ namespace think\model\relation; use think\Model; -use think\model\relation\OneToOne; class BelongsTo extends OneToOne { diff --git a/library/think/model/relation/HasOne.php b/library/think/model/relation/HasOne.php index fbfc8042..4ac1a589 100644 --- a/library/think/model/relation/HasOne.php +++ b/library/think/model/relation/HasOne.php @@ -12,7 +12,6 @@ namespace think\model\relation; use think\Model; -use think\model\relation\OneToOne; class HasOne extends OneToOne { diff --git a/library/think/model/relation/OneToOne.php b/library/think/model/relation/OneToOne.php index a5a5de9d..0f22898b 100644 --- a/library/think/model/relation/OneToOne.php +++ b/library/think/model/relation/OneToOne.php @@ -16,7 +16,6 @@ use think\Exception; use think\Loader; use think\Model; use think\model\Relation; -use think\model\relation\BelongsTo; abstract class OneToOne extends Relation { diff --git a/library/think/process/Builder.php b/library/think/process/Builder.php index 826e6745..da561639 100644 --- a/library/think/process/Builder.php +++ b/library/think/process/Builder.php @@ -15,10 +15,9 @@ use think\Process; class Builder { - private $arguments; private $cwd; - private $env = null; + private $env = null; private $input; private $timeout = 60; private $options = []; @@ -155,7 +154,7 @@ class Builder return $this; } - $timeout = (float)$timeout; + $timeout = (float) $timeout; if ($timeout < 0) { throw new \InvalidArgumentException('The timeout value must be a valid positive integer or float number.'); @@ -231,4 +230,4 @@ class Builder return $process; } -} \ No newline at end of file +} diff --git a/library/think/process/Utils.php b/library/think/process/Utils.php index 3ed136a5..f94c6488 100644 --- a/library/think/process/Utils.php +++ b/library/think/process/Utils.php @@ -60,7 +60,7 @@ class Utils return $input; } if (is_scalar($input)) { - return (string)$input; + return (string) $input; } throw new \InvalidArgumentException(sprintf('%s only accepts strings or stream resources.', $caller)); } @@ -72,4 +72,4 @@ class Utils return 2 < strlen($arg) && $char === $arg[0] && $char === $arg[strlen($arg) - 1]; } -} \ No newline at end of file +} diff --git a/library/think/process/exception/Faild.php b/library/think/process/exception/Failed.php similarity index 99% rename from library/think/process/exception/Faild.php rename to library/think/process/exception/Failed.php index 23df369d..52950823 100644 --- a/library/think/process/exception/Faild.php +++ b/library/think/process/exception/Failed.php @@ -11,7 +11,6 @@ namespace think\process\exception; - use think\Process; class Failed extends \RuntimeException diff --git a/library/think/process/pipes/Unix.php b/library/think/process/pipes/Unix.php index abfe61b2..fd99a5d6 100644 --- a/library/think/process/pipes/Unix.php +++ b/library/think/process/pipes/Unix.php @@ -25,14 +25,14 @@ class Unix extends Pipes public function __construct($ttyMode, $ptyMode, $input, $disableOutput) { - $this->ttyMode = (bool)$ttyMode; - $this->ptyMode = (bool)$ptyMode; - $this->disableOutput = (bool)$disableOutput; + $this->ttyMode = (bool) $ttyMode; + $this->ptyMode = (bool) $ptyMode; + $this->disableOutput = (bool) $disableOutput; if (is_resource($input)) { $this->input = $input; } else { - $this->inputBuffer = (string)$input; + $this->inputBuffer = (string) $input; } } @@ -134,12 +134,12 @@ class Unix extends Pipes $type = (false !== $found = array_search($pipe, $this->pipes)) ? $found : 'input'; $data = ''; - while ('' !== $dataread = (string)fread($pipe, self::CHUNK_SIZE)) { + while ('' !== $dataread = (string) fread($pipe, self::CHUNK_SIZE)) { $data .= $dataread; } if ('' !== $data) { - if ($type === 'input') { + if ('input' === $type) { $this->inputBuffer .= $data; } else { $read[$type] = $data; @@ -147,7 +147,7 @@ class Unix extends Pipes } if (false === $data || (true === $close && feof($pipe) && '' === $data)) { - if ($type === 'input') { + if ('input' === $type) { $this->input = null; } else { fclose($this->pipes[$type]); @@ -160,7 +160,7 @@ class Unix extends Pipes while (strlen($this->inputBuffer)) { $written = fwrite($w[0], $this->inputBuffer, 2 << 18); // write 512k if ($written > 0) { - $this->inputBuffer = (string)substr($this->inputBuffer, $written); + $this->inputBuffer = (string) substr($this->inputBuffer, $written); } else { break; } @@ -180,7 +180,7 @@ class Unix extends Pipes */ public function areOpen() { - return (bool)$this->pipes; + return (bool) $this->pipes; } /** @@ -193,4 +193,4 @@ class Unix extends Pipes { return new static($process->isTty(), $process->isPty(), $input, $process->isOutputDisabled()); } -} \ No newline at end of file +} diff --git a/library/think/process/pipes/Windows.php b/library/think/process/pipes/Windows.php index 2cc44ca7..bba7e9b8 100644 --- a/library/think/process/pipes/Windows.php +++ b/library/think/process/pipes/Windows.php @@ -30,7 +30,7 @@ class Windows extends Pipes public function __construct($disableOutput, $input) { - $this->disableOutput = (bool)$disableOutput; + $this->disableOutput = (bool) $disableOutput; if (!$this->disableOutput) { @@ -128,7 +128,7 @@ class Windows extends Pipes */ public function areOpen() { - return (bool)$this->pipes && (bool)$this->fileHandles; + return (bool) $this->pipes && (bool) $this->fileHandles; } /** @@ -213,7 +213,7 @@ class Windows extends Pipes while (strlen($this->inputBuffer)) { $written = fwrite($w[0], $this->inputBuffer, 2 << 18); if ($written > 0) { - $this->inputBuffer = (string)substr($this->inputBuffer, $written); + $this->inputBuffer = (string) substr($this->inputBuffer, $written); } else { break; } @@ -225,4 +225,4 @@ class Windows extends Pipes unset($this->pipes[0]); } } -} \ No newline at end of file +} diff --git a/library/traits/think/Instance.php b/library/traits/think/Instance.php index 206a9412..4dd005e4 100644 --- a/library/traits/think/Instance.php +++ b/library/traits/think/Instance.php @@ -11,7 +11,7 @@ namespace traits\think; -use \think\Exception; +use think\Exception; trait Instance { -- Gitee From 18f8ee155de5fd702e18fd963dca51cfbae0bda3 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 24 Dec 2016 21:44:12 +0800 Subject: [PATCH 0323/1170] =?UTF-8?q?=E8=A7=84=E8=8C=83=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/console/output/driver/Console.php | 2 +- library/think/db/exception/BindParamException.php | 2 +- library/think/db/exception/DataNotFoundException.php | 8 ++++---- library/think/db/exception/ModelNotFoundException.php | 8 ++++---- library/think/template/taglib/Cx.php | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/library/think/console/output/driver/Console.php b/library/think/console/output/driver/Console.php index a6e89218..3fbe224f 100644 --- a/library/think/console/output/driver/Console.php +++ b/library/think/console/output/driver/Console.php @@ -219,7 +219,7 @@ class Console private function getMode() { if (!function_exists('proc_open')) { - return null; + return; } $descriptorspec = [1 => ['pipe', 'w'], 2 => ['pipe', 'w']]; diff --git a/library/think/db/exception/BindParamException.php b/library/think/db/exception/BindParamException.php index 585a0d73..3872e7c0 100644 --- a/library/think/db/exception/BindParamException.php +++ b/library/think/db/exception/BindParamException.php @@ -16,7 +16,7 @@ use think\exception\DbException; /** * PDO参数绑定异常 */ -class BindParamException extends DbException +class BindParamException extends DbException { /** diff --git a/library/think/db/exception/DataNotFoundException.php b/library/think/db/exception/DataNotFoundException.php index efd66d3b..cd4253ab 100644 --- a/library/think/db/exception/DataNotFoundException.php +++ b/library/think/db/exception/DataNotFoundException.php @@ -13,7 +13,7 @@ namespace think\db\exception; use think\exception\DbException; -class DataNotFoundException extends DbException +class DataNotFoundException extends DbException { protected $table; @@ -23,10 +23,10 @@ class DataNotFoundException extends DbException * @param string $table * @param array $config */ - public function __construct($message, $table = '', Array $config = []) + public function __construct($message, $table = '', array $config = []) { - $this->message = $message; - $this->table = $table; + $this->message = $message; + $this->table = $table; $this->setData('Database Config', $config); } diff --git a/library/think/db/exception/ModelNotFoundException.php b/library/think/db/exception/ModelNotFoundException.php index 69b70965..1d4724a6 100644 --- a/library/think/db/exception/ModelNotFoundException.php +++ b/library/think/db/exception/ModelNotFoundException.php @@ -13,7 +13,7 @@ namespace think\db\exception; use think\exception\DbException; -class ModelNotFoundException extends DbException +class ModelNotFoundException extends DbException { protected $model; @@ -22,10 +22,10 @@ class ModelNotFoundException extends DbException * @param string $message * @param string $model */ - public function __construct($message, $model = '', Array $config = []) + public function __construct($message, $model = '', array $config = []) { - $this->message = $message; - $this->model = $model; + $this->message = $message; + $this->model = $model; $this->setData('Database Config', $config); } diff --git a/library/think/template/taglib/Cx.php b/library/think/template/taglib/Cx.php index b15c7bba..1a23c764 100644 --- a/library/think/template/taglib/Cx.php +++ b/library/think/template/taglib/Cx.php @@ -620,8 +620,8 @@ class Cx extends Taglib return $parseStr; } - /** - * U函数的tag标签 + /** + * url函数的tag标签 * 格式:{url link="模块/控制器/方法" vars="参数" suffix="true或者false 是否带有后缀" domain="true或者false 是否携带域名" /} * @access public * @param array $tag 标签属性 -- Gitee From 3363dd6226d1798733d403295d15645cfe046a65 Mon Sep 17 00:00:00 2001 From: ThinkPHP Date: Sat, 24 Dec 2016 13:46:11 +0000 Subject: [PATCH 0324/1170] Apply fixes from StyleCI --- console.php | 2 +- library/think/Debug.php | 2 +- library/think/Session.php | 720 +++++++++--------- library/think/Url.php | 2 +- library/think/console/command/Lists.php | 2 +- .../console/command/optimize/Autoload.php | 2 +- library/think/console/output/Ask.php | 2 +- library/think/paginator/Collection.php | 2 +- library/think/paginator/driver/Bootstrap.php | 4 +- library/think/process/exception/Timeout.php | 2 +- library/think/process/pipes/Pipes.php | 3 +- tests/mock.php | 40 +- tests/thinkphp/library/think/appTest.php | 1 - tests/thinkphp/library/think/behavior/One.php | 4 +- .../thinkphp/library/think/behavior/Three.php | 2 +- tests/thinkphp/library/think/behavior/Two.php | 2 +- .../think/cache/driver/cacheTestCase.php | 414 +++++----- .../library/think/cache/driver/fileTest.php | 92 +-- .../library/think/cache/driver/liteTest.php | 138 ++-- .../think/cache/driver/memcacheTest.php | 98 +-- .../think/cache/driver/memcachedTest.php | 144 ++-- .../thinkphp/library/think/controllerTest.php | 8 +- tests/thinkphp/library/think/dbTest.php | 3 +- tests/thinkphp/library/think/debugTest.php | 358 ++++----- tests/thinkphp/library/think/lang/lang.php | 2 +- .../library/think/log/driver/fileTest.php | 68 +- tests/thinkphp/library/think/paginateTest.php | 6 +- tests/thinkphp/library/think/responseTest.php | 190 ++--- tests/thinkphp/library/think/sessionTest.php | 638 ++++++++-------- .../library/think/template/taglib/cxTest.php | 2 +- tests/thinkphp/library/think/viewTest.php | 152 ++-- 31 files changed, 1548 insertions(+), 1557 deletions(-) diff --git a/console.php b/console.php index 3d518e78..fa777801 100644 --- a/console.php +++ b/console.php @@ -17,4 +17,4 @@ require __DIR__ . '/base.php'; // 执行应用 App::initCommon(); -Console::init(); \ No newline at end of file +Console::init(); diff --git a/library/think/Debug.php b/library/think/Debug.php index 24acd3d3..0b5d022d 100644 --- a/library/think/Debug.php +++ b/library/think/Debug.php @@ -174,7 +174,7 @@ class Debug $output = '
' . $label . $output . '
'; } if ($echo) { - echo ($output); + echo($output); return; } else { return $output; diff --git a/library/think/Session.php b/library/think/Session.php index 6870e164..06adcff6 100644 --- a/library/think/Session.php +++ b/library/think/Session.php @@ -1,360 +1,360 @@ - -// +---------------------------------------------------------------------- - -namespace think; - -use think\exception\ClassNotFoundException; - -class Session -{ - protected static $prefix = ''; - protected static $init = null; - - /** - * 设置或者获取session作用域(前缀) - * @param string $prefix - * @return string|void - */ - public static function prefix($prefix = '') - { - if (empty($prefix) && null !== $prefix) { - return self::$prefix; - } else { - self::$prefix = $prefix; - } - } - - /** - * session初始化 - * @param array $config - * @return void - * @throws \think\Exception - */ - public static function init(array $config = []) - { - if (empty($config)) { - $config = Config::get('session'); - } - // 记录初始化信息 - App::$debug && Log::record('[ SESSION ] INIT ' . var_export($config, true), 'info'); - $isDoStart = false; - if (isset($config['use_trans_sid'])) { - ini_set('session.use_trans_sid', $config['use_trans_sid'] ? 1 : 0); - } - - // 启动session - if (!empty($config['auto_start']) && PHP_SESSION_ACTIVE != session_status()) { - ini_set('session.auto_start', 0); - $isDoStart = true; - } - - if (isset($config['prefix'])) { - self::$prefix = $config['prefix']; - } - if (isset($config['var_session_id']) && isset($_REQUEST[$config['var_session_id']])) { - session_id($_REQUEST[$config['var_session_id']]); - } elseif (isset($config['id']) && !empty($config['id'])) { - session_id($config['id']); - } - if (isset($config['name'])) { - session_name($config['name']); - } - if (isset($config['path'])) { - session_save_path($config['path']); - } - if (isset($config['domain'])) { - ini_set('session.cookie_domain', $config['domain']); - } - if (isset($config['expire'])) { - ini_set('session.gc_maxlifetime', $config['expire']); - ini_set('session.cookie_lifetime', $config['expire']); - } - - if (isset($config['use_cookies'])) { - ini_set('session.use_cookies', $config['use_cookies'] ? 1 : 0); - } - if (isset($config['cache_limiter'])) { - session_cache_limiter($config['cache_limiter']); - } - if (isset($config['cache_expire'])) { - session_cache_expire($config['cache_expire']); - } - if (!empty($config['type'])) { - // 读取session驱动 - $class = false !== strpos($config['type'], '\\') ? $config['type'] : '\\think\\session\\driver\\' . ucwords($config['type']); - - // 检查驱动类 - if (!class_exists($class) || !session_set_save_handler(new $class($config))) { - throw new ClassNotFoundException('error session handler:' . $class, $class); - } - } - if ($isDoStart) { - session_start(); - self::$init = true; - } else { - self::$init = false; - } - } - - /** - * session自动启动或者初始化 - * @return void - */ - public static function boot() - { - if (is_null(self::$init)) { - self::init(); - } elseif (false === self::$init) { - if (PHP_SESSION_ACTIVE != session_status()) { - session_start(); - } - self::$init = true; - } - } - - /** - * session设置 - * @param string $name session名称 - * @param mixed $value session值 - * @param string|null $prefix 作用域(前缀) - * @return void - */ - public static function set($name, $value = '', $prefix = null) - { - empty(self::$init) && self::boot(); - - $prefix = !is_null($prefix) ? $prefix : self::$prefix; - if (strpos($name, '.')) { - // 二维数组赋值 - list($name1, $name2) = explode('.', $name); - if ($prefix) { - $_SESSION[$prefix][$name1][$name2] = $value; - } else { - $_SESSION[$name1][$name2] = $value; - } - } elseif ($prefix) { - $_SESSION[$prefix][$name] = $value; - } else { - $_SESSION[$name] = $value; - } - } - - /** - * session获取 - * @param string $name session名称 - * @param string|null $prefix 作用域(前缀) - * @return mixed - */ - public static function get($name = '', $prefix = null) - { - empty(self::$init) && self::boot(); - $prefix = !is_null($prefix) ? $prefix : self::$prefix; - if ('' == $name) { - // 获取全部的session - $value = $prefix ? (!empty($_SESSION[$prefix]) ? $_SESSION[$prefix] : []) : $_SESSION; - } elseif ($prefix) { - // 获取session - if (strpos($name, '.')) { - list($name1, $name2) = explode('.', $name); - $value = isset($_SESSION[$prefix][$name1][$name2]) ? $_SESSION[$prefix][$name1][$name2] : null; - } else { - $value = isset($_SESSION[$prefix][$name]) ? $_SESSION[$prefix][$name] : null; - } - } else { - if (strpos($name, '.')) { - list($name1, $name2) = explode('.', $name); - $value = isset($_SESSION[$name1][$name2]) ? $_SESSION[$name1][$name2] : null; - } else { - $value = isset($_SESSION[$name]) ? $_SESSION[$name] : null; - } - } - return $value; - } - - /** - * session获取并删除 - * @param string $name session名称 - * @param string|null $prefix 作用域(前缀) - * @return mixed - */ - public static function pull($name, $prefix = null) - { - $result = self::get($name, $prefix); - if ($result) { - self::delete($name, $prefix); - return $result; - } else { - return null; - } - } - - /** - * session设置 下一次请求有效 - * @param string $name session名称 - * @param mixed $value session值 - * @param string|null $prefix 作用域(前缀) - * @return void - */ - public static function flash($name, $value) - { - self::set($name, $value); - if (!self::has('__flash__.__time__')) { - self::set('__flash__.__time__', $_SERVER['REQUEST_TIME_FLOAT']); - } - self::push('__flash__', $name); - } - - /** - * 清空当前请求的session数据 - * @return void - */ - public static function flush() - { - if (self::$init) { - $item = self::get('__flash__'); - - if (!empty($item)) { - $time = $item['__time__']; - if ($_SERVER['REQUEST_TIME_FLOAT'] > $time) { - unset($item['__time__']); - self::delete($item); - self::set('__flash__', []); - } - } - } - } - - /** - * 删除session数据 - * @param string|array $name session名称 - * @param string|null $prefix 作用域(前缀) - * @return void - */ - public static function delete($name, $prefix = null) - { - empty(self::$init) && self::boot(); - $prefix = !is_null($prefix) ? $prefix : self::$prefix; - if (is_array($name)) { - foreach ($name as $key) { - self::delete($key, $prefix); - } - } elseif (strpos($name, '.')) { - list($name1, $name2) = explode('.', $name); - if ($prefix) { - unset($_SESSION[$prefix][$name1][$name2]); - } else { - unset($_SESSION[$name1][$name2]); - } - } else { - if ($prefix) { - unset($_SESSION[$prefix][$name]); - } else { - unset($_SESSION[$name]); - } - } - } - - /** - * 清空session数据 - * @param string|null $prefix 作用域(前缀) - * @return void - */ - public static function clear($prefix = null) - { - empty(self::$init) && self::boot(); - $prefix = !is_null($prefix) ? $prefix : self::$prefix; - if ($prefix) { - unset($_SESSION[$prefix]); - } else { - $_SESSION = []; - } - } - - /** - * 判断session数据 - * @param string $name session名称 - * @param string|null $prefix - * @return bool - */ - public static function has($name, $prefix = null) - { - empty(self::$init) && self::boot(); - $prefix = !is_null($prefix) ? $prefix : self::$prefix; - if (strpos($name, '.')) { - // 支持数组 - list($name1, $name2) = explode('.', $name); - return $prefix ? isset($_SESSION[$prefix][$name1][$name2]) : isset($_SESSION[$name1][$name2]); - } else { - return $prefix ? isset($_SESSION[$prefix][$name]) : isset($_SESSION[$name]); - } - } - - /** - * 添加数据到一个session数组 - * @param string $key - * @param mixed $value - * @return void - */ - public static function push($key, $value) - { - $array = self::get($key); - if (is_null($array)) { - $array = []; - } - $array[] = $value; - self::set($key, $array); - } - - /** - * 启动session - * @return void - */ - public static function start() - { - session_start(); - self::$init = true; - } - - /** - * 销毁session - * @return void - */ - public static function destroy() - { - if (!empty($_SESSION)) { - $_SESSION = []; - } - session_unset(); - session_destroy(); - self::$init = null; - } - - /** - * 重新生成session_id - * @param bool $delete 是否删除关联会话文件 - * @return void - */ - private static function regenerate($delete = false) - { - session_regenerate_id($delete); - } - - /** - * 暂停session - * @return void - */ - public static function pause() - { - // 暂停session - session_write_close(); - self::$init = false; - } -} + +// +---------------------------------------------------------------------- + +namespace think; + +use think\exception\ClassNotFoundException; + +class Session +{ + protected static $prefix = ''; + protected static $init = null; + + /** + * 设置或者获取session作用域(前缀) + * @param string $prefix + * @return string|void + */ + public static function prefix($prefix = '') + { + if (empty($prefix) && null !== $prefix) { + return self::$prefix; + } else { + self::$prefix = $prefix; + } + } + + /** + * session初始化 + * @param array $config + * @return void + * @throws \think\Exception + */ + public static function init(array $config = []) + { + if (empty($config)) { + $config = Config::get('session'); + } + // 记录初始化信息 + App::$debug && Log::record('[ SESSION ] INIT ' . var_export($config, true), 'info'); + $isDoStart = false; + if (isset($config['use_trans_sid'])) { + ini_set('session.use_trans_sid', $config['use_trans_sid'] ? 1 : 0); + } + + // 启动session + if (!empty($config['auto_start']) && PHP_SESSION_ACTIVE != session_status()) { + ini_set('session.auto_start', 0); + $isDoStart = true; + } + + if (isset($config['prefix'])) { + self::$prefix = $config['prefix']; + } + if (isset($config['var_session_id']) && isset($_REQUEST[$config['var_session_id']])) { + session_id($_REQUEST[$config['var_session_id']]); + } elseif (isset($config['id']) && !empty($config['id'])) { + session_id($config['id']); + } + if (isset($config['name'])) { + session_name($config['name']); + } + if (isset($config['path'])) { + session_save_path($config['path']); + } + if (isset($config['domain'])) { + ini_set('session.cookie_domain', $config['domain']); + } + if (isset($config['expire'])) { + ini_set('session.gc_maxlifetime', $config['expire']); + ini_set('session.cookie_lifetime', $config['expire']); + } + + if (isset($config['use_cookies'])) { + ini_set('session.use_cookies', $config['use_cookies'] ? 1 : 0); + } + if (isset($config['cache_limiter'])) { + session_cache_limiter($config['cache_limiter']); + } + if (isset($config['cache_expire'])) { + session_cache_expire($config['cache_expire']); + } + if (!empty($config['type'])) { + // 读取session驱动 + $class = false !== strpos($config['type'], '\\') ? $config['type'] : '\\think\\session\\driver\\' . ucwords($config['type']); + + // 检查驱动类 + if (!class_exists($class) || !session_set_save_handler(new $class($config))) { + throw new ClassNotFoundException('error session handler:' . $class, $class); + } + } + if ($isDoStart) { + session_start(); + self::$init = true; + } else { + self::$init = false; + } + } + + /** + * session自动启动或者初始化 + * @return void + */ + public static function boot() + { + if (is_null(self::$init)) { + self::init(); + } elseif (false === self::$init) { + if (PHP_SESSION_ACTIVE != session_status()) { + session_start(); + } + self::$init = true; + } + } + + /** + * session设置 + * @param string $name session名称 + * @param mixed $value session值 + * @param string|null $prefix 作用域(前缀) + * @return void + */ + public static function set($name, $value = '', $prefix = null) + { + empty(self::$init) && self::boot(); + + $prefix = !is_null($prefix) ? $prefix : self::$prefix; + if (strpos($name, '.')) { + // 二维数组赋值 + list($name1, $name2) = explode('.', $name); + if ($prefix) { + $_SESSION[$prefix][$name1][$name2] = $value; + } else { + $_SESSION[$name1][$name2] = $value; + } + } elseif ($prefix) { + $_SESSION[$prefix][$name] = $value; + } else { + $_SESSION[$name] = $value; + } + } + + /** + * session获取 + * @param string $name session名称 + * @param string|null $prefix 作用域(前缀) + * @return mixed + */ + public static function get($name = '', $prefix = null) + { + empty(self::$init) && self::boot(); + $prefix = !is_null($prefix) ? $prefix : self::$prefix; + if ('' == $name) { + // 获取全部的session + $value = $prefix ? (!empty($_SESSION[$prefix]) ? $_SESSION[$prefix] : []) : $_SESSION; + } elseif ($prefix) { + // 获取session + if (strpos($name, '.')) { + list($name1, $name2) = explode('.', $name); + $value = isset($_SESSION[$prefix][$name1][$name2]) ? $_SESSION[$prefix][$name1][$name2] : null; + } else { + $value = isset($_SESSION[$prefix][$name]) ? $_SESSION[$prefix][$name] : null; + } + } else { + if (strpos($name, '.')) { + list($name1, $name2) = explode('.', $name); + $value = isset($_SESSION[$name1][$name2]) ? $_SESSION[$name1][$name2] : null; + } else { + $value = isset($_SESSION[$name]) ? $_SESSION[$name] : null; + } + } + return $value; + } + + /** + * session获取并删除 + * @param string $name session名称 + * @param string|null $prefix 作用域(前缀) + * @return mixed + */ + public static function pull($name, $prefix = null) + { + $result = self::get($name, $prefix); + if ($result) { + self::delete($name, $prefix); + return $result; + } else { + return; + } + } + + /** + * session设置 下一次请求有效 + * @param string $name session名称 + * @param mixed $value session值 + * @param string|null $prefix 作用域(前缀) + * @return void + */ + public static function flash($name, $value) + { + self::set($name, $value); + if (!self::has('__flash__.__time__')) { + self::set('__flash__.__time__', $_SERVER['REQUEST_TIME_FLOAT']); + } + self::push('__flash__', $name); + } + + /** + * 清空当前请求的session数据 + * @return void + */ + public static function flush() + { + if (self::$init) { + $item = self::get('__flash__'); + + if (!empty($item)) { + $time = $item['__time__']; + if ($_SERVER['REQUEST_TIME_FLOAT'] > $time) { + unset($item['__time__']); + self::delete($item); + self::set('__flash__', []); + } + } + } + } + + /** + * 删除session数据 + * @param string|array $name session名称 + * @param string|null $prefix 作用域(前缀) + * @return void + */ + public static function delete($name, $prefix = null) + { + empty(self::$init) && self::boot(); + $prefix = !is_null($prefix) ? $prefix : self::$prefix; + if (is_array($name)) { + foreach ($name as $key) { + self::delete($key, $prefix); + } + } elseif (strpos($name, '.')) { + list($name1, $name2) = explode('.', $name); + if ($prefix) { + unset($_SESSION[$prefix][$name1][$name2]); + } else { + unset($_SESSION[$name1][$name2]); + } + } else { + if ($prefix) { + unset($_SESSION[$prefix][$name]); + } else { + unset($_SESSION[$name]); + } + } + } + + /** + * 清空session数据 + * @param string|null $prefix 作用域(前缀) + * @return void + */ + public static function clear($prefix = null) + { + empty(self::$init) && self::boot(); + $prefix = !is_null($prefix) ? $prefix : self::$prefix; + if ($prefix) { + unset($_SESSION[$prefix]); + } else { + $_SESSION = []; + } + } + + /** + * 判断session数据 + * @param string $name session名称 + * @param string|null $prefix + * @return bool + */ + public static function has($name, $prefix = null) + { + empty(self::$init) && self::boot(); + $prefix = !is_null($prefix) ? $prefix : self::$prefix; + if (strpos($name, '.')) { + // 支持数组 + list($name1, $name2) = explode('.', $name); + return $prefix ? isset($_SESSION[$prefix][$name1][$name2]) : isset($_SESSION[$name1][$name2]); + } else { + return $prefix ? isset($_SESSION[$prefix][$name]) : isset($_SESSION[$name]); + } + } + + /** + * 添加数据到一个session数组 + * @param string $key + * @param mixed $value + * @return void + */ + public static function push($key, $value) + { + $array = self::get($key); + if (is_null($array)) { + $array = []; + } + $array[] = $value; + self::set($key, $array); + } + + /** + * 启动session + * @return void + */ + public static function start() + { + session_start(); + self::$init = true; + } + + /** + * 销毁session + * @return void + */ + public static function destroy() + { + if (!empty($_SESSION)) { + $_SESSION = []; + } + session_unset(); + session_destroy(); + self::$init = null; + } + + /** + * 重新生成session_id + * @param bool $delete 是否删除关联会话文件 + * @return void + */ + private static function regenerate($delete = false) + { + session_regenerate_id($delete); + } + + /** + * 暂停session + * @return void + */ + public static function pause() + { + // 暂停session + session_write_close(); + self::$init = false; + } +} diff --git a/library/think/Url.php b/library/think/Url.php index 75fffac6..a1bc8d2a 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -248,7 +248,7 @@ class Url $domain .= $rootDomain; } break; - } else if (false !== strpos($key, '*')) { + } elseif (false !== strpos($key, '*')) { if (!empty($rootDomain)) { $domain .= $rootDomain; } diff --git a/library/think/console/command/Lists.php b/library/think/console/command/Lists.php index ffbee07c..084ddaa2 100644 --- a/library/think/console/command/Lists.php +++ b/library/think/console/command/Lists.php @@ -71,4 +71,4 @@ EOF new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list') ]); } -} \ No newline at end of file +} diff --git a/library/think/console/command/optimize/Autoload.php b/library/think/console/command/optimize/Autoload.php index 0481e179..7311aafb 100644 --- a/library/think/console/command/optimize/Autoload.php +++ b/library/think/console/command/optimize/Autoload.php @@ -278,4 +278,4 @@ EOF; return $classes; } -} \ No newline at end of file +} diff --git a/library/think/console/output/Ask.php b/library/think/console/output/Ask.php index 4d360bce..3933eb29 100644 --- a/library/think/console/output/Ask.php +++ b/library/think/console/output/Ask.php @@ -337,4 +337,4 @@ class Ask return self::$stty = $exitcode === 0; } -} \ No newline at end of file +} diff --git a/library/think/paginator/Collection.php b/library/think/paginator/Collection.php index 82e88272..50803ba8 100644 --- a/library/think/paginator/Collection.php +++ b/library/think/paginator/Collection.php @@ -71,4 +71,4 @@ class Collection extends \think\Collection throw new Exception('method not exists:' . __CLASS__ . '->' . $method); } } -} \ No newline at end of file +} diff --git a/library/think/paginator/driver/Bootstrap.php b/library/think/paginator/driver/Bootstrap.php index 87e1fe48..13b7bccd 100644 --- a/library/think/paginator/driver/Bootstrap.php +++ b/library/think/paginator/driver/Bootstrap.php @@ -102,7 +102,6 @@ class Bootstrap extends Paginator return $html; } - /** * 渲染分页html * @return mixed @@ -127,7 +126,6 @@ class Bootstrap extends Paginator } } - /** * 生成一个可点击的按钮 * @@ -204,4 +202,4 @@ class Bootstrap extends Paginator return $this->getAvailablePageWrapper($url, $page); } -} \ No newline at end of file +} diff --git a/library/think/process/exception/Timeout.php b/library/think/process/exception/Timeout.php index c085ee8e..d5f1162f 100644 --- a/library/think/process/exception/Timeout.php +++ b/library/think/process/exception/Timeout.php @@ -58,4 +58,4 @@ class Timeout extends \RuntimeException throw new \LogicException(sprintf('Unknown timeout type "%d".', $this->timeoutType)); } } -} \ No newline at end of file +} diff --git a/library/think/process/pipes/Pipes.php b/library/think/process/pipes/Pipes.php index 51da44f3..82396b8f 100644 --- a/library/think/process/pipes/Pipes.php +++ b/library/think/process/pipes/Pipes.php @@ -53,7 +53,6 @@ abstract class Pipes */ abstract public function areOpen(); - /** * {@inheritdoc} */ @@ -91,4 +90,4 @@ abstract class Pipes $this->blocked = false; } -} \ No newline at end of file +} diff --git a/tests/mock.php b/tests/mock.php index 28471ee2..0c29e596 100644 --- a/tests/mock.php +++ b/tests/mock.php @@ -1,20 +1,20 @@ - -// +---------------------------------------------------------------------- - -// 测试入口文件 -$_SERVER['REQUEST_METHOD'] = 'GET'; -// 定义项目测试基础路径 -define('TEST_PATH', __DIR__ . '/'); -// 定义项目路径 -define('APP_PATH', __DIR__ . '/application/'); -// 加载框架基础文件 -require __DIR__ . '/../base.php'; -\think\Loader::addNamespace('tests', TEST_PATH); + +// +---------------------------------------------------------------------- + +// 测试入口文件 +$_SERVER['REQUEST_METHOD'] = 'GET'; +// 定义项目测试基础路径 +define('TEST_PATH', __DIR__ . '/'); +// 定义项目路径 +define('APP_PATH', __DIR__ . '/application/'); +// 加载框架基础文件 +require __DIR__ . '/../base.php'; +\think\Loader::addNamespace('tests', TEST_PATH); diff --git a/tests/thinkphp/library/think/appTest.php b/tests/thinkphp/library/think/appTest.php index 366b4f55..016bbf9c 100644 --- a/tests/thinkphp/library/think/appTest.php +++ b/tests/thinkphp/library/think/appTest.php @@ -16,7 +16,6 @@ namespace tests\thinkphp\library\think; -use ReflectionClass; use think\App; use think\Config; use think\Request; diff --git a/tests/thinkphp/library/think/behavior/One.php b/tests/thinkphp/library/think/behavior/One.php index ae8fa49d..1ec6e66e 100644 --- a/tests/thinkphp/library/think/behavior/One.php +++ b/tests/thinkphp/library/think/behavior/One.php @@ -3,12 +3,12 @@ namespace tests\thinkphp\library\think\behavior; class One { - public function run(&$data){ + public function run(&$data) { $data['id'] = 1; return true; } - public function test(&$data){ + public function test(&$data) { $data['name'] = 'test'; return false; } diff --git a/tests/thinkphp/library/think/behavior/Three.php b/tests/thinkphp/library/think/behavior/Three.php index 0f2e0495..c98b7aeb 100644 --- a/tests/thinkphp/library/think/behavior/Three.php +++ b/tests/thinkphp/library/think/behavior/Three.php @@ -3,7 +3,7 @@ namespace tests\thinkphp\library\think\behavior; class Three { - public function run(&$data){ + public function run(&$data) { $data['id'] = 3; } } diff --git a/tests/thinkphp/library/think/behavior/Two.php b/tests/thinkphp/library/think/behavior/Two.php index 3e194bf5..1e52a2b5 100644 --- a/tests/thinkphp/library/think/behavior/Two.php +++ b/tests/thinkphp/library/think/behavior/Two.php @@ -3,7 +3,7 @@ namespace tests\thinkphp\library\think\behavior; class Two { - public function run(&$data){ + public function run(&$data) { $data['id'] = 2; } } diff --git a/tests/thinkphp/library/think/cache/driver/cacheTestCase.php b/tests/thinkphp/library/think/cache/driver/cacheTestCase.php index ec8f9b6b..5b2f2a3e 100644 --- a/tests/thinkphp/library/think/cache/driver/cacheTestCase.php +++ b/tests/thinkphp/library/think/cache/driver/cacheTestCase.php @@ -1,207 +1,207 @@ - -// +---------------------------------------------------------------------- - -/** - * 缓存抽象类,提供一些测试 - * @author simon - */ - -namespace tests\thinkphp\library\think\cache\driver; - -use think\Cache; - -abstract class cacheTestCase extends \PHPUnit_Framework_TestCase -{ - - /** - * 获取缓存句柄,子类必须有 - * @access protected - */ - abstract protected function getCacheInstance(); - - /** - * tearDown函数 - */ - protected function tearDown() - { - } - - /** - * 设定一组测试值,包括测试字符串、整数、数组和对象 - * @return mixed - * @access public - */ - public function prepare() - { - $cache = $this->getCacheInstance(); - $cache->clear(); - $cache->set('string_test', 'string_test'); - $cache->set('number_test', 11); - $cache->set('array_test', ['array_test' => 'array_test']); - return $cache; - } - - /** - * 测试缓存设置,包括测试字符串、整数、数组和对象 - * @return mixed - * @access public - */ - public function testSet() - { - $cache = $this->getCacheInstance(); - $this->assertTrue($cache->set('string_test', 'string_test')); - $this->assertTrue($cache->set('number_test', 11)); - $this->assertTrue($cache->set('array_test', ['array_test' => 'array_test'])); - } - - /** - * 测试缓存自增 - * @return mixed - * @access public - */ - public function testInc() - { - $cache = $this->getCacheInstance(); - $this->assertEquals(14, $cache->inc('number_test', 3)); - } - - /** - * 测试缓存自减 - * @return mixed - * @access public - */ - public function testDec() - { - $cache = $this->getCacheInstance(); - $this->assertEquals(8, $cache->dec('number_test', 6)); - } - - /** - * 测试缓存读取,包括测试字符串、整数、数组和对象 - * @return mixed - * @access public - */ - public function testGet() - { - $cache = $this->prepare(); - $this->assertEquals('string_test', $cache->get('string_test')); - $this->assertEquals(11, $cache->get('number_test')); - $array = $cache->get('array_test'); - $this->assertArrayHasKey('array_test', $array); - $this->assertEquals('array_test', $array['array_test']); - - $result = $cache->set('no_expire', 1, 0); - $this->assertTrue($result); - } - - /** - * 测试缓存存在情况,包括测试字符串、整数、数组和对象 - * @return mixed - * @access public - */ - public function testExists() - { - $cache = $this->prepare(); - $this->assertNotEmpty($cache->has('string_test')); - $this->assertNotEmpty($cache->has('number_test')); - $this->assertFalse($cache->has('not_exists')); - } - - /** - * 测试缓存不存在情况,包括测试字符串、整数、数组和对象 - * @return mixed - * @access public - */ - public function testGetNonExistent() - { - $cache = $this->getCacheInstance(); - $this->assertFalse($cache->get('non_existent_key', false)); - } - - /** - * 测试特殊值缓存,包括测试字符串、整数、数组和对象 - * @return mixed - * @access public - */ - public function testStoreSpecialValues() - { - $cache = $this->getCacheInstance(); - $cache->set('null_value', null); - //清空缓存后,返回null而不是false - $this->assertTrue(is_null($cache->get('null_value'))); - } - - /** - * 缓存过期测试 - * @return mixed - * @access public - */ - public function testExpire() - { - $cache = $this->getCacheInstance(); - $this->assertTrue($cache->set('expire_test', 'expire_test', 1)); - usleep(600000); - $this->assertEquals('expire_test', $cache->get('expire_test')); - usleep(800000); - $this->assertFalse($cache->get('expire_test')); - } - - /** - * 删除缓存测试 - * @return mixed - * @access public - */ - public function testDelete() - { - $cache = $this->prepare(); - $this->assertNotNull($cache->rm('number_test')); - $this->assertFalse($cache->get('number_test')); - } - - /** - * 获取并删除缓存测试 - * @return mixed - * @access public - */ - public function testPull() - { - $cache = $this->prepare(); - $this->assertEquals(11, $cache->pull('number_test')); - $this->assertFalse($cache->get('number_test')); - } - - /** - * 清空缓存测试 - * @return mixed - * @access public - */ - public function testClear() - { - $cache = $this->prepare(); - $this->assertTrue($cache->clear()); - $this->assertFalse($cache->get('number_test')); - } - - public function testStaticCall() - { - $this->assertTrue(Cache::set('a', 1)); - $this->assertEquals(1, Cache::get('a')); - $this->assertEquals(2, Cache::inc('a')); - $this->assertEquals(4, Cache::inc('a', 2)); - $this->assertEquals(4, Cache::get('a')); - $this->assertEquals(3, Cache::dec('a')); - $this->assertEquals(1, Cache::dec('a', 2)); - $this->assertEquals(1, Cache::get('a')); - $this->assertNotNull(Cache::rm('a')); - $this->assertNotNull(Cache::clear()); - } - -} + +// +---------------------------------------------------------------------- + +/** + * 缓存抽象类,提供一些测试 + * @author simon + */ + +namespace tests\thinkphp\library\think\cache\driver; + +use think\Cache; + +abstract class cacheTestCase extends \PHPUnit_Framework_TestCase +{ + + /** + * 获取缓存句柄,子类必须有 + * @access protected + */ + abstract protected function getCacheInstance(); + + /** + * tearDown函数 + */ + protected function tearDown() + { + } + + /** + * 设定一组测试值,包括测试字符串、整数、数组和对象 + * @return mixed + * @access public + */ + public function prepare() + { + $cache = $this->getCacheInstance(); + $cache->clear(); + $cache->set('string_test', 'string_test'); + $cache->set('number_test', 11); + $cache->set('array_test', ['array_test' => 'array_test']); + return $cache; + } + + /** + * 测试缓存设置,包括测试字符串、整数、数组和对象 + * @return mixed + * @access public + */ + public function testSet() + { + $cache = $this->getCacheInstance(); + $this->assertTrue($cache->set('string_test', 'string_test')); + $this->assertTrue($cache->set('number_test', 11)); + $this->assertTrue($cache->set('array_test', ['array_test' => 'array_test'])); + } + + /** + * 测试缓存自增 + * @return mixed + * @access public + */ + public function testInc() + { + $cache = $this->getCacheInstance(); + $this->assertEquals(14, $cache->inc('number_test', 3)); + } + + /** + * 测试缓存自减 + * @return mixed + * @access public + */ + public function testDec() + { + $cache = $this->getCacheInstance(); + $this->assertEquals(8, $cache->dec('number_test', 6)); + } + + /** + * 测试缓存读取,包括测试字符串、整数、数组和对象 + * @return mixed + * @access public + */ + public function testGet() + { + $cache = $this->prepare(); + $this->assertEquals('string_test', $cache->get('string_test')); + $this->assertEquals(11, $cache->get('number_test')); + $array = $cache->get('array_test'); + $this->assertArrayHasKey('array_test', $array); + $this->assertEquals('array_test', $array['array_test']); + + $result = $cache->set('no_expire', 1, 0); + $this->assertTrue($result); + } + + /** + * 测试缓存存在情况,包括测试字符串、整数、数组和对象 + * @return mixed + * @access public + */ + public function testExists() + { + $cache = $this->prepare(); + $this->assertNotEmpty($cache->has('string_test')); + $this->assertNotEmpty($cache->has('number_test')); + $this->assertFalse($cache->has('not_exists')); + } + + /** + * 测试缓存不存在情况,包括测试字符串、整数、数组和对象 + * @return mixed + * @access public + */ + public function testGetNonExistent() + { + $cache = $this->getCacheInstance(); + $this->assertFalse($cache->get('non_existent_key', false)); + } + + /** + * 测试特殊值缓存,包括测试字符串、整数、数组和对象 + * @return mixed + * @access public + */ + public function testStoreSpecialValues() + { + $cache = $this->getCacheInstance(); + $cache->set('null_value', null); + //清空缓存后,返回null而不是false + $this->assertTrue(is_null($cache->get('null_value'))); + } + + /** + * 缓存过期测试 + * @return mixed + * @access public + */ + public function testExpire() + { + $cache = $this->getCacheInstance(); + $this->assertTrue($cache->set('expire_test', 'expire_test', 1)); + usleep(600000); + $this->assertEquals('expire_test', $cache->get('expire_test')); + usleep(800000); + $this->assertFalse($cache->get('expire_test')); + } + + /** + * 删除缓存测试 + * @return mixed + * @access public + */ + public function testDelete() + { + $cache = $this->prepare(); + $this->assertNotNull($cache->rm('number_test')); + $this->assertFalse($cache->get('number_test')); + } + + /** + * 获取并删除缓存测试 + * @return mixed + * @access public + */ + public function testPull() + { + $cache = $this->prepare(); + $this->assertEquals(11, $cache->pull('number_test')); + $this->assertFalse($cache->get('number_test')); + } + + /** + * 清空缓存测试 + * @return mixed + * @access public + */ + public function testClear() + { + $cache = $this->prepare(); + $this->assertTrue($cache->clear()); + $this->assertFalse($cache->get('number_test')); + } + + public function testStaticCall() + { + $this->assertTrue(Cache::set('a', 1)); + $this->assertEquals(1, Cache::get('a')); + $this->assertEquals(2, Cache::inc('a')); + $this->assertEquals(4, Cache::inc('a', 2)); + $this->assertEquals(4, Cache::get('a')); + $this->assertEquals(3, Cache::dec('a')); + $this->assertEquals(1, Cache::dec('a', 2)); + $this->assertEquals(1, Cache::get('a')); + $this->assertNotNull(Cache::rm('a')); + $this->assertNotNull(Cache::clear()); + } + +} diff --git a/tests/thinkphp/library/think/cache/driver/fileTest.php b/tests/thinkphp/library/think/cache/driver/fileTest.php index aee0bd46..eb2099ce 100644 --- a/tests/thinkphp/library/think/cache/driver/fileTest.php +++ b/tests/thinkphp/library/think/cache/driver/fileTest.php @@ -1,46 +1,46 @@ - -// +---------------------------------------------------------------------- - -/** - * File缓存驱动测试 - * @author 刘志淳 - */ - -namespace tests\thinkphp\library\think\cache\driver; - -class fileTest extends cacheTestCase -{ - private $_cacheInstance = null; - - /** - * 基境缓存类型 - */ - protected function setUp() - { - \think\Cache::connect(['type' => 'File', 'path' => CACHE_PATH]); - } - - /** - * @return FileCache - */ - protected function getCacheInstance() - { - if (null === $this->_cacheInstance) { - $this->_cacheInstance = new \think\cache\driver\File(); - } - return $this->_cacheInstance; - } - - // skip testExpire - public function testExpire() - { - } -} + +// +---------------------------------------------------------------------- + +/** + * File缓存驱动测试 + * @author 刘志淳 + */ + +namespace tests\thinkphp\library\think\cache\driver; + +class fileTest extends cacheTestCase +{ + private $_cacheInstance = null; + + /** + * 基境缓存类型 + */ + protected function setUp() + { + \think\Cache::connect(['type' => 'File', 'path' => CACHE_PATH]); + } + + /** + * @return FileCache + */ + protected function getCacheInstance() + { + if (null === $this->_cacheInstance) { + $this->_cacheInstance = new \think\cache\driver\File(); + } + return $this->_cacheInstance; + } + + // skip testExpire + public function testExpire() + { + } +} diff --git a/tests/thinkphp/library/think/cache/driver/liteTest.php b/tests/thinkphp/library/think/cache/driver/liteTest.php index b52bdff9..19cbb9ef 100644 --- a/tests/thinkphp/library/think/cache/driver/liteTest.php +++ b/tests/thinkphp/library/think/cache/driver/liteTest.php @@ -1,69 +1,69 @@ - -// +---------------------------------------------------------------------- - -/** - * Lite缓存驱动测试 - * @author 刘志淳 - */ - -namespace tests\thinkphp\library\think\cache\driver; - -use think\Cache; - -class liteTest extends \PHPUnit_Framework_TestCase -{ - protected function getCacheInstance() - { - return Cache::connect(['type' => 'Lite', 'path' => CACHE_PATH]); - } - - /** - * 测试缓存读取 - * @return mixed - * @access public - */ - public function testGet() - { - $cache = $this->getCacheInstance(); - $this->assertFalse($cache->get('test')); - } - - /** - * 测试缓存设置 - * @return mixed - * @access public - */ - public function testSet() - { - $cache = $this->getCacheInstance(); - $this->assertNotEmpty($cache->set('test', 'test')); - } - - /** - * 删除缓存测试 - * @return mixed - * @access public - */ - public function testRm() - { - $cache = $this->getCacheInstance(); - $this->assertTrue($cache->rm('test')); - } - - /** - * 清空缓存测试 - * @return mixed - * @access public - */ - public function testClear() - { - } -} + +// +---------------------------------------------------------------------- + +/** + * Lite缓存驱动测试 + * @author 刘志淳 + */ + +namespace tests\thinkphp\library\think\cache\driver; + +use think\Cache; + +class liteTest extends \PHPUnit_Framework_TestCase +{ + protected function getCacheInstance() + { + return Cache::connect(['type' => 'Lite', 'path' => CACHE_PATH]); + } + + /** + * 测试缓存读取 + * @return mixed + * @access public + */ + public function testGet() + { + $cache = $this->getCacheInstance(); + $this->assertFalse($cache->get('test')); + } + + /** + * 测试缓存设置 + * @return mixed + * @access public + */ + public function testSet() + { + $cache = $this->getCacheInstance(); + $this->assertNotEmpty($cache->set('test', 'test')); + } + + /** + * 删除缓存测试 + * @return mixed + * @access public + */ + public function testRm() + { + $cache = $this->getCacheInstance(); + $this->assertTrue($cache->rm('test')); + } + + /** + * 清空缓存测试 + * @return mixed + * @access public + */ + public function testClear() + { + } +} diff --git a/tests/thinkphp/library/think/cache/driver/memcacheTest.php b/tests/thinkphp/library/think/cache/driver/memcacheTest.php index 15dfaa5a..8975fa20 100644 --- a/tests/thinkphp/library/think/cache/driver/memcacheTest.php +++ b/tests/thinkphp/library/think/cache/driver/memcacheTest.php @@ -1,49 +1,49 @@ - -// +---------------------------------------------------------------------- - -/** - * Memcache缓存驱动测试 - * @author 刘志淳 - */ - -namespace tests\thinkphp\library\think\cache\driver; - -class memcacheTest extends cacheTestCase -{ - private $_cacheInstance = null; - - /** - * 基境缓存类型 - */ - protected function setUp() - { - if (!extension_loaded('memcache')) { - $this->markTestSkipped("Memcache没有安装,已跳过测试!"); - } - \think\Cache::connect(['type' => 'memcache', 'expire' => 2]); - } - - /** - * @return ApcCache - */ - protected function getCacheInstance() - { - if (null === $this->_cacheInstance) { - $this->_cacheInstance = new \think\cache\driver\Memcache(['length' => 3]); - } - return $this->_cacheInstance; - } - - // skip testExpire - public function testExpire() - { - } -} + +// +---------------------------------------------------------------------- + +/** + * Memcache缓存驱动测试 + * @author 刘志淳 + */ + +namespace tests\thinkphp\library\think\cache\driver; + +class memcacheTest extends cacheTestCase +{ + private $_cacheInstance = null; + + /** + * 基境缓存类型 + */ + protected function setUp() + { + if (!extension_loaded('memcache')) { + $this->markTestSkipped("Memcache没有安装,已跳过测试!"); + } + \think\Cache::connect(['type' => 'memcache', 'expire' => 2]); + } + + /** + * @return ApcCache + */ + protected function getCacheInstance() + { + if (null === $this->_cacheInstance) { + $this->_cacheInstance = new \think\cache\driver\Memcache(['length' => 3]); + } + return $this->_cacheInstance; + } + + // skip testExpire + public function testExpire() + { + } +} diff --git a/tests/thinkphp/library/think/cache/driver/memcachedTest.php b/tests/thinkphp/library/think/cache/driver/memcachedTest.php index 58bcbd88..d528dd22 100644 --- a/tests/thinkphp/library/think/cache/driver/memcachedTest.php +++ b/tests/thinkphp/library/think/cache/driver/memcachedTest.php @@ -1,72 +1,72 @@ - -// +---------------------------------------------------------------------- - -/** - * Memcached缓存驱动测试 - * @author 7IN0SAN9 - */ - -namespace tests\thinkphp\library\think\cache\driver; - -class memcachedTest extends cacheTestCase -{ - private $_cacheInstance = null; - /** - * 基境缓存类型 - */ - protected function setUp() - { - if (!extension_loaded("memcached") && !extension_loaded('memcache')) { - $this->markTestSkipped("Memcached或Memcache没有安装,已跳过测试!"); - } - \think\Cache::connect(array('type' => 'memcached', 'expire' => 2)); - } - /** - * @return ApcCache - */ - protected function getCacheInstance() - { - if (null === $this->_cacheInstance) { - $this->_cacheInstance = new \think\cache\driver\Memcached(['length' => 3]); - } - return $this->_cacheInstance; - } - /** - * 缓存过期测试《提出来测试,因为目前看通不过缓存过期测试,所以还需研究》 - * @return mixed - * @access public - */ - public function testExpire() - { - } - - public function testStaticCall() - { - } - - /** - * 测试缓存自增 - * @return mixed - * @access public - */ - public function testInc() - { - } - - /** - * 测试缓存自减 - * @return mixed - * @access public - */ - public function testDec() - { - } -} + +// +---------------------------------------------------------------------- + +/** + * Memcached缓存驱动测试 + * @author 7IN0SAN9 + */ + +namespace tests\thinkphp\library\think\cache\driver; + +class memcachedTest extends cacheTestCase +{ + private $_cacheInstance = null; + /** + * 基境缓存类型 + */ + protected function setUp() + { + if (!extension_loaded("memcached") && !extension_loaded('memcache')) { + $this->markTestSkipped("Memcached或Memcache没有安装,已跳过测试!"); + } + \think\Cache::connect(array('type' => 'memcached', 'expire' => 2)); + } + /** + * @return ApcCache + */ + protected function getCacheInstance() + { + if (null === $this->_cacheInstance) { + $this->_cacheInstance = new \think\cache\driver\Memcached(['length' => 3]); + } + return $this->_cacheInstance; + } + /** + * 缓存过期测试《提出来测试,因为目前看通不过缓存过期测试,所以还需研究》 + * @return mixed + * @access public + */ + public function testExpire() + { + } + + public function testStaticCall() + { + } + + /** + * 测试缓存自增 + * @return mixed + * @access public + */ + public function testInc() + { + } + + /** + * 测试缓存自减 + * @return mixed + * @access public + */ + public function testDec() + { + } +} diff --git a/tests/thinkphp/library/think/controllerTest.php b/tests/thinkphp/library/think/controllerTest.php index ce5f49a0..fba8d6c5 100644 --- a/tests/thinkphp/library/think/controllerTest.php +++ b/tests/thinkphp/library/think/controllerTest.php @@ -40,13 +40,13 @@ class Foo extends Controller public function fetchTest() { - $template = dirname(__FILE__) . '/display.html'; - return $this->fetch($template, ['name' => 'ThinkPHP']); + $template = dirname(__FILE__) . '/display.html'; + return $this->fetch($template, ['name' => 'ThinkPHP']); } public function displayTest() { - $template = dirname(__FILE__) . '/display.html'; + $template = dirname(__FILE__) . '/display.html'; return $this->display($template, ['name' => 'ThinkPHP']); } public function test() @@ -71,7 +71,7 @@ class Foo extends Controller ['sex', 'in:0,1', '性别只能为为男或女'], ['age', 'between:1,80', '年龄只能在10-80之间'], ]; - return $this->validate($data, $validate); + return $this->validate($data, $validate); } } diff --git a/tests/thinkphp/library/think/dbTest.php b/tests/thinkphp/library/think/dbTest.php index f44b6b6c..4d3d16d5 100644 --- a/tests/thinkphp/library/think/dbTest.php +++ b/tests/thinkphp/library/think/dbTest.php @@ -16,7 +16,7 @@ namespace tests\thinkphp\library\think; -use \think\Db; +use think\Db; class dbTest extends \PHPUnit_Framework_TestCase { @@ -349,5 +349,4 @@ EOF; $this->assertNotEquals($cache, $updateCache); } - } diff --git a/tests/thinkphp/library/think/debugTest.php b/tests/thinkphp/library/think/debugTest.php index 12ff815f..d6424a3d 100644 --- a/tests/thinkphp/library/think/debugTest.php +++ b/tests/thinkphp/library/think/debugTest.php @@ -1,179 +1,179 @@ - -// +---------------------------------------------------------------------- - -/** - * Debug测试 - * @author 大漠 - */ - -namespace tests\thinkphp\library\think; - -use think\Debug; - -class debugTest extends \PHPUnit_Framework_TestCase -{ - - /** - * - * @var Debug - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - $this->object = new Debug(); - } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - {} - - /** - * @covers think\Debug::remark - * @todo Implement testRemark(). - */ - public function testRemark() - { - $name = "testremarkkey"; - Debug::remark($name); - } - - /** - * @covers think\Debug::getRangeTime - * @todo Implement testGetRangeTime(). - */ - public function testGetRangeTime() - { - $start = "testGetRangeTimeStart"; - $end = "testGetRangeTimeEnd"; - Debug::remark($start); - usleep(20000); - // \think\Debug::remark($end); - - $time = Debug::getRangeTime($start, $end); - $this->assertLessThan(0.03, $time); - //$this->assertEquals(0.03, ceil($time)); - } - - /** - * @covers think\Debug::getUseTime - * @todo Implement testGetUseTime(). - */ - public function testGetUseTime() - { - $time = Debug::getUseTime(); - $this->assertLessThan(20, $time); - } - - /** - * @covers think\Debug::getThroughputRate - * @todo Implement testGetThroughputRate(). - */ - public function testGetThroughputRate() - { - usleep(100000); - $throughputRate = Debug::getThroughputRate(); - $this->assertLessThan(10, $throughputRate); - } - - /** - * @covers think\Debug::getRangeMem - * @todo Implement testGetRangeMem(). - */ - public function testGetRangeMem() - { - $start = "testGetRangeMemStart"; - $end = "testGetRangeMemEnd"; - Debug::remark($start); - $str = ""; - for ($i = 0; $i < 10000; $i++) { - $str .= "mem"; - } - - $rangeMem = Debug::getRangeMem($start, $end); - - $this->assertLessThan(33, explode(" ", $rangeMem)[0]); - } - - /** - * @covers think\Debug::getUseMem - * @todo Implement testGetUseMem(). - */ - public function testGetUseMem() - { - $useMem = Debug::getUseMem(); - - $this->assertLessThan(30, explode(" ", $useMem)[0]); - } - - /** - * @covers think\Debug::getMemPeak - * @todo Implement testGetMemPeak(). - */ - public function testGetMemPeak() - { - $start = "testGetMemPeakStart"; - $end = "testGetMemPeakEnd"; - Debug::remark($start); - $str = ""; - for ($i = 0; $i < 100000; $i++) { - $str .= "mem"; - } - $memPeak = Debug::getMemPeak($start, $end); - $this->assertLessThan(500, explode(" ", $memPeak)[0]); - } - - /** - * @covers think\Debug::getFile - * @todo Implement testGetFile(). - */ - public function testGetFile() - { - $count = Debug::getFile(); - - $this->assertEquals(count(get_included_files()), $count); - - $info = Debug::getFile(true); - $this->assertEquals(count(get_included_files()), count($info)); - - $this->assertContains("KB", $info[0]); - } - - /** - * @covers think\Debug::dump - * @todo Implement testDump(). - */ - public function testDump() - { - if (strstr(PHP_VERSION, 'hhvm')) { - return ; - } - - $var = []; - $var["key"] = "val"; - $output = Debug::dump($var, false, $label = "label"); - $array = explode("array", json_encode($output)); - if (IS_WIN) { - $this->assertEquals("(1) {\\n [\\\"key\\\"] => string(3) \\\"val\\\"\\n}\\n\\r\\n\"", end($array)); - } else if (strstr(PHP_OS, 'Darwin')) { - $this->assertEquals("(1) {\\n [\\\"key\\\"] => string(3) \\\"val\\\"\\n}\\n\\n\"", end($array)); - } else { - $this->assertEquals("(1) {\\n 'key' =>\\n string(3) \\\"val\\\"\\n}\\n\\n\"", end($array)); - } - } -} + +// +---------------------------------------------------------------------- + +/** + * Debug测试 + * @author 大漠 + */ + +namespace tests\thinkphp\library\think; + +use think\Debug; + +class debugTest extends \PHPUnit_Framework_TestCase +{ + + /** + * + * @var Debug + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp() + { + $this->object = new Debug(); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + {} + + /** + * @covers think\Debug::remark + * @todo Implement testRemark(). + */ + public function testRemark() + { + $name = "testremarkkey"; + Debug::remark($name); + } + + /** + * @covers think\Debug::getRangeTime + * @todo Implement testGetRangeTime(). + */ + public function testGetRangeTime() + { + $start = "testGetRangeTimeStart"; + $end = "testGetRangeTimeEnd"; + Debug::remark($start); + usleep(20000); + // \think\Debug::remark($end); + + $time = Debug::getRangeTime($start, $end); + $this->assertLessThan(0.03, $time); + //$this->assertEquals(0.03, ceil($time)); + } + + /** + * @covers think\Debug::getUseTime + * @todo Implement testGetUseTime(). + */ + public function testGetUseTime() + { + $time = Debug::getUseTime(); + $this->assertLessThan(20, $time); + } + + /** + * @covers think\Debug::getThroughputRate + * @todo Implement testGetThroughputRate(). + */ + public function testGetThroughputRate() + { + usleep(100000); + $throughputRate = Debug::getThroughputRate(); + $this->assertLessThan(10, $throughputRate); + } + + /** + * @covers think\Debug::getRangeMem + * @todo Implement testGetRangeMem(). + */ + public function testGetRangeMem() + { + $start = "testGetRangeMemStart"; + $end = "testGetRangeMemEnd"; + Debug::remark($start); + $str = ""; + for ($i = 0; $i < 10000; $i++) { + $str .= "mem"; + } + + $rangeMem = Debug::getRangeMem($start, $end); + + $this->assertLessThan(33, explode(" ", $rangeMem)[0]); + } + + /** + * @covers think\Debug::getUseMem + * @todo Implement testGetUseMem(). + */ + public function testGetUseMem() + { + $useMem = Debug::getUseMem(); + + $this->assertLessThan(30, explode(" ", $useMem)[0]); + } + + /** + * @covers think\Debug::getMemPeak + * @todo Implement testGetMemPeak(). + */ + public function testGetMemPeak() + { + $start = "testGetMemPeakStart"; + $end = "testGetMemPeakEnd"; + Debug::remark($start); + $str = ""; + for ($i = 0; $i < 100000; $i++) { + $str .= "mem"; + } + $memPeak = Debug::getMemPeak($start, $end); + $this->assertLessThan(500, explode(" ", $memPeak)[0]); + } + + /** + * @covers think\Debug::getFile + * @todo Implement testGetFile(). + */ + public function testGetFile() + { + $count = Debug::getFile(); + + $this->assertEquals(count(get_included_files()), $count); + + $info = Debug::getFile(true); + $this->assertEquals(count(get_included_files()), count($info)); + + $this->assertContains("KB", $info[0]); + } + + /** + * @covers think\Debug::dump + * @todo Implement testDump(). + */ + public function testDump() + { + if (strstr(PHP_VERSION, 'hhvm')) { + return ; + } + + $var = []; + $var["key"] = "val"; + $output = Debug::dump($var, false, $label = "label"); + $array = explode("array", json_encode($output)); + if (IS_WIN) { + $this->assertEquals("(1) {\\n [\\\"key\\\"] => string(3) \\\"val\\\"\\n}\\n\\r\\n\"", end($array)); + } elseif (strstr(PHP_OS, 'Darwin')) { + $this->assertEquals("(1) {\\n [\\\"key\\\"] => string(3) \\\"val\\\"\\n}\\n\\n\"", end($array)); + } else { + $this->assertEquals("(1) {\\n 'key' =>\\n string(3) \\\"val\\\"\\n}\\n\\n\"", end($array)); + } + } +} diff --git a/tests/thinkphp/library/think/lang/lang.php b/tests/thinkphp/library/think/lang/lang.php index 044b171b..96880b15 100644 --- a/tests/thinkphp/library/think/lang/lang.php +++ b/tests/thinkphp/library/think/lang/lang.php @@ -1,4 +1,4 @@ '加载', -]; \ No newline at end of file +]; diff --git a/tests/thinkphp/library/think/log/driver/fileTest.php b/tests/thinkphp/library/think/log/driver/fileTest.php index 3453c09b..3352e144 100644 --- a/tests/thinkphp/library/think/log/driver/fileTest.php +++ b/tests/thinkphp/library/think/log/driver/fileTest.php @@ -1,34 +1,34 @@ - -// +---------------------------------------------------------------------- - -/** - * Test File Log - */ -namespace tests\thinkphp\library\think\log\driver; - -use think\Log; - -class fileTest extends \PHPUnit_Framework_TestCase -{ - protected function setUp() - { - Log::init(['type' => 'file']); - } - - public function testRecord() - { - $record_msg = 'record'; - Log::record($record_msg, 'notice'); - $logs = Log::getLog(); - - $this->assertNotFalse(array_search($record_msg, $logs['notice'])); - } -} + +// +---------------------------------------------------------------------- + +/** + * Test File Log + */ +namespace tests\thinkphp\library\think\log\driver; + +use think\Log; + +class fileTest extends \PHPUnit_Framework_TestCase +{ + protected function setUp() + { + Log::init(['type' => 'file']); + } + + public function testRecord() + { + $record_msg = 'record'; + Log::record($record_msg, 'notice'); + $logs = Log::getLog(); + + $this->assertNotFalse(array_search($record_msg, $logs['notice'])); + } +} diff --git a/tests/thinkphp/library/think/paginateTest.php b/tests/thinkphp/library/think/paginateTest.php index 5bbcc961..8cd45507 100644 --- a/tests/thinkphp/library/think/paginateTest.php +++ b/tests/thinkphp/library/think/paginateTest.php @@ -11,7 +11,6 @@ namespace tests\thinkphp\library\think; - use think\paginator\driver\Bootstrap; class paginateTest extends \PHPUnit_Framework_TestCase @@ -38,7 +37,4 @@ class paginateTest extends \PHPUnit_Framework_TestCase $this->assertEquals($render, $p->render()); } - - - -} \ No newline at end of file +} diff --git a/tests/thinkphp/library/think/responseTest.php b/tests/thinkphp/library/think/responseTest.php index aa21a4b6..62d15747 100644 --- a/tests/thinkphp/library/think/responseTest.php +++ b/tests/thinkphp/library/think/responseTest.php @@ -1,95 +1,95 @@ - -// +---------------------------------------------------------------------- - -/** - * Response测试 - * @author 大漠 - */ - -namespace tests\thinkphp\library\think; - -use think\Config; -use think\Request; -use think\Response; - -class responseTest extends \PHPUnit_Framework_TestCase -{ - - /** - * - * @var \think\Response - */ - protected $object; - - protected $default_return_type; - - protected $default_ajax_return; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - // 1. - // restore_error_handler(); - // Warning: Cannot modify header information - headers already sent by (output started at PHPUnit\Util\Printer.php:173) - // more see in https://www.analysisandsolutions.com/blog/html/writing-phpunit-tests-for-wordpress-plugins-wp-redirect-and-continuing-after-php-errors.htm - - // 2. - // the Symfony used the HeaderMock.php - - // 3. - // not run the eclipse will held, and travis-ci.org Searching for coverage reports - // **> Python coverage not found - // **> No coverage report found. - // add the - // /** - // * @runInSeparateProcess - // */ - if (!$this->default_return_type) { - $this->default_return_type = Config::get('default_return_type'); - } - if (!$this->default_ajax_return) { - $this->default_ajax_return = Config::get('default_ajax_return'); - } - } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - Config::set('default_ajax_return', $this->default_ajax_return); - Config::set('default_return_type', $this->default_return_type); - } - - /** - * @covers think\Response::send - * @todo Implement testSend(). - */ - public function testSend() - { - $dataArr = []; - $dataArr["key"] = "value"; - - $response = Response::create($dataArr, 'json'); - $result = $response->getContent(); - $this->assertEquals('{"key":"value"}', $result); - $request = Request::instance(); - $request->get(['callback' => 'callback']); - $response = Response::create($dataArr, 'jsonp'); - $result = $response->getContent(); - $this->assertEquals('callback({"key":"value"});', $result); - } - -} + +// +---------------------------------------------------------------------- + +/** + * Response测试 + * @author 大漠 + */ + +namespace tests\thinkphp\library\think; + +use think\Config; +use think\Request; +use think\Response; + +class responseTest extends \PHPUnit_Framework_TestCase +{ + + /** + * + * @var \think\Response + */ + protected $object; + + protected $default_return_type; + + protected $default_ajax_return; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp() + { + // 1. + // restore_error_handler(); + // Warning: Cannot modify header information - headers already sent by (output started at PHPUnit\Util\Printer.php:173) + // more see in https://www.analysisandsolutions.com/blog/html/writing-phpunit-tests-for-wordpress-plugins-wp-redirect-and-continuing-after-php-errors.htm + + // 2. + // the Symfony used the HeaderMock.php + + // 3. + // not run the eclipse will held, and travis-ci.org Searching for coverage reports + // **> Python coverage not found + // **> No coverage report found. + // add the + // /** + // * @runInSeparateProcess + // */ + if (!$this->default_return_type) { + $this->default_return_type = Config::get('default_return_type'); + } + if (!$this->default_ajax_return) { + $this->default_ajax_return = Config::get('default_ajax_return'); + } + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + Config::set('default_ajax_return', $this->default_ajax_return); + Config::set('default_return_type', $this->default_return_type); + } + + /** + * @covers think\Response::send + * @todo Implement testSend(). + */ + public function testSend() + { + $dataArr = []; + $dataArr["key"] = "value"; + + $response = Response::create($dataArr, 'json'); + $result = $response->getContent(); + $this->assertEquals('{"key":"value"}', $result); + $request = Request::instance(); + $request->get(['callback' => 'callback']); + $response = Response::create($dataArr, 'jsonp'); + $result = $response->getContent(); + $this->assertEquals('callback({"key":"value"});', $result); + } + +} diff --git a/tests/thinkphp/library/think/sessionTest.php b/tests/thinkphp/library/think/sessionTest.php index ab3e64f4..5fd95f10 100644 --- a/tests/thinkphp/library/think/sessionTest.php +++ b/tests/thinkphp/library/think/sessionTest.php @@ -1,319 +1,319 @@ - -// +---------------------------------------------------------------------- - -/** - * Session测试 - * @author 大漠 - */ - -namespace tests\thinkphp\library\think; - -use think\Session; - -class sessionTest extends \PHPUnit_Framework_TestCase -{ - - /** - * - * @var \think\Session - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - // $this->object = new Session (); - // register_shutdown_function ( function () { - // } ); // 此功能无法取消,需要回调函数配合。 - set_exception_handler(function () {}); - set_error_handler(function () {}); - } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - register_shutdown_function('think\Error::appShutdown'); - set_error_handler('think\Error::appError'); - set_exception_handler('think\Error::appException'); - } - - /** - * @covers think\Session::prefix - * - * @todo Implement testPrefix(). - */ - public function testPrefix() - { - Session::prefix(null); - Session::prefix('think_'); - - $this->assertEquals('think_', Session::prefix()); - } - - /** - * @covers think\Session::init - * - * @todo Implement testInit(). - */ - public function testInit() - { - Session::prefix(null); - $config = [ - // cookie 名称前缀 - 'prefix' => 'think_', - // cookie 保存时间 - 'expire' => 60, - // cookie 保存路径 - 'path' => '/path/to/test/session/', - // cookie 有效域名 - 'domain' => '.thinkphp.cn', - 'var_session_id' => 'sessionidtest', - 'id' => 'sess_8fhgkjuakhatbeg2fa14lo84q1', - 'name' => 'session_name', - 'use_trans_sid' => '1', - 'use_cookies' => '1', - 'cache_limiter' => '60', - 'cache_expire' => '60', - 'type' => '', // memcache - 'namespace' => '\\think\\session\\driver\\', // ? - 'auto_start' => '1', - ]; - - $_REQUEST[$config['var_session_id']] = $config['id']; - Session::init($config); - - // 开始断言 - $this->assertEquals($config['prefix'], Session::prefix()); - $this->assertEquals($config['id'], $_REQUEST[$config['var_session_id']]); - $this->assertEquals($config['name'], session_name()); - - $this->assertEquals($config['path'], session_save_path()); - $this->assertEquals($config['use_cookies'], ini_get('session.use_cookies')); - $this->assertEquals($config['domain'], ini_get('session.cookie_domain')); - $this->assertEquals($config['expire'], ini_get('session.gc_maxlifetime')); - $this->assertEquals($config['expire'], ini_get('session.cookie_lifetime')); - - $this->assertEquals($config['cache_limiter'], session_cache_limiter($config['cache_limiter'])); - $this->assertEquals($config['cache_expire'], session_cache_expire($config['cache_expire'])); - - // 检测分支 - $_REQUEST[$config['var_session_id']] = null; - session_write_close(); - session_destroy(); - - Session::init($config); - - // 测试auto_start - // PHP_SESSION_DISABLED - // PHP_SESSION_NONE - // PHP_SESSION_ACTIVE - // session_status() - if (strstr(PHP_VERSION, 'hhvm')) { - $this->assertEquals('', ini_get('session.auto_start')); - } else { - $this->assertEquals(0, ini_get('session.auto_start')); - } - - $this->assertEquals($config['use_trans_sid'], ini_get('session.use_trans_sid')); - - Session::init($config); - $this->assertEquals($config['id'], session_id()); - } - - /** - * 单独重现异常 - * @expectedException \think\Exception - */ - public function testException() - { - $config = [ - // cookie 名称前缀 - 'prefix' => 'think_', - // cookie 保存时间 - 'expire' => 0, - // cookie 保存路径 - 'path' => '/path/to/test/session/', - // cookie 有效域名 - 'domain' => '.thinkphp.cn', - 'var_session_id' => 'sessionidtest', - 'id' => 'sess_8fhgkjuakhatbeg2fa14lo84q1', - 'name' => 'session_name', - 'use_trans_sid' => '1', - 'use_cookies' => '1', - 'cache_limiter' => '60', - 'cache_expire' => '60', - 'type' => '\\think\\session\\driver\\Memcache', // - 'auto_start' => '1', - ]; - - // 测试session驱动是否存在 - // @expectedException 异常类名 - $this->setExpectedException('\think\exception\ClassNotFoundException', 'error session handler'); - - Session::init($config); - } - - /** - * @covers think\Session::set - * - * @todo Implement testSet(). - */ - public function testSet() - { - Session::prefix(null); - Session::set('sessionname', 'sessionvalue'); - $this->assertEquals('sessionvalue', $_SESSION['sessionname']); - - Session::set('sessionnamearr.subname', 'sessionvalue'); - $this->assertEquals('sessionvalue', $_SESSION['sessionnamearr']['subname']); - - Session::set('sessionnameper', 'sessionvalue', 'think_'); - $this->assertEquals('sessionvalue', $_SESSION['think_']['sessionnameper']); - - Session::set('sessionnamearrper.subname', 'sessionvalue', 'think_'); - $this->assertEquals('sessionvalue', $_SESSION['think_']['sessionnamearrper']['subname']); - } - - /** - * @covers think\Session::get - * - * @todo Implement testGet(). - */ - public function testGet() - { - Session::prefix(null); - - Session::set('sessionnameget', 'sessionvalue'); - $this->assertEquals(Session::get('sessionnameget'), $_SESSION['sessionnameget']); - - Session::set('sessionnamegetarr.subname', 'sessionvalue'); - $this->assertEquals(Session::get('sessionnamegetarr.subname'), $_SESSION['sessionnamegetarr']['subname']); - - Session::set('sessionnamegetarrperall', 'sessionvalue', 'think_'); - $this->assertEquals(Session::get('', 'think_')['sessionnamegetarrperall'], $_SESSION['think_']['sessionnamegetarrperall']); - - Session::set('sessionnamegetper', 'sessionvalue', 'think_'); - $this->assertEquals(Session::get('sessionnamegetper', 'think_'), $_SESSION['think_']['sessionnamegetper']); - - Session::set('sessionnamegetarrper.subname', 'sessionvalue', 'think_'); - $this->assertEquals(Session::get('sessionnamegetarrper.subname', 'think_'), $_SESSION['think_']['sessionnamegetarrper']['subname']); - } - - public function testPull() - { - Session::prefix(null); - Session::set('sessionnamedel', 'sessionvalue'); - $this->assertEquals('sessionvalue', Session::pull('sessionnameget')); - $this->assertNull(Session::get('sessionnameget')); - } - - /** - * @covers think\Session::delete - * - * @todo Implement testDelete(). - */ - public function testDelete() - { - Session::prefix(null); - Session::set('sessionnamedel', 'sessionvalue'); - Session::delete('sessionnamedel'); - $this->assertEmpty($_SESSION['sessionnamedel']); - - Session::set('sessionnamedelarr.subname', 'sessionvalue'); - Session::delete('sessionnamedelarr.subname'); - $this->assertEmpty($_SESSION['sessionnamedelarr']['subname']); - - Session::set('sessionnamedelper', 'sessionvalue', 'think_'); - Session::delete('sessionnamedelper', 'think_'); - $this->assertEmpty($_SESSION['think_']['sessionnamedelper']); - - Session::set('sessionnamedelperarr.subname', 'sessionvalue', 'think_'); - Session::delete('sessionnamedelperarr.subname', 'think_'); - $this->assertEmpty($_SESSION['think_']['sessionnamedelperarr']['subname']); - } - - /** - * @covers think\Session::clear - * - * @todo Implement testClear(). - */ - public function testClear() - { - Session::prefix(null); - - Session::set('sessionnameclsper', 'sessionvalue1', 'think_'); - Session::clear('think_'); - $this->assertNull($_SESSION['think_']); - - Session::set('sessionnameclsper', 'sessionvalue1', 'think_'); - Session::clear(); - $this->assertEmpty($_SESSION); - } - - /** - * @covers think\Session::has - * - * @todo Implement testHas(). - */ - public function testHas() - { - Session::prefix(null); - Session::set('sessionnamehas', 'sessionvalue'); - $this->assertTrue(Session::has('sessionnamehas')); - - Session::set('sessionnamehasarr.subname', 'sessionvalue'); - $this->assertTrue(Session::has('sessionnamehasarr.subname')); - - Session::set('sessionnamehasper', 'sessionvalue', 'think_'); - $this->assertTrue(Session::has('sessionnamehasper', 'think_')); - - Session::set('sessionnamehasarrper.subname', 'sessionvalue', 'think_'); - $this->assertTrue(Session::has('sessionnamehasarrper.subname', 'think_')); - } - - /** - * @covers think\Session::pause - * - * @todo Implement testPause(). - */ - public function testPause() - { - Session::pause(); - } - - /** - * @covers think\Session::start - * - * @todo Implement testStart(). - */ - public function testStart() - { - Session::start(); - } - - /** - * @covers think\Session::destroy - * - * @todo Implement testDestroy(). - */ - public function testDestroy() - { - Session::set('sessionnamedestroy', 'sessionvalue'); - Session::destroy(); - $this->assertEmpty($_SESSION['sessionnamedestroy']); - } -} + +// +---------------------------------------------------------------------- + +/** + * Session测试 + * @author 大漠 + */ + +namespace tests\thinkphp\library\think; + +use think\Session; + +class sessionTest extends \PHPUnit_Framework_TestCase +{ + + /** + * + * @var \think\Session + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp() + { + // $this->object = new Session (); + // register_shutdown_function ( function () { + // } ); // 此功能无法取消,需要回调函数配合。 + set_exception_handler(function () {}); + set_error_handler(function () {}); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + register_shutdown_function('think\Error::appShutdown'); + set_error_handler('think\Error::appError'); + set_exception_handler('think\Error::appException'); + } + + /** + * @covers think\Session::prefix + * + * @todo Implement testPrefix(). + */ + public function testPrefix() + { + Session::prefix(null); + Session::prefix('think_'); + + $this->assertEquals('think_', Session::prefix()); + } + + /** + * @covers think\Session::init + * + * @todo Implement testInit(). + */ + public function testInit() + { + Session::prefix(null); + $config = [ + // cookie 名称前缀 + 'prefix' => 'think_', + // cookie 保存时间 + 'expire' => 60, + // cookie 保存路径 + 'path' => '/path/to/test/session/', + // cookie 有效域名 + 'domain' => '.thinkphp.cn', + 'var_session_id' => 'sessionidtest', + 'id' => 'sess_8fhgkjuakhatbeg2fa14lo84q1', + 'name' => 'session_name', + 'use_trans_sid' => '1', + 'use_cookies' => '1', + 'cache_limiter' => '60', + 'cache_expire' => '60', + 'type' => '', // memcache + 'namespace' => '\\think\\session\\driver\\', // ? + 'auto_start' => '1', + ]; + + $_REQUEST[$config['var_session_id']] = $config['id']; + Session::init($config); + + // 开始断言 + $this->assertEquals($config['prefix'], Session::prefix()); + $this->assertEquals($config['id'], $_REQUEST[$config['var_session_id']]); + $this->assertEquals($config['name'], session_name()); + + $this->assertEquals($config['path'], session_save_path()); + $this->assertEquals($config['use_cookies'], ini_get('session.use_cookies')); + $this->assertEquals($config['domain'], ini_get('session.cookie_domain')); + $this->assertEquals($config['expire'], ini_get('session.gc_maxlifetime')); + $this->assertEquals($config['expire'], ini_get('session.cookie_lifetime')); + + $this->assertEquals($config['cache_limiter'], session_cache_limiter($config['cache_limiter'])); + $this->assertEquals($config['cache_expire'], session_cache_expire($config['cache_expire'])); + + // 检测分支 + $_REQUEST[$config['var_session_id']] = null; + session_write_close(); + session_destroy(); + + Session::init($config); + + // 测试auto_start + // PHP_SESSION_DISABLED + // PHP_SESSION_NONE + // PHP_SESSION_ACTIVE + // session_status() + if (strstr(PHP_VERSION, 'hhvm')) { + $this->assertEquals('', ini_get('session.auto_start')); + } else { + $this->assertEquals(0, ini_get('session.auto_start')); + } + + $this->assertEquals($config['use_trans_sid'], ini_get('session.use_trans_sid')); + + Session::init($config); + $this->assertEquals($config['id'], session_id()); + } + + /** + * 单独重现异常 + * @expectedException \think\Exception + */ + public function testException() + { + $config = [ + // cookie 名称前缀 + 'prefix' => 'think_', + // cookie 保存时间 + 'expire' => 0, + // cookie 保存路径 + 'path' => '/path/to/test/session/', + // cookie 有效域名 + 'domain' => '.thinkphp.cn', + 'var_session_id' => 'sessionidtest', + 'id' => 'sess_8fhgkjuakhatbeg2fa14lo84q1', + 'name' => 'session_name', + 'use_trans_sid' => '1', + 'use_cookies' => '1', + 'cache_limiter' => '60', + 'cache_expire' => '60', + 'type' => '\\think\\session\\driver\\Memcache', // + 'auto_start' => '1', + ]; + + // 测试session驱动是否存在 + // @expectedException 异常类名 + $this->setExpectedException('\think\exception\ClassNotFoundException', 'error session handler'); + + Session::init($config); + } + + /** + * @covers think\Session::set + * + * @todo Implement testSet(). + */ + public function testSet() + { + Session::prefix(null); + Session::set('sessionname', 'sessionvalue'); + $this->assertEquals('sessionvalue', $_SESSION['sessionname']); + + Session::set('sessionnamearr.subname', 'sessionvalue'); + $this->assertEquals('sessionvalue', $_SESSION['sessionnamearr']['subname']); + + Session::set('sessionnameper', 'sessionvalue', 'think_'); + $this->assertEquals('sessionvalue', $_SESSION['think_']['sessionnameper']); + + Session::set('sessionnamearrper.subname', 'sessionvalue', 'think_'); + $this->assertEquals('sessionvalue', $_SESSION['think_']['sessionnamearrper']['subname']); + } + + /** + * @covers think\Session::get + * + * @todo Implement testGet(). + */ + public function testGet() + { + Session::prefix(null); + + Session::set('sessionnameget', 'sessionvalue'); + $this->assertEquals(Session::get('sessionnameget'), $_SESSION['sessionnameget']); + + Session::set('sessionnamegetarr.subname', 'sessionvalue'); + $this->assertEquals(Session::get('sessionnamegetarr.subname'), $_SESSION['sessionnamegetarr']['subname']); + + Session::set('sessionnamegetarrperall', 'sessionvalue', 'think_'); + $this->assertEquals(Session::get('', 'think_')['sessionnamegetarrperall'], $_SESSION['think_']['sessionnamegetarrperall']); + + Session::set('sessionnamegetper', 'sessionvalue', 'think_'); + $this->assertEquals(Session::get('sessionnamegetper', 'think_'), $_SESSION['think_']['sessionnamegetper']); + + Session::set('sessionnamegetarrper.subname', 'sessionvalue', 'think_'); + $this->assertEquals(Session::get('sessionnamegetarrper.subname', 'think_'), $_SESSION['think_']['sessionnamegetarrper']['subname']); + } + + public function testPull() + { + Session::prefix(null); + Session::set('sessionnamedel', 'sessionvalue'); + $this->assertEquals('sessionvalue', Session::pull('sessionnameget')); + $this->assertNull(Session::get('sessionnameget')); + } + + /** + * @covers think\Session::delete + * + * @todo Implement testDelete(). + */ + public function testDelete() + { + Session::prefix(null); + Session::set('sessionnamedel', 'sessionvalue'); + Session::delete('sessionnamedel'); + $this->assertEmpty($_SESSION['sessionnamedel']); + + Session::set('sessionnamedelarr.subname', 'sessionvalue'); + Session::delete('sessionnamedelarr.subname'); + $this->assertEmpty($_SESSION['sessionnamedelarr']['subname']); + + Session::set('sessionnamedelper', 'sessionvalue', 'think_'); + Session::delete('sessionnamedelper', 'think_'); + $this->assertEmpty($_SESSION['think_']['sessionnamedelper']); + + Session::set('sessionnamedelperarr.subname', 'sessionvalue', 'think_'); + Session::delete('sessionnamedelperarr.subname', 'think_'); + $this->assertEmpty($_SESSION['think_']['sessionnamedelperarr']['subname']); + } + + /** + * @covers think\Session::clear + * + * @todo Implement testClear(). + */ + public function testClear() + { + Session::prefix(null); + + Session::set('sessionnameclsper', 'sessionvalue1', 'think_'); + Session::clear('think_'); + $this->assertNull($_SESSION['think_']); + + Session::set('sessionnameclsper', 'sessionvalue1', 'think_'); + Session::clear(); + $this->assertEmpty($_SESSION); + } + + /** + * @covers think\Session::has + * + * @todo Implement testHas(). + */ + public function testHas() + { + Session::prefix(null); + Session::set('sessionnamehas', 'sessionvalue'); + $this->assertTrue(Session::has('sessionnamehas')); + + Session::set('sessionnamehasarr.subname', 'sessionvalue'); + $this->assertTrue(Session::has('sessionnamehasarr.subname')); + + Session::set('sessionnamehasper', 'sessionvalue', 'think_'); + $this->assertTrue(Session::has('sessionnamehasper', 'think_')); + + Session::set('sessionnamehasarrper.subname', 'sessionvalue', 'think_'); + $this->assertTrue(Session::has('sessionnamehasarrper.subname', 'think_')); + } + + /** + * @covers think\Session::pause + * + * @todo Implement testPause(). + */ + public function testPause() + { + Session::pause(); + } + + /** + * @covers think\Session::start + * + * @todo Implement testStart(). + */ + public function testStart() + { + Session::start(); + } + + /** + * @covers think\Session::destroy + * + * @todo Implement testDestroy(). + */ + public function testDestroy() + { + Session::set('sessionnamedestroy', 'sessionvalue'); + Session::destroy(); + $this->assertEmpty($_SESSION['sessionnamedestroy']); + } +} diff --git a/tests/thinkphp/library/think/template/taglib/cxTest.php b/tests/thinkphp/library/think/template/taglib/cxTest.php index a77824b6..c1c67413 100644 --- a/tests/thinkphp/library/think/template/taglib/cxTest.php +++ b/tests/thinkphp/library/think/template/taglib/cxTest.php @@ -19,7 +19,7 @@ namespace tests\thinkphp\library\think\tempplate\taglib; use think\Template; use think\template\taglib\Cx; -class templateTest extends \PHPUnit_Framework_TestCase +class cxTest extends \PHPUnit_Framework_TestCase { public function testPhp() { diff --git a/tests/thinkphp/library/think/viewTest.php b/tests/thinkphp/library/think/viewTest.php index 56804798..5bb7de16 100644 --- a/tests/thinkphp/library/think/viewTest.php +++ b/tests/thinkphp/library/think/viewTest.php @@ -1,76 +1,76 @@ - -// +---------------------------------------------------------------------- - -/** - * view测试 - * @author mahuan - */ - -namespace tests\thinkphp\library\think; - -class viewTest extends \PHPUnit_Framework_TestCase -{ - - /** - * 句柄测试 - * @return mixed - * @access public - */ - public function testGetInstance() - { - \think\Cookie::get('a'); - $view_instance = \think\View::instance(); - $this->assertInstanceOf('\think\view', $view_instance, 'instance方法返回错误'); - } - - /** - * 测试变量赋值 - * @return mixed - * @access public - */ - public function testAssign() - { - $view_instance = \think\View::instance(); - $view_instance->key = 'value'; - $this->assertTrue(isset($view_instance->key)); - $this->assertEquals('value', $view_instance->key); - $data = $view_instance->assign(array('key' => 'value')); - $data = $view_instance->assign('key2', 'value2'); - //测试私有属性 - $expect_data = array('key' => 'value', 'key2' => 'value2'); - $this->assertAttributeEquals($expect_data, 'data', $view_instance); - } - - /** - * 测试引擎设置 - * @return mixed - * @access public - */ - public function testEngine() - { - $view_instance = \think\View::instance(); - $data = $view_instance->engine('php'); - $data = $view_instance->engine(['type' => 'php', 'view_path' => '', 'view_suffix' => '.php', 'view_depr' => DS]); - $php_engine = new \think\view\driver\Php(['view_path' => '', 'view_suffix' => '.php', 'view_depr' => DS]); - $this->assertAttributeEquals($php_engine, 'engine', $view_instance); - //测试模板引擎驱动 - $data = $view_instance->engine(['type' => 'think', 'view_path' => '', 'view_suffix' => '.html', 'view_depr' => DS]); - $think_engine = new \think\view\driver\Think(['view_path' => '', 'view_suffix' => '.html', 'view_depr' => DS]); - $this->assertAttributeEquals($think_engine, 'engine', $view_instance); - } - - public function testReplace() - { - $view_instance = \think\View::instance(); - $view_instance->replace('string', 'replace')->display('string'); - } - -} + +// +---------------------------------------------------------------------- + +/** + * view测试 + * @author mahuan + */ + +namespace tests\thinkphp\library\think; + +class viewTest extends \PHPUnit_Framework_TestCase +{ + + /** + * 句柄测试 + * @return mixed + * @access public + */ + public function testGetInstance() + { + \think\Cookie::get('a'); + $view_instance = \think\View::instance(); + $this->assertInstanceOf('\think\view', $view_instance, 'instance方法返回错误'); + } + + /** + * 测试变量赋值 + * @return mixed + * @access public + */ + public function testAssign() + { + $view_instance = \think\View::instance(); + $view_instance->key = 'value'; + $this->assertTrue(isset($view_instance->key)); + $this->assertEquals('value', $view_instance->key); + $data = $view_instance->assign(array('key' => 'value')); + $data = $view_instance->assign('key2', 'value2'); + //测试私有属性 + $expect_data = array('key' => 'value', 'key2' => 'value2'); + $this->assertAttributeEquals($expect_data, 'data', $view_instance); + } + + /** + * 测试引擎设置 + * @return mixed + * @access public + */ + public function testEngine() + { + $view_instance = \think\View::instance(); + $data = $view_instance->engine('php'); + $data = $view_instance->engine(['type' => 'php', 'view_path' => '', 'view_suffix' => '.php', 'view_depr' => DS]); + $php_engine = new \think\view\driver\Php(['view_path' => '', 'view_suffix' => '.php', 'view_depr' => DS]); + $this->assertAttributeEquals($php_engine, 'engine', $view_instance); + //测试模板引擎驱动 + $data = $view_instance->engine(['type' => 'think', 'view_path' => '', 'view_suffix' => '.html', 'view_depr' => DS]); + $think_engine = new \think\view\driver\Think(['view_path' => '', 'view_suffix' => '.html', 'view_depr' => DS]); + $this->assertAttributeEquals($think_engine, 'engine', $view_instance); + } + + public function testReplace() + { + $view_instance = \think\View::instance(); + $view_instance->replace('string', 'replace')->display('string'); + } + +} -- Gitee From 463cdcf874c259fdc6c6b9b47c4cc9fc630785b6 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 24 Dec 2016 22:10:30 +0800 Subject: [PATCH 0325/1170] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convention.php | 44 ++++++++++++++++++++------------- library/think/db/Connection.php | 2 +- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/convention.php b/convention.php index 487c2481..a35ac0b9 100644 --- a/convention.php +++ b/convention.php @@ -231,39 +231,49 @@ return [ 'database' => [ // 数据库类型 - 'type' => 'mysql', + 'type' => 'mysql', // 数据库连接DSN配置 - 'dsn' => '', + 'dsn' => '', // 服务器地址 - 'hostname' => 'localhost', + 'hostname' => '127.0.0.1', // 数据库名 - 'database' => '', + 'database' => '', // 数据库用户名 - 'username' => 'root', + 'username' => 'root', // 数据库密码 - 'password' => '', + 'password' => '', // 数据库连接端口 - 'hostport' => '', + 'hostport' => '', // 数据库连接参数 - 'params' => [], + 'params' => [], // 数据库编码默认采用utf8 - 'charset' => 'utf8', + 'charset' => 'utf8', // 数据库表前缀 - 'prefix' => '', + 'prefix' => '', // 数据库调试模式 - 'debug' => false, + 'debug' => false, // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) - 'deploy' => 0, + 'deploy' => 0, // 数据库读写是否分离 主从式有效 - 'rw_separate' => false, + 'rw_separate' => false, // 读写分离后 主服务器数量 - 'master_num' => 1, + 'master_num' => 1, // 指定从服务器序号 - 'slave_no' => '', + 'slave_no' => '', // 是否严格检查字段是否存在 - 'fields_strict' => true, + 'fields_strict' => true, + // 数据集返回类型 + 'resultset_type' => 'array', // 自动写入时间戳字段 - 'auto_timestamp' => false, + 'auto_timestamp' => false, + // 时间字段取出后的默认时间格式 + 'datetime_format' => 'Y-m-d H:i:s', + // 是否需要进行SQL性能分析 + 'sql_explain' => false, + // Builder类 + 'builder' => '', + // Query类 + 'query' => '\\think\\db\\Query', ], //分页配置 diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index 3b6d92c8..765af588 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -99,7 +99,7 @@ abstract class Connection 'resultset_type' => 'array', // 自动写入时间戳字段 'auto_timestamp' => false, - // 时间戳格式 + // 时间字段取出后的默认时间格式 'datetime_format' => 'Y-m-d H:i:s', // 是否需要进行SQL性能分析 'sql_explain' => false, -- Gitee From 1788025df7f83b55187a668c582eb6338f80ef3b Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 25 Dec 2016 09:28:45 +0800 Subject: [PATCH 0326/1170] =?UTF-8?q?Cache=E7=B1=BB=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Cache.php | 8 +++++--- library/think/Db.php | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/library/think/Cache.php b/library/think/Cache.php index 372da705..7e1b98a9 100644 --- a/library/think/Cache.php +++ b/library/think/Cache.php @@ -11,6 +11,8 @@ namespace think; +use think\cache\Driver; + class Cache { protected static $instance = []; @@ -29,7 +31,7 @@ class Cache * @access public * @param array $options 配置数组 * @param bool|string $name 缓存连接标识 true 强制重新连接 - * @return \think\cache\Driver + * @return Driver */ public static function connect(array $options = [], $name = false) { @@ -77,7 +79,7 @@ class Cache * 切换缓存类型 需要配置 cache.type 为 complex * @access public * @param string $name 缓存标识 - * @return \think\cache\Driver + * @return Driver */ public static function store($name) { @@ -218,7 +220,7 @@ class Cache * @param string $name 标签名 * @param string|array $keys 缓存标识 * @param bool $overlay 是否覆盖 - * @return \think\cache\Driver + * @return Driver */ public static function tag($name, $keys = null, $overlay = false) { diff --git a/library/think/Db.php b/library/think/Db.php index 4998469f..99df4366 100644 --- a/library/think/Db.php +++ b/library/think/Db.php @@ -11,6 +11,7 @@ namespace think; +use think\db\Connection; use think\db\Query; use think\paginator\Collection as PaginatorCollection; @@ -60,7 +61,7 @@ class Db * @access public * @param mixed $config 连接配置 * @param bool|string $name 连接标识 true 强制重新连接 - * @return \think\db\Connection + * @return Connection * @throws Exception */ public static function connect($config = [], $name = false) -- Gitee From 2e51ccbc5ef2ab72a5f397dc8d52590dd6762edd Mon Sep 17 00:00:00 2001 From: 7IN0SAN9 Date: Sun, 25 Dec 2016 15:38:41 +0800 Subject: [PATCH 0327/1170] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20StyleCI=20?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 65db2b9e..d81d68c8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ ThinkPHP 5.0 =============== +[![StyleCI](https://styleci.io/repos/48530411/shield?style=flat&branch=master)](https://styleci.io/repos/48530411) [![Build Status](https://travis-ci.org/top-think/framework.svg?branch=master)](https://travis-ci.org/top-think/framework) [![codecov.io](http://codecov.io/github/top-think/framework/coverage.svg?branch=master)](http://codecov.io/github/github/top-think/framework?branch=master) [![Total Downloads](https://poser.pugx.org/topthink/framework/downloads)](https://packagist.org/packages/topthink/framework) -- Gitee From bfcc08cdeb73b0080593fd5cf48ade6a765888ad Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 26 Dec 2016 12:28:03 +0800 Subject: [PATCH 0328/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Model=E7=B1=BB?= =?UTF-8?q?=E4=B8=80=E5=A4=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Model.php b/library/think/Model.php index 71fbfc69..7c31dc5e 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -333,7 +333,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess } elseif (is_string($this->autoWriteTimestamp) && in_array(strtolower($this->autoWriteTimestamp), ['datetime', 'date', 'timestamp'])) { $value = $this->formatDateTime($_SERVER['REQUEST_TIME'], $this->dateFormat); } else { - $value = $this->formatDateTime($value, $this->dateFormat, true); + $value = $this->formatDateTime($_SERVER['REQUEST_TIME'], $this->dateFormat, true); } return $value; } -- Gitee From a74b842d71f6e607d37fb676c16f8f6d9b3d1af6 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 26 Dec 2016 15:52:53 +0800 Subject: [PATCH 0329/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=85=B3=E8=81=94?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 22 +++++++++++++++++-- .../think/model/relation/BelongsToMany.php | 11 ++++++++++ library/think/model/relation/HasMany.php | 15 +++++++++++++ library/think/model/relation/MorphMany.php | 15 +++++++++++++ 4 files changed, 61 insertions(+), 2 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 6daa6f67..cd7a093b 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1675,11 +1675,29 @@ class Query * 关联统计 * @access public * @param string|array $relation 关联方法名 + * @param bool $subQuery 是否使用子查询 * @return $this */ - public function withCount($relation) + public function withCount($relation, $subQuery = false) { - $this->options['with_count'] = $relation; + if (!$subQuery) { + $this->options['with_count'] = $relation; + } else { + $relations = is_string($relation) ? explode(',', $relation) : $relation; + if (!isset($this->options['field'])) { + $this->field('*'); + } + foreach ($relations as $key => $relation) { + $closure = false; + if ($relation instanceof \Closure) { + $closure = $relation; + $relation = $key; + } + $relation = Loader::parseName($relation, 1, false); + $count = '(' . (new $this->model)->$relation()->getRelationCountQuery($closure) . ')'; + $this->field([$count => Loader::parseName($relation) . '_count']); + } + } return $this; } diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index 37d07eec..e1849d89 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -161,6 +161,17 @@ class BelongsToMany extends Relation return $count; } + /** + * 获取关联统计子查询 + * @access public + * @param \Closure $closure 闭包 + * @return string + */ + public function getRelationCountQuery($closure) + { + return $this->belongsToManyQuery($this->middle, $this->foreignKey, $this->localKey, ['pivot.' . $this->localKey => ['exp', '=' . $this->parent->getTable() . '.' . $this->parent->getPk()]])->fetchSql()->count(); + } + /** * 多对多 关联模型预查询 * @access public diff --git a/library/think/model/relation/HasMany.php b/library/think/model/relation/HasMany.php index f6455d6b..e5690137 100644 --- a/library/think/model/relation/HasMany.php +++ b/library/think/model/relation/HasMany.php @@ -130,6 +130,21 @@ class HasMany extends Relation return $count; } + /** + * 创建关联统计子查询 + * @access public + * @param \Closure $closure 闭包 + * @return string + */ + public function getRelationCountQuery($closure) + { + if ($closure) { + call_user_func_array($closure, [ & $this->query]); + } + + return $this->query->where([$this->foreignKey => ['exp', '=' . $this->parent->getTable() . '.' . $this->parent->getPk()]])->fetchSql()->count(); + } + /** * 一对多 关联模型预查询 * @access public diff --git a/library/think/model/relation/MorphMany.php b/library/think/model/relation/MorphMany.php index 44c344cd..d76052ed 100644 --- a/library/think/model/relation/MorphMany.php +++ b/library/think/model/relation/MorphMany.php @@ -133,6 +133,21 @@ class MorphMany extends Relation return $count; } + /** + * 获取关联统计子查询 + * @access public + * @param \Closure $closure 闭包 + * @return string + */ + public function getRelationCountQuery($closure) + { + if ($closure) { + call_user_func_array($closure, [ & $this->query]); + } + + return $this->query->where([$this->morphKey => ['exp', '=' . $this->parent->getTable() . '.' . $this->parent->getPk()], $this->morphType => $this->type])->fetchSql()->count(); + } + /** * 多态一对多 关联模型预查询 * @access public -- Gitee From 5128ad407bbb36e342a59a377f9e012fb4bc31ea Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 26 Dec 2016 15:58:16 +0800 Subject: [PATCH 0330/1170] =?UTF-8?q?withCount=E6=96=B9=E6=B3=95=E7=9A=84?= =?UTF-8?q?=E7=AC=AC=E4=BA=8C=E4=B8=AA=E5=8F=82=E6=95=B0=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E4=B8=BAtrue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index cd7a093b..2f37c000 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1678,7 +1678,7 @@ class Query * @param bool $subQuery 是否使用子查询 * @return $this */ - public function withCount($relation, $subQuery = false) + public function withCount($relation, $subQuery = true) { if (!$subQuery) { $this->options['with_count'] = $relation; -- Gitee From 7bb3e5561c16f6f7d44baed6f59d0b0a12fea7d7 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 26 Dec 2016 22:55:38 +0800 Subject: [PATCH 0331/1170] =?UTF-8?q?=E4=BC=98=E5=8C=96Connection=E7=B1=BB?= =?UTF-8?q?=5F=5Fcall=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Connection.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index 765af588..3ab285dc 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -155,11 +155,8 @@ abstract class Connection */ public function __call($method, $args) { - if (!isset($this->query['database'])) { - $class = $this->config['query']; - $this->query['database'] = new $class($this); - } - return call_user_func_array([$this->query['database'], $method], $args); + $query = $this->model('datebase'); + return call_user_func_array([$query, $method], $args); } /** -- Gitee From 0fd725967906a97743e2574de5e7e2573dd31544 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 26 Dec 2016 23:06:20 +0800 Subject: [PATCH 0332/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Connection.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index 3ab285dc..7392cc1d 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -137,11 +137,11 @@ abstract class Connection * @param string $queryClass 查询对象类名 * @return Query */ - public function model($model, $queryClass = '') + public function model($model = 'db', $queryClass = '') { if (!isset($this->query[$model])) { $class = $queryClass ?: $this->config['query']; - $this->query[$model] = new $class($this, $model); + $this->query[$model] = new $class($this, 'db' == $model ? '' : $model); } return $this->query[$model]; } @@ -155,8 +155,7 @@ abstract class Connection */ public function __call($method, $args) { - $query = $this->model('datebase'); - return call_user_func_array([$query, $method], $args); + return call_user_func_array([$this->model(), $method], $args); } /** -- Gitee From c20c27bcb829203ab157a4bbd060b2ca776f4003 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 27 Dec 2016 08:15:57 +0800 Subject: [PATCH 0333/1170] =?UTF-8?q?Connection=E7=B1=BBmodel=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E6=9B=B4=E6=94=B9=E4=B8=BAgetQuery?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 2 +- library/think/db/Connection.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 7c31dc5e..605d48d3 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -178,7 +178,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $connection = []; } // 设置当前模型 确保查询返回模型对象 - $query = Db::connect($connection)->model($model, $this->query); + $query = Db::connect($connection)->getQuery($model, $this->query); // 设置当前数据表和模型名 if (!empty($this->table)) { diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index 7392cc1d..e5c60aae 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -137,7 +137,7 @@ abstract class Connection * @param string $queryClass 查询对象类名 * @return Query */ - public function model($model = 'db', $queryClass = '') + public function getQuery($model = 'db', $queryClass = '') { if (!isset($this->query[$model])) { $class = $queryClass ?: $this->config['query']; @@ -155,7 +155,7 @@ abstract class Connection */ public function __call($method, $args) { - return call_user_func_array([$this->model(), $method], $args); + return call_user_func_array([$this->getQuery(), $method], $args); } /** -- Gitee From 7a26126a9bd83bae802d311b940245d64b9187dd Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 27 Dec 2016 10:23:22 +0800 Subject: [PATCH 0334/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=E7=B1=BB=E5=9E=8B=20=E6=94=AF=E6=8C=81bit?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E8=87=AA=E5=8A=A8=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 2f37c000..7bc75c3d 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1556,7 +1556,7 @@ class Query */ protected function getFieldBindType($type) { - if (preg_match('/(int|double|float|decimal|real|numeric|serial)/is', $type)) { + if (preg_match('/(int|double|float|decimal|real|numeric|serial|bit)/is', $type)) { $bind = PDO::PARAM_INT; } elseif (preg_match('/bool/is', $type)) { $bind = PDO::PARAM_BOOL; -- Gitee From d89fb4bd0a97bf778884cc02d71c36584572aca0 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 27 Dec 2016 13:43:31 +0800 Subject: [PATCH 0335/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BBuilder=E7=B1=BB?= =?UTF-8?q?=E7=9A=84insertall=E6=96=B9=E6=B3=95=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=AF=B9null=E5=92=8C=E5=AF=B9=E8=B1=A1=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=9A=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Builder.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index fb315057..24ff06ff 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -702,8 +702,13 @@ abstract class Builder throw new Exception('fields not exists:[' . $key . ']'); } unset($data[$key]); + } elseif (is_null($val)) { + $data[$key] = 'NULL'; } elseif (is_scalar($val)) { $data[$key] = $this->parseValue($val, $key); + } elseif (is_object($val) && method_exists($val, '__toString')) { + // 对象数据写入 + $data[$key] = $val->__toString(); } else { // 过滤掉非标量数据 unset($data[$key]); -- Gitee From d409477b42e507adc8eb246a19a739ac59bb5bbe Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 27 Dec 2016 15:49:01 +0800 Subject: [PATCH 0336/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=E6=94=AF=E6=8C=81=E4=B8=AD=E6=96=87=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E8=87=AA=E5=8A=A8=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Builder.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index 24ff06ff..51b7a871 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -317,6 +317,11 @@ abstract class Builder } } $bindName = $bindName ?: 'where_' . str_replace('.', '_', $field); + if (preg_match('/\W/', $bindName)) { + // 处理带非单词字符的字段名 + $bindName = md5($bindName); + } + $bindType = isset($binds[$field]) ? $binds[$field] : PDO::PARAM_STR; if (is_scalar($value) && array_key_exists($field, $binds) && !in_array($exp, ['EXP', 'NOT NULL', 'NULL', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN']) && strpos($exp, 'TIME') === false) { if (strpos($value, ':') !== 0 || !$this->query->isBind(substr($value, 1))) { -- Gitee From b0237b766db590d0d834868bd08a9ba8b4a212a6 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 28 Dec 2016 11:37:50 +0800 Subject: [PATCH 0337/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=85=B3=E8=81=94?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E4=B8=AD=E5=8C=85=E5=90=AB=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E5=90=8E=E9=87=8D=E5=A4=8D=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 8 +++++--- library/think/model/Relation.php | 11 +++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 7bc75c3d..c4fd0dc1 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1005,9 +1005,11 @@ class Query * @param string $option 参数名 * @return $this */ - public function removeOption($option) + public function removeOption($option = '') { - if (isset($this->options[$option])) { + if ('' === $option) { + $this->options = []; + } elseif (isset($this->options[$option])) { unset($this->options[$option]); } return $this; @@ -1658,7 +1660,7 @@ class Query /** @var Relation $model */ $relation = Loader::parseName($relation, 1, false); - $model = $class->$relation(); + $model = $class->$relation()->removeOption(); if ($model instanceof OneToOne && 0 == $model->getEagerlyType()) { $model->eagerly($this, $relation, $subRelation, $closure, $first); $first = false; diff --git a/library/think/model/Relation.php b/library/think/model/Relation.php index 4fc68ff2..9766ce2e 100644 --- a/library/think/model/Relation.php +++ b/library/think/model/Relation.php @@ -92,6 +92,17 @@ abstract class Relation return $this; } + /** + * 移除关联查询参数 + * @access public + * @return $this + */ + public function removeOption() + { + $this->query->removeOption(); + return $this; + } + public function __call($method, $args) { if ($this->query) { -- Gitee From 28844c12b0434104b0da25fb54da9ce37b5ee133 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 28 Dec 2016 14:21:19 +0800 Subject: [PATCH 0338/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=85=B3=E8=81=94?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E7=9A=84=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Model.php b/library/think/Model.php index 605d48d3..85b4cedd 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -439,7 +439,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $value = $this->readTransform($value, $this->type[$name]); } elseif ($notFound) { $method = Loader::parseName($name, 1, false); - if (method_exists($this, $method) && $this->$method() instanceof Relation) { + if (method_exists($this, $method) && $this->$method()->removeOption() instanceof Relation) { // 不存在该字段 获取关联数据 $value = $this->$method()->getRelation(); // 保存关联对象值 -- Gitee From 293dce863993c12f8922d55756472a6fc4fad375 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 28 Dec 2016 14:58:43 +0800 Subject: [PATCH 0339/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 4 +++- library/think/db/Query.php | 12 ++++++------ library/think/model/relation/OneToOne.php | 1 + 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 85b4cedd..2fa51f0f 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -439,7 +439,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $value = $this->readTransform($value, $this->type[$name]); } elseif ($notFound) { $method = Loader::parseName($name, 1, false); - if (method_exists($this, $method) && $this->$method()->removeOption() instanceof Relation) { + if (method_exists($this, $method) && $this->$method() instanceof Relation) { + // 清空之前的查询参数 + $this->$method()->removeOption(); // 不存在该字段 获取关联数据 $value = $this->$method()->getRelation(); // 保存关联对象值 diff --git a/library/think/db/Query.php b/library/think/db/Query.php index c4fd0dc1..af09a975 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1000,16 +1000,16 @@ class Query } /** - * 去除某个查询参数 + * 去除查询参数 * @access public - * @param string $option 参数名 + * @param string|bool $option 参数名 true 表示去除所有参数 * @return $this */ - public function removeOption($option = '') + public function removeOption($option = true) { - if ('' === $option) { + if (true === $option) { $this->options = []; - } elseif (isset($this->options[$option])) { + } elseif (is_string($option) && isset($this->options[$option])) { unset($this->options[$option]); } return $this; @@ -1660,7 +1660,7 @@ class Query /** @var Relation $model */ $relation = Loader::parseName($relation, 1, false); - $model = $class->$relation()->removeOption(); + $model = $class->$relation(); if ($model instanceof OneToOne && 0 == $model->getEagerlyType()) { $model->eagerly($this, $relation, $subRelation, $closure, $first); $first = false; diff --git a/library/think/model/relation/OneToOne.php b/library/think/model/relation/OneToOne.php index 0f22898b..7b989ef9 100644 --- a/library/think/model/relation/OneToOne.php +++ b/library/think/model/relation/OneToOne.php @@ -160,6 +160,7 @@ abstract class OneToOne extends Relation */ public function getEagerlyType() { + $this->removeOption(); return $this->eagerlyType; } -- Gitee From e4c0e406cfa17df5b4c6bd5ed2dfba1f0f0e0149 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 28 Dec 2016 17:52:38 +0800 Subject: [PATCH 0340/1170] =?UTF-8?q?exp=E6=9F=A5=E8=AF=A2=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=BC=A0=E5=85=A5=E7=BB=91=E5=AE=9A=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index af09a975..f1ad2fb7 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -957,6 +957,10 @@ class Query $where[$field] = ['eq', $op]; } else { $where[$field] = [$op, $condition]; + if ('exp' == strtolower($op) && isset($param[2]) && is_array($param[2])) { + // 参数绑定 + $this->bind($param[2]); + } // 记录一个字段多次查询条件 $this->options['multi'][$field][] = $where[$field]; } -- Gitee From c4686695bc9ecb550b2cfc0e509665774310038e Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 29 Dec 2016 10:18:10 +0800 Subject: [PATCH 0341/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BRequest=E7=B1=BB?= =?UTF-8?q?=E7=9A=84input=E5=92=8Cpost=E6=96=B9=E6=B3=95=E5=AF=B9json?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8F=82=E6=95=B0=E7=9A=84=E6=8E=A5=E6=94=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/think/Request.php b/library/think/Request.php index a806dd87..b8bcb512 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -688,7 +688,7 @@ class Request { if (empty($this->post)) { $content = $this->input; - if (empty($_POST) && strpos($content, '":')) { + if (empty($_POST) && 'json' == $this->type()) { $this->post = (array) json_decode($content, true); } else { $this->post = $_POST; @@ -713,7 +713,7 @@ class Request { if (is_null($this->put)) { $content = $this->input; - if (strpos($content, '":')) { + if ('json' == $this->type()) { $this->put = (array) json_decode($content, true); } else { parse_str($content, $this->put); -- Gitee From dd384422a7b33aee6d738046b8ce1da2bc5364a0 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 29 Dec 2016 12:05:58 +0800 Subject: [PATCH 0342/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/library/think/Request.php b/library/think/Request.php index b8bcb512..bbc635a6 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -688,7 +688,7 @@ class Request { if (empty($this->post)) { $content = $this->input; - if (empty($_POST) && 'json' == $this->type()) { + if (empty($_POST) && 'application/json' == $this->contentType()) { $this->post = (array) json_decode($content, true); } else { $this->post = $_POST; @@ -713,7 +713,7 @@ class Request { if (is_null($this->put)) { $content = $this->input; - if ('json' == $this->type()) { + if ('application/json' == $this->contentType()) { $this->put = (array) json_decode($content, true); } else { parse_str($content, $this->put); @@ -1348,6 +1348,21 @@ class Request return $this->server('REMOTE_PORT'); } + /** + * 当前请求 HTTP_CONTENT_TYPE + * @access public + * @return string + */ + public function contentType() + { + $contentType = $this->server('HTTP_CONTENT_TYPE'); + if ($contentType) { + list($type) = explode(';', $contentType); + return trim($type); + } + return ''; + } + /** * 获取当前请求的路由信息 * @access public -- Gitee From 465b2326a35526692e5c8051db026482571ec98c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 29 Dec 2016 18:07:29 +0800 Subject: [PATCH 0343/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BRoute=E7=9A=84?= =?UTF-8?q?=E5=90=8E=E7=BC=80=E9=99=90=E5=88=B6=E6=9D=A1=E4=BB=B6=E6=A3=80?= =?UTF-8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index 7a31659a..5fa3b1ed 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1126,8 +1126,8 @@ class Route || (isset($option['ajax']) && !$option['ajax'] && $request->isAjax()) // 非Ajax检测 || (isset($option['pjax']) && $option['pjax'] && !$request->isPjax()) // Pjax检测 || (isset($option['pjax']) && !$option['pjax'] && $request->isPjax()) // 非Pjax检测 - || (isset($option['ext']) && false === stripos($option['ext'], $request->ext())) // 伪静态后缀检测 - || (isset($option['deny_ext']) && false !== stripos($option['deny_ext'], $request->ext())) + || (isset($option['ext']) && false === stripos($option['ext'] . '|', $request->ext() . '|')) // 伪静态后缀检测 + || (isset($option['deny_ext']) && false !== stripos($option['deny_ext'] . '|', $request->ext() . '|')) || (isset($option['domain']) && !in_array($option['domain'], [$_SERVER['HTTP_HOST'], self::$subDomain])) // 域名检测 || (isset($option['https']) && $option['https'] && !$request->isSsl()) // https检测 || (isset($option['https']) && !$option['https'] && $request->isSsl()) // https检测 -- Gitee From e7895d259383b6c83fb2a72298bf81c7ce3a279f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 29 Dec 2016 22:33:25 +0800 Subject: [PATCH 0344/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Request=E7=B1=BBcon?= =?UTF-8?q?tentType=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Request.php b/library/think/Request.php index bbc635a6..790c2475 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -1355,7 +1355,7 @@ class Request */ public function contentType() { - $contentType = $this->server('HTTP_CONTENT_TYPE'); + $contentType = $this->server('CONTENT_TYPE'); if ($contentType) { list($type) = explode(';', $contentType); return trim($type); -- Gitee From d6b9e2f628ce0f055783264b12dddabaee695bf7 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 1 Jan 2017 13:00:23 +0800 Subject: [PATCH 0345/1170] =?UTF-8?q?2017=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base.php | 2 +- helper.php | 2 +- lang/zh-cn.php | 2 +- library/think/App.php | 2 +- library/think/Build.php | 2 +- library/think/Cache.php | 2 +- library/think/Collection.php | 2 +- library/think/Config.php | 2 +- library/think/Controller.php | 2 +- library/think/Cookie.php | 2 +- library/think/Db.php | 2 +- library/think/Debug.php | 2 +- library/think/Env.php | 2 +- library/think/Error.php | 2 +- library/think/Exception.php | 2 +- library/think/File.php | 2 +- library/think/Hook.php | 2 +- library/think/Lang.php | 2 +- library/think/Loader.php | 2 +- library/think/Log.php | 2 +- library/think/Model.php | 2 +- library/think/Paginator.php | 2 +- library/think/Request.php | 2 +- library/think/Response.php | 2 +- library/think/Route.php | 2 +- library/think/Session.php | 2 +- library/think/Template.php | 2 +- library/think/Url.php | 2 +- library/think/Validate.php | 2 +- library/think/View.php | 2 +- library/think/cache/Driver.php | 2 +- library/think/cache/driver/File.php | 2 +- library/think/cache/driver/Lite.php | 2 +- library/think/cache/driver/Memcache.php | 2 +- library/think/cache/driver/Memcached.php | 2 +- library/think/cache/driver/Redis.php | 2 +- library/think/cache/driver/Sqlite.php | 2 +- library/think/cache/driver/Wincache.php | 2 +- library/think/cache/driver/Xcache.php | 2 +- library/think/config/driver/Ini.php | 2 +- library/think/config/driver/Json.php | 2 +- library/think/config/driver/Xml.php | 2 +- library/think/controller/Rest.php | 2 +- library/think/db/Builder.php | 2 +- library/think/db/Connection.php | 2 +- library/think/db/Query.php | 2 +- library/think/db/builder/Mysql.php | 2 +- library/think/db/builder/Pgsql.php | 2 +- library/think/db/builder/Sqlite.php | 2 +- library/think/db/connector/Mysql.php | 2 +- library/think/db/connector/Pgsql.php | 2 +- library/think/db/connector/Sqlite.php | 2 +- library/think/db/exception/BindParamException.php | 2 +- library/think/db/exception/DataNotFoundException.php | 2 +- library/think/db/exception/ModelNotFoundException.php | 2 +- library/think/exception/DbException.php | 2 +- library/think/exception/ErrorException.php | 2 +- library/think/exception/PDOException.php | 2 +- library/think/model/Merge.php | 2 +- library/think/model/Pivot.php | 2 +- library/think/model/Relation.php | 2 +- library/think/model/relation/BelongsTo.php | 2 +- library/think/model/relation/BelongsToMany.php | 2 +- library/think/model/relation/HasMany.php | 2 +- library/think/model/relation/HasManyThrough.php | 2 +- library/think/model/relation/HasOne.php | 2 +- library/think/model/relation/MorphMany.php | 2 +- library/think/model/relation/MorphTo.php | 2 +- library/think/model/relation/OneToOne.php | 2 +- library/think/paginator/Collection.php | 2 +- library/think/paginator/driver/Bootstrap.php | 2 +- library/think/response/Json.php | 2 +- library/think/response/Jsonp.php | 2 +- library/think/response/Redirect.php | 2 +- library/think/response/View.php | 2 +- library/think/response/Xml.php | 2 +- library/think/session/driver/Memcache.php | 2 +- library/think/session/driver/Memcached.php | 2 +- library/think/session/driver/Redis.php | 2 +- library/think/template/TagLib.php | 2 +- library/think/template/driver/File.php | 2 +- library/think/view/driver/Php.php | 2 +- library/think/view/driver/Think.php | 2 +- library/traits/think/Instance.php | 2 +- start.php | 2 +- 85 files changed, 85 insertions(+), 85 deletions(-) diff --git a/base.php b/base.php index 85ac946b..fdbd5d90 100644 --- a/base.php +++ b/base.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/helper.php b/helper.php index 02d8761a..83dbddda 100644 --- a/helper.php +++ b/helper.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/lang/zh-cn.php b/lang/zh-cn.php index b3fef357..6d33b0ce 100644 --- a/lang/zh-cn.php +++ b/lang/zh-cn.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/App.php b/library/think/App.php index a7e1ddfa..77721112 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/Build.php b/library/think/Build.php index dd2bd550..13b7bfdc 100644 --- a/library/think/Build.php +++ b/library/think/Build.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/Cache.php b/library/think/Cache.php index 7e1b98a9..12107091 100644 --- a/library/think/Cache.php +++ b/library/think/Cache.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/Collection.php b/library/think/Collection.php index cf2888d5..41b42759 100644 --- a/library/think/Collection.php +++ b/library/think/Collection.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/Config.php b/library/think/Config.php index fb5340d8..fc6c50ac 100644 --- a/library/think/Config.php +++ b/library/think/Config.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/Controller.php b/library/think/Controller.php index e9d6829b..69db0a1d 100644 --- a/library/think/Controller.php +++ b/library/think/Controller.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/Cookie.php b/library/think/Cookie.php index f1c2426a..93edb8d7 100644 --- a/library/think/Cookie.php +++ b/library/think/Cookie.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/Db.php b/library/think/Db.php index 99df4366..a29dac3e 100644 --- a/library/think/Db.php +++ b/library/think/Db.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/Debug.php b/library/think/Debug.php index 0b5d022d..844dfb89 100644 --- a/library/think/Debug.php +++ b/library/think/Debug.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/Env.php b/library/think/Env.php index a23d9925..6f31841d 100644 --- a/library/think/Env.php +++ b/library/think/Env.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/Error.php b/library/think/Error.php index 28f75882..c17292bf 100644 --- a/library/think/Error.php +++ b/library/think/Error.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/Exception.php b/library/think/Exception.php index ac648764..034c85b6 100644 --- a/library/think/Exception.php +++ b/library/think/Exception.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/File.php b/library/think/File.php index 60a16417..ba59273f 100644 --- a/library/think/File.php +++ b/library/think/File.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/Hook.php b/library/think/Hook.php index 4559cd30..f06196e4 100644 --- a/library/think/Hook.php +++ b/library/think/Hook.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/Lang.php b/library/think/Lang.php index 551481f1..d52f1947 100644 --- a/library/think/Lang.php +++ b/library/think/Lang.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/Loader.php b/library/think/Loader.php index effd3f4a..70de3175 100644 --- a/library/think/Loader.php +++ b/library/think/Loader.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/Log.php b/library/think/Log.php index 413e2761..4a8b0b40 100644 --- a/library/think/Log.php +++ b/library/think/Log.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/Model.php b/library/think/Model.php index 2fa51f0f..76bc2d36 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/Paginator.php b/library/think/Paginator.php index dc4cdeeb..d2fe79d2 100644 --- a/library/think/Paginator.php +++ b/library/think/Paginator.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/Request.php b/library/think/Request.php index 790c2475..b72a5aaf 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/Response.php b/library/think/Response.php index 8b107589..656198f0 100644 --- a/library/think/Response.php +++ b/library/think/Response.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/Route.php b/library/think/Route.php index 5fa3b1ed..b5f29c25 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/Session.php b/library/think/Session.php index 06adcff6..48f23caa 100644 --- a/library/think/Session.php +++ b/library/think/Session.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/Template.php b/library/think/Template.php index 072cc80c..66ba9e18 100644 --- a/library/think/Template.php +++ b/library/think/Template.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/Url.php b/library/think/Url.php index a1bc8d2a..51c846d7 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/Validate.php b/library/think/Validate.php index 528861b4..03f19017 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/View.php b/library/think/View.php index 1be47f4e..020e5789 100644 --- a/library/think/View.php +++ b/library/think/View.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/cache/Driver.php b/library/think/cache/Driver.php index f21da7bf..688507a8 100644 --- a/library/think/cache/Driver.php +++ b/library/think/cache/Driver.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/cache/driver/File.php b/library/think/cache/driver/File.php index 5c98d799..6f52693b 100644 --- a/library/think/cache/driver/File.php +++ b/library/think/cache/driver/File.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/cache/driver/Lite.php b/library/think/cache/driver/Lite.php index b9d10097..57727651 100644 --- a/library/think/cache/driver/Lite.php +++ b/library/think/cache/driver/Lite.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/cache/driver/Memcache.php b/library/think/cache/driver/Memcache.php index ca2f8aa8..d41939d8 100644 --- a/library/think/cache/driver/Memcache.php +++ b/library/think/cache/driver/Memcache.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/cache/driver/Memcached.php b/library/think/cache/driver/Memcached.php index 4c4505b0..35fafd07 100644 --- a/library/think/cache/driver/Memcached.php +++ b/library/think/cache/driver/Memcached.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/cache/driver/Redis.php b/library/think/cache/driver/Redis.php index e7f78762..360f515a 100644 --- a/library/think/cache/driver/Redis.php +++ b/library/think/cache/driver/Redis.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/cache/driver/Sqlite.php b/library/think/cache/driver/Sqlite.php index 907f93df..76c592d8 100644 --- a/library/think/cache/driver/Sqlite.php +++ b/library/think/cache/driver/Sqlite.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/cache/driver/Wincache.php b/library/think/cache/driver/Wincache.php index 11d059e4..5be8d0df 100644 --- a/library/think/cache/driver/Wincache.php +++ b/library/think/cache/driver/Wincache.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/cache/driver/Xcache.php b/library/think/cache/driver/Xcache.php index e790ef7c..317a4ee3 100644 --- a/library/think/cache/driver/Xcache.php +++ b/library/think/cache/driver/Xcache.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/config/driver/Ini.php b/library/think/config/driver/Ini.php index d8dc558d..a223a578 100644 --- a/library/think/config/driver/Ini.php +++ b/library/think/config/driver/Ini.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/config/driver/Json.php b/library/think/config/driver/Json.php index ec2419f9..557f75fe 100644 --- a/library/think/config/driver/Json.php +++ b/library/think/config/driver/Json.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/config/driver/Xml.php b/library/think/config/driver/Xml.php index 5bc93015..b573a562 100644 --- a/library/think/config/driver/Xml.php +++ b/library/think/config/driver/Xml.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/controller/Rest.php b/library/think/controller/Rest.php index a75cfd37..c297f4eb 100644 --- a/library/think/controller/Rest.php +++ b/library/think/controller/Rest.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index 51b7a871..29b5688a 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index e5c60aae..b43a1ddb 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/db/Query.php b/library/think/db/Query.php index f1ad2fb7..9b30d3ed 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/db/builder/Mysql.php b/library/think/db/builder/Mysql.php index a3e223ed..de38fac5 100644 --- a/library/think/db/builder/Mysql.php +++ b/library/think/db/builder/Mysql.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/db/builder/Pgsql.php b/library/think/db/builder/Pgsql.php index e6e7dffa..8b853a2f 100644 --- a/library/think/db/builder/Pgsql.php +++ b/library/think/db/builder/Pgsql.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/db/builder/Sqlite.php b/library/think/db/builder/Sqlite.php index c9f55027..02d1bf2e 100644 --- a/library/think/db/builder/Sqlite.php +++ b/library/think/db/builder/Sqlite.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/db/connector/Mysql.php b/library/think/db/connector/Mysql.php index 47b069fb..fd6f4ece 100644 --- a/library/think/db/connector/Mysql.php +++ b/library/think/db/connector/Mysql.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/db/connector/Pgsql.php b/library/think/db/connector/Pgsql.php index e9866cf3..4f8756ca 100644 --- a/library/think/db/connector/Pgsql.php +++ b/library/think/db/connector/Pgsql.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/db/connector/Sqlite.php b/library/think/db/connector/Sqlite.php index 95b023e5..4a08c740 100644 --- a/library/think/db/connector/Sqlite.php +++ b/library/think/db/connector/Sqlite.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/db/exception/BindParamException.php b/library/think/db/exception/BindParamException.php index 3872e7c0..d0e2387b 100644 --- a/library/think/db/exception/BindParamException.php +++ b/library/think/db/exception/BindParamException.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/db/exception/DataNotFoundException.php b/library/think/db/exception/DataNotFoundException.php index cd4253ab..e399b063 100644 --- a/library/think/db/exception/DataNotFoundException.php +++ b/library/think/db/exception/DataNotFoundException.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/db/exception/ModelNotFoundException.php b/library/think/db/exception/ModelNotFoundException.php index 1d4724a6..2180ab07 100644 --- a/library/think/db/exception/ModelNotFoundException.php +++ b/library/think/db/exception/ModelNotFoundException.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/exception/DbException.php b/library/think/exception/DbException.php index bd6fb442..656d6913 100644 --- a/library/think/exception/DbException.php +++ b/library/think/exception/DbException.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/exception/ErrorException.php b/library/think/exception/ErrorException.php index 2f1525c0..e3f18375 100644 --- a/library/think/exception/ErrorException.php +++ b/library/think/exception/ErrorException.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/exception/PDOException.php b/library/think/exception/PDOException.php index 1d88e9f6..ebd53dff 100644 --- a/library/think/exception/PDOException.php +++ b/library/think/exception/PDOException.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/model/Merge.php b/library/think/model/Merge.php index 5edb2a45..b876c2f3 100644 --- a/library/think/model/Merge.php +++ b/library/think/model/Merge.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/model/Pivot.php b/library/think/model/Pivot.php index 24034b07..7823370c 100644 --- a/library/think/model/Pivot.php +++ b/library/think/model/Pivot.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/model/Relation.php b/library/think/model/Relation.php index 9766ce2e..e940a78d 100644 --- a/library/think/model/Relation.php +++ b/library/think/model/Relation.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/model/relation/BelongsTo.php b/library/think/model/relation/BelongsTo.php index 0f1f0c73..8f26d033 100644 --- a/library/think/model/relation/BelongsTo.php +++ b/library/think/model/relation/BelongsTo.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index e1849d89..bbab3714 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/model/relation/HasMany.php b/library/think/model/relation/HasMany.php index e5690137..c9235bac 100644 --- a/library/think/model/relation/HasMany.php +++ b/library/think/model/relation/HasMany.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/model/relation/HasManyThrough.php b/library/think/model/relation/HasManyThrough.php index 79a822f3..2585f354 100644 --- a/library/think/model/relation/HasManyThrough.php +++ b/library/think/model/relation/HasManyThrough.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/model/relation/HasOne.php b/library/think/model/relation/HasOne.php index 4ac1a589..41667e2a 100644 --- a/library/think/model/relation/HasOne.php +++ b/library/think/model/relation/HasOne.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/model/relation/MorphMany.php b/library/think/model/relation/MorphMany.php index d76052ed..abb32ebd 100644 --- a/library/think/model/relation/MorphMany.php +++ b/library/think/model/relation/MorphMany.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/model/relation/MorphTo.php b/library/think/model/relation/MorphTo.php index fa691489..e6676574 100644 --- a/library/think/model/relation/MorphTo.php +++ b/library/think/model/relation/MorphTo.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/model/relation/OneToOne.php b/library/think/model/relation/OneToOne.php index 7b989ef9..ef21bee0 100644 --- a/library/think/model/relation/OneToOne.php +++ b/library/think/model/relation/OneToOne.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/paginator/Collection.php b/library/think/paginator/Collection.php index 50803ba8..0c877388 100644 --- a/library/think/paginator/Collection.php +++ b/library/think/paginator/Collection.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/paginator/driver/Bootstrap.php b/library/think/paginator/driver/Bootstrap.php index 13b7bccd..58fa9436 100644 --- a/library/think/paginator/driver/Bootstrap.php +++ b/library/think/paginator/driver/Bootstrap.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/response/Json.php b/library/think/response/Json.php index 027aa2a3..538fc5a0 100644 --- a/library/think/response/Json.php +++ b/library/think/response/Json.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/response/Jsonp.php b/library/think/response/Jsonp.php index b92aa9f6..de8fb304 100644 --- a/library/think/response/Jsonp.php +++ b/library/think/response/Jsonp.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/response/Redirect.php b/library/think/response/Redirect.php index a3104c2f..f2002779 100644 --- a/library/think/response/Redirect.php +++ b/library/think/response/Redirect.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/response/View.php b/library/think/response/View.php index 3a5f3660..de75515a 100644 --- a/library/think/response/View.php +++ b/library/think/response/View.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/response/Xml.php b/library/think/response/Xml.php index 3a2c59bd..ca12e295 100644 --- a/library/think/response/Xml.php +++ b/library/think/response/Xml.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/session/driver/Memcache.php b/library/think/session/driver/Memcache.php index 78320864..0c02e23e 100644 --- a/library/think/session/driver/Memcache.php +++ b/library/think/session/driver/Memcache.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/session/driver/Memcached.php b/library/think/session/driver/Memcached.php index c5df23dc..bcaf8a1b 100644 --- a/library/think/session/driver/Memcached.php +++ b/library/think/session/driver/Memcached.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/session/driver/Redis.php b/library/think/session/driver/Redis.php index b1632f9e..a4c2b54a 100644 --- a/library/think/session/driver/Redis.php +++ b/library/think/session/driver/Redis.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/template/TagLib.php b/library/think/template/TagLib.php index 101593bf..b3325191 100644 --- a/library/think/template/TagLib.php +++ b/library/think/template/TagLib.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/template/driver/File.php b/library/think/template/driver/File.php index 1cd041af..b27e7265 100644 --- a/library/think/template/driver/File.php +++ b/library/think/template/driver/File.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/view/driver/Php.php b/library/think/view/driver/Php.php index b7028c2d..468d3611 100644 --- a/library/think/view/driver/Php.php +++ b/library/think/view/driver/Php.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/think/view/driver/Think.php b/library/think/view/driver/Think.php index e5336b41..39a14ca3 100644 --- a/library/think/view/driver/Think.php +++ b/library/think/view/driver/Think.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/library/traits/think/Instance.php b/library/traits/think/Instance.php index 4dd005e4..ba45ddd8 100644 --- a/library/traits/think/Instance.php +++ b/library/traits/think/Instance.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- diff --git a/start.php b/start.php index 2d517914..8af62ef3 100644 --- a/start.php +++ b/start.php @@ -2,7 +2,7 @@ // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- -// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved. +// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- -- Gitee From 0e3bfbe06c60fe5d19ed76cc1b5c4c870c776c94 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 2 Jan 2017 20:39:20 +0800 Subject: [PATCH 0346/1170] =?UTF-8?q?=E4=BC=98=E5=8C=96Connection=E7=9A=84?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Connection.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index b43a1ddb..ef56c6fd 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -337,7 +337,7 @@ abstract class Connection $this->queryStr = $this->getRealSql($sql, $bind); //释放前次的查询结果 - if (!empty($this->PDOStatement)) { + if (!empty($this->PDOStatement) && $this->PDOStatement->queryString != $sql) { $this->free(); } @@ -346,11 +346,13 @@ abstract class Connection // 调试开始 $this->debug(true); // 预处理 - $this->PDOStatement = $this->linkID->prepare($sql); + if (empty($this->PDOStatement)) { + $this->PDOStatement = $this->linkID->prepare($sql); + } // 参数绑定 $this->bindValue($bind); // 执行查询 - $result = $this->PDOStatement->execute(); + $this->PDOStatement->execute(); // 调试结束 $this->debug(false); $procedure = in_array(strtolower(substr(trim($sql), 0, 4)), ['call', 'exec']); @@ -379,7 +381,7 @@ abstract class Connection $this->queryStr = $this->getRealSql($sql, $bind); //释放前次的查询结果 - if (!empty($this->PDOStatement)) { + if (!empty($this->PDOStatement) && $this->PDOStatement->queryString != $sql) { $this->free(); } @@ -388,11 +390,13 @@ abstract class Connection // 调试开始 $this->debug(true); // 预处理 - $this->PDOStatement = $this->linkID->prepare($sql); + if (empty($this->PDOStatement)) { + $this->PDOStatement = $this->linkID->prepare($sql); + } // 参数绑定操作 $this->bindValue($bind); // 执行语句 - $result = $this->PDOStatement->execute(); + $this->PDOStatement->execute(); // 调试结束 $this->debug(false); -- Gitee From 24c928f3e232c283385e8c2cd3c156cb18807b51 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 3 Jan 2017 08:16:44 +0800 Subject: [PATCH 0347/1170] =?UTF-8?q?Query=E7=B1=BB=E5=A2=9E=E5=8A=A0data?= =?UTF-8?q?=20inc=20dec=20exp=E6=96=B9=E6=B3=95=E7=94=A8=E4=BA=8E=E5=BF=AB?= =?UTF-8?q?=E6=8D=B7=E8=AE=BE=E7=BD=AE=E6=95=B0=E6=8D=AE=20insert=E5=92=8C?= =?UTF-8?q?update=E6=96=B9=E6=B3=95=E5=8F=82=E6=95=B0=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA=20=E8=AF=BB=E5=8F=96data=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 66 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 9b30d3ed..c6586c00 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -797,6 +797,62 @@ class Query return $this; } + /** + * 设置数据 + * @access public + * @param mixed $field 字段名或者数据 + * @param mixed $value 字段值 + * @return $this + */ + public function data($field, $value = null) + { + if (is_array($field)) { + $this->options['data'] = $field; + } else { + $this->options['data'][$field] = $value; + } + return $this; + } + + /** + * 字段值增长 + * @access public + * @param string $field 字段名 + * @param integer $step 增长值 + * @return $this + */ + public function inc($field, $step = 1) + { + $this->data($field, ['exp', $field . '+' . $step]); + return $this; + } + + /** + * 字段值减少 + * @access public + * @param string $field 字段名 + * @param integer $step 增长值 + * @return $this + */ + public function dec($field, $step = 1) + { + $this->data($field, ['exp', $field . '-' . $step]); + return $this; + } + + /** + * 使用表达式设置数据 + * @access public + * @param string $field 字段名 + * @param string $value 字段值 + * @return $this + */ + public function exp($field, $value) + { + $this->data($field, ['exp', $value]); + return $this; + } + /** * 指定JOIN查询字段 * @access public @@ -1802,10 +1858,11 @@ class Query * @param string $sequence 自增序列名 * @return integer|string */ - public function insert(array $data, $replace = false, $getLastInsID = false, $sequence = null) + public function insert(array $data = [], $replace = false, $getLastInsID = false, $sequence = null) { // 分析查询表达式 $options = $this->parseExpress(); + $data = array_merge($options['data'], $data); // 生成SQL语句 $sql = $this->builder->insert($data, $options, $replace); // 获取参数绑定 @@ -1900,9 +1957,10 @@ class Query * @throws Exception * @throws PDOException */ - public function update(array $data) + public function update(array $data = []) { $options = $this->parseExpress(); + $data = array_merge($options['data'], $data); $pk = $this->getPk($options); if (isset($options['cache']) && is_string($options['cache'])) { $key = $options['cache']; @@ -2382,6 +2440,10 @@ class Query $options['field'] = '*'; } + if (!isset($options['data'])) { + $options['data'] = []; + } + if (!isset($options['strict'])) { $options['strict'] = $this->getConfig('fields_strict'); } -- Gitee From 917bba151e360d386f0b9ddaadaa274086013aa6 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 3 Jan 2017 12:04:00 +0800 Subject: [PATCH 0348/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BRoute=E7=B1=BB?= =?UTF-8?q?=E7=9A=84=E5=90=8E=E7=BC=80=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index b5f29c25..4f08e911 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1126,8 +1126,8 @@ class Route || (isset($option['ajax']) && !$option['ajax'] && $request->isAjax()) // 非Ajax检测 || (isset($option['pjax']) && $option['pjax'] && !$request->isPjax()) // Pjax检测 || (isset($option['pjax']) && !$option['pjax'] && $request->isPjax()) // 非Pjax检测 - || (isset($option['ext']) && false === stripos($option['ext'] . '|', $request->ext() . '|')) // 伪静态后缀检测 - || (isset($option['deny_ext']) && false !== stripos($option['deny_ext'] . '|', $request->ext() . '|')) + || (isset($option['ext']) && false === stripos('|' . $option['ext'] . '|', $request->ext() ? '|' . $request->ext() . '|' : '')) // 伪静态后缀检测 + || (isset($option['deny_ext']) && false !== stripos('|' . $option['deny_ext'] . '|', $request->ext() ? '|' . $request->ext() . '|' : '')) || (isset($option['domain']) && !in_array($option['domain'], [$_SERVER['HTTP_HOST'], self::$subDomain])) // 域名检测 || (isset($option['https']) && $option['https'] && !$request->isSsl()) // https检测 || (isset($option['https']) && !$option['https'] && $request->isSsl()) // https检测 -- Gitee From c27baa4b08b0ef0916df1c0b3c553ea0d09e1f35 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 3 Jan 2017 12:09:59 +0800 Subject: [PATCH 0349/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/thinkphp/library/think/debugTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/thinkphp/library/think/debugTest.php b/tests/thinkphp/library/think/debugTest.php index d6424a3d..fc2fdd47 100644 --- a/tests/thinkphp/library/think/debugTest.php +++ b/tests/thinkphp/library/think/debugTest.php @@ -118,7 +118,7 @@ class debugTest extends \PHPUnit_Framework_TestCase { $useMem = Debug::getUseMem(); - $this->assertLessThan(30, explode(" ", $useMem)[0]); + $this->assertLessThan(35, explode(" ", $useMem)[0]); } /** @@ -161,7 +161,7 @@ class debugTest extends \PHPUnit_Framework_TestCase public function testDump() { if (strstr(PHP_VERSION, 'hhvm')) { - return ; + return; } $var = []; -- Gitee From c659275872faa0169d7ec1777e5179e925ecec8f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 3 Jan 2017 13:59:31 +0800 Subject: [PATCH 0350/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BB?= =?UTF-8?q?=E7=9A=84data=E7=9A=84=E5=A4=9A=E6=AC=A1=E8=AE=BE=E7=BD=AE=20?= =?UTF-8?q?=20inc=20=E5=92=8Cdec=E6=96=B9=E6=B3=95=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index c6586c00..21c70a03 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -807,7 +807,7 @@ class Query public function data($field, $value = null) { if (is_array($field)) { - $this->options['data'] = $field; + $this->options['data'] = isset($this->options['data']) ? array_merge($this->options['data'], $field) : $field; } else { $this->options['data'][$field] = $value; } @@ -817,26 +817,32 @@ class Query /** * 字段值增长 * @access public - * @param string $field 字段名 - * @param integer $step 增长值 + * @param string|array $field 字段名 + * @param integer $step 增长值 * @return $this */ public function inc($field, $step = 1) { - $this->data($field, ['exp', $field . '+' . $step]); + $fields = is_string($field) ? explode(',', $field) : $field; + foreach ($fields as $field) { + $this->data($field, ['exp', $field . '+' . $step]); + } return $this; } /** * 字段值减少 * @access public - * @param string $field 字段名 - * @param integer $step 增长值 + * @param string|array $field 字段名 + * @param integer $step 增长值 * @return $this */ public function dec($field, $step = 1) { - $this->data($field, ['exp', $field . '-' . $step]); + $fields = is_string($field) ? explode(',', $field) : $field; + foreach ($fields as $field) { + $this->data($field, ['exp', $field . '-' . $step]); + } return $this; } -- Gitee From 7fa018ca0c5714fe0f2a11279824f3ae927f95a8 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 3 Jan 2017 14:37:41 +0800 Subject: [PATCH 0351/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9BMysql=E9=A9=B1?= =?UTF-8?q?=E5=8A=A8=E7=9A=84getFields=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/connector/Mysql.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/library/think/db/connector/Mysql.php b/library/think/db/connector/Mysql.php index fd6f4ece..31435694 100644 --- a/library/think/db/connector/Mysql.php +++ b/library/think/db/connector/Mysql.php @@ -51,10 +51,13 @@ class Mysql extends Connection { $this->initConnect(true); list($tableName) = explode(' ', $tableName); - if (strpos($tableName, '.')) { - $tableName = str_replace('.', '`.`', $tableName); + if (false === strpos($tableName, '`')) { + if (strpos($tableName, '.')) { + $tableName = str_replace('.', '`.`', $tableName); + } + $tableName = '`' . $tableName . '`'; } - $sql = 'SHOW COLUMNS FROM `' . $tableName . '`'; + $sql = 'SHOW COLUMNS FROM ' . $tableName; // 调试开始 $this->debug(true); $pdo = $this->linkID->query($sql); -- Gitee From 5b97e178faf32cd74db44bed3f7c7812163ed576 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 4 Jan 2017 11:00:35 +0800 Subject: [PATCH 0352/1170] =?UTF-8?q?Validate=E7=B1=BB=E7=9A=84confirm?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E6=94=B9=E4=B8=BA=E6=81=92=E7=AD=89=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index 03f19017..e3bc9db6 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -435,7 +435,7 @@ class Validate $rule = $field . '_confirm'; } } - return $this->getDataValue($data, $rule) == $value; + return $this->getDataValue($data, $rule) === $value; } /** -- Gitee From 8f39a8ef7cf23e9a498670bfe3a50109311f2023 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 4 Jan 2017 12:41:13 +0800 Subject: [PATCH 0353/1170] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=EF=BC=88create=5Ftime=20=E5=92=8C=20update?= =?UTF-8?q?=5Ftime=EF=BC=89=E7=9A=84=E8=8E=B7=E5=8F=96=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=97=B6=E9=97=B4=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/think/Model.php b/library/think/Model.php index 76bc2d36..b520f801 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -437,6 +437,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess } elseif (isset($this->type[$name])) { // 类型转换 $value = $this->readTransform($value, $this->type[$name]); + } elseif (in_array($name, [$this->createTime, $this->updateTime])) { + $value = $this->formatDateTime($value, $this->dateFormat); } elseif ($notFound) { $method = Loader::parseName($name, 1, false); if (method_exists($this, $method) && $this->$method() instanceof Relation) { -- Gitee From 8985a41c323ccb13957fc76ce1d81040efe4c3f8 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 4 Jan 2017 16:50:42 +0800 Subject: [PATCH 0354/1170] =?UTF-8?q?like=E6=9F=A5=E8=AF=A2=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E6=94=AF=E6=8C=81=E6=95=B0=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Builder.php | 12 +++++++++++- library/think/db/Query.php | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index 29b5688a..2372152c 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -334,9 +334,19 @@ abstract class Builder } $whereStr = ''; - if (in_array($exp, ['=', '<>', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE'])) { + if (in_array($exp, ['=', '<>', '>', '>=', '<', '<='])) { // 比较运算 及 模糊匹配 $whereStr .= $key . ' ' . $exp . ' ' . $this->parseValue($value, $field); + } elseif ('LIKE' == $exp || 'NOT LIKE' == $exp) { + if (is_array($value)) { + foreach ($value as $item) { + $array[] = $key . ' ' . $exp . ' ' . $this->parseValue($item, $field); + } + $logic = isset($val[2]) ? $val[2] : 'AND'; + $whereStr .= '(' . implode($array, ' ' . strtoupper($logic) . ' ') . ')'; + } else { + $whereStr .= $key . ' ' . $exp . ' ' . $this->parseValue($value, $field); + } } elseif ('EXP' == $exp) { // 表达式查询 $whereStr .= '( ' . $key . ' ' . $value . ' )'; diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 21c70a03..263565f9 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1018,7 +1018,7 @@ class Query // 字段相等查询 $where[$field] = ['eq', $op]; } else { - $where[$field] = [$op, $condition]; + $where[$field] = [$op, $condition, isset($param[2]) ? $param[2] : null]; if ('exp' == strtolower($op) && isset($param[2]) && is_array($param[2])) { // 参数绑定 $this->bind($param[2]); -- Gitee From aecd3524a9deafdac7822532f034f7cacf6a6326 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 4 Jan 2017 21:46:02 +0800 Subject: [PATCH 0355/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E5=BC=95=E6=93=8E=E7=9A=84empty=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/template/taglib/Cx.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/think/template/taglib/Cx.php b/library/think/template/taglib/Cx.php index 1a23c764..8132c178 100644 --- a/library/think/template/taglib/Cx.php +++ b/library/think/template/taglib/Cx.php @@ -431,7 +431,7 @@ class Cx extends Taglib { $name = $tag['name']; $name = $this->autoBuildVar($name); - $parseStr = 'isEmpty())): ?>' . $content . ''; + $parseStr = 'isEmpty())): ?>' . $content . ''; return $parseStr; } @@ -448,7 +448,7 @@ class Cx extends Taglib { $name = $tag['name']; $name = $this->autoBuildVar($name); - $parseStr = 'isEmpty()))): ?>' . $content . ''; + $parseStr = 'isEmpty()))): ?>' . $content . ''; return $parseStr; } -- Gitee From 3275b70156ea2092e4ae830e7c09a1418e1d6475 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 4 Jan 2017 22:06:55 +0800 Subject: [PATCH 0356/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/thinkphp/library/think/template/taglib/cxTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/thinkphp/library/think/template/taglib/cxTest.php b/tests/thinkphp/library/think/template/taglib/cxTest.php index c1c67413..04f3c26d 100644 --- a/tests/thinkphp/library/think/template/taglib/cxTest.php +++ b/tests/thinkphp/library/think/template/taglib/cxTest.php @@ -389,7 +389,7 @@ default {/empty} EOF; $data = <<isEmpty())): ?> +isEmpty())): ?> default EOF; @@ -402,7 +402,7 @@ default {/notempty} EOF; $data = <<isEmpty()))): ?> +isEmpty()))): ?> default EOF; @@ -538,13 +538,13 @@ EOF; public function testUrl() { $template = new template(); - $content = <<display($content); $this->expectOutputString(\think\Url::build('Index/index')); } - + public function testFunction() { $template = new template(); -- Gitee From 8f5fbe2e9fe8f08bc7ee62705b84bd88b3f30b29 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 4 Jan 2017 22:11:30 +0800 Subject: [PATCH 0357/1170] =?UTF-8?q?=E7=BB=A7=E7=BB=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/thinkphp/library/think/template/taglib/cxTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/thinkphp/library/think/template/taglib/cxTest.php b/tests/thinkphp/library/think/template/taglib/cxTest.php index 04f3c26d..54a8a931 100644 --- a/tests/thinkphp/library/think/template/taglib/cxTest.php +++ b/tests/thinkphp/library/think/template/taglib/cxTest.php @@ -389,7 +389,7 @@ default {/empty} EOF; $data = <<isEmpty())): ?> +isEmpty())): ?> default EOF; @@ -402,7 +402,7 @@ default {/notempty} EOF; $data = <<isEmpty()))): ?> +isEmpty()))): ?> default EOF; -- Gitee From 883574dea270a484a351526e1d301f5f46d130c2 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 5 Jan 2017 15:43:37 +0800 Subject: [PATCH 0358/1170] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=AD=97=E6=AE=B5=E7=9A=84=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index b520f801..0491e551 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -438,7 +438,11 @@ abstract class Model implements \JsonSerializable, \ArrayAccess // 类型转换 $value = $this->readTransform($value, $this->type[$name]); } elseif (in_array($name, [$this->createTime, $this->updateTime])) { - $value = $this->formatDateTime($value, $this->dateFormat); + if (is_string($this->autoWriteTimestamp) && in_array(strtolower($this->autoWriteTimestamp), ['datetime', 'date', 'timestamp'])) { + $value = $this->formatDateTime(strtotime($value), $this->dateFormat); + } else { + $value = $this->formatDateTime($value, $this->dateFormat); + } } elseif ($notFound) { $method = Loader::parseName($name, 1, false); if (method_exists($this, $method) && $this->$method() instanceof Relation) { @@ -724,7 +728,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $this->autoCompleteData($this->auto); // 自动写入更新时间 - if ($this->autoWriteTimestamp && $this->updateTime && !isset($this->data[$this->updateTime])) { + if ($this->autoWriteTimestamp && $this->updateTime && (empty($this->change) || !in_array($this->updateTime, $this->change))) { $this->setAttr($this->updateTime, null); } @@ -781,7 +785,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $this->autoCompleteData($this->insert); // 自动写入创建时间 - if ($this->autoWriteTimestamp && $this->createTime && !isset($this->data[$this->createTime])) { + if ($this->autoWriteTimestamp && $this->createTime && (empty($this->change) || !in_array($this->createTime, $this->change))) { $this->setAttr($this->createTime, null); } -- Gitee From 07fe0e0ae77fdc5b61aa22cfb7253d6336d38975 Mon Sep 17 00:00:00 2001 From: birdy0815 Date: Fri, 6 Jan 2017 14:02:36 +0800 Subject: [PATCH 0359/1170] =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E5=85=81=E8=AE=B8?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89Output=E7=9A=84driver=EF=BC=8C?= =?UTF-8?q?=E4=BB=A5=E9=80=82=E5=BA=94=E5=91=BD=E4=BB=A4=E8=A1=8C=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=E8=B0=83=E7=94=A8=E5=85=B6=E5=AE=83=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E8=A1=8C=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 这样在命令行下,调用别的命令行,可以直接一行一行地输出日志,而不用等到buffer完,才输出 --- library/think/Console.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/library/think/Console.php b/library/think/Console.php index 233489b5..1d97ab2b 100644 --- a/library/think/Console.php +++ b/library/think/Console.php @@ -88,18 +88,19 @@ class Console } /** - * @param $command - * @param array $parameters + * @param $command + * @param array $parameters + * @param string $driver * @return Output|Buffer */ - public static function call($command, array $parameters = []) + public static function call($command, array $parameters = [], $driver = 'buffer') { $console = self::init(false); array_unshift($parameters, $command); $input = new Input($parameters); - $output = new Output('buffer'); + $output = new Output($driver); $console->setCatchExceptions(false); $console->find($command)->run($input, $output); -- Gitee From d81a52f8d2a885f74b0c93265f99fa5290e3b9ee Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 6 Jan 2017 14:14:21 +0800 Subject: [PATCH 0360/1170] =?UTF-8?q?Session=E7=B1=BB=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=AE=89=E5=85=A8=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convention.php | 2 ++ library/think/Session.php | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/convention.php b/convention.php index a35ac0b9..c66ef583 100644 --- a/convention.php +++ b/convention.php @@ -203,6 +203,8 @@ return [ 'type' => '', // 是否自动开启 SESSION 'auto_start' => true, + 'httponly' => true, + 'secure' => true, ], // +---------------------------------------------------------------------- diff --git a/library/think/Session.php b/library/think/Session.php index 48f23caa..35726220 100644 --- a/library/think/Session.php +++ b/library/think/Session.php @@ -77,7 +77,12 @@ class Session ini_set('session.gc_maxlifetime', $config['expire']); ini_set('session.cookie_lifetime', $config['expire']); } - + if (isset($config['secure'])) { + ini_set('session.cookie_secure', $config['secure']); + } + if (isset($config['httponly'])) { + ini_set('session.cookie_httponly', $config['httponly']); + } if (isset($config['use_cookies'])) { ini_set('session.use_cookies', $config['use_cookies'] ? 1 : 0); } -- Gitee From 4afee9c8b82e14c93e8ef4e1f217fef5514914f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=82=A0=E6=82=A0=E5=B1=B1=E9=9B=A8?= Date: Fri, 6 Jan 2017 15:10:59 +0800 Subject: [PATCH 0361/1170] Update BelongsToMany.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 给$data默认值NULL,用于删除以关联外键为条件的中间表 --- library/think/model/relation/BelongsToMany.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index bbab3714..428620a2 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -308,7 +308,7 @@ class BelongsToMany extends Relation * @param bool $relationDel 是否同时删除关联表数据 * @return integer */ - public function detach($data, $relationDel = false) + public function detach($data = null, $relationDel = false) { if (is_array($data)) { $id = $data; -- Gitee From fd2546730b0afa0046ce05aef66ce719ee8fe65a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 6 Jan 2017 16:12:27 +0800 Subject: [PATCH 0362/1170] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=8F=82=E6=95=B0=E5=A2=9E=E5=8A=A0result=5Ftype=20?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E8=AE=BE=E7=BD=AE=E6=95=B0=E6=8D=AE=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E7=B1=BB=E5=9E=8B=20=E6=96=B9=E6=B3=95=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=90=8D=E7=A7=B0=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Connection.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index ef56c6fd..23bf00cb 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -95,6 +95,8 @@ abstract class Connection 'slave_no' => '', // 是否严格检查字段是否存在 'fields_strict' => true, + // 数据返回类型 + 'result_type' => PDO::FETCH_ASSOC, // 数据集返回类型 'resultset_type' => 'array', // 自动写入时间戳字段 @@ -269,6 +271,10 @@ abstract class Connection if (isset($config['resultset_type'])) { $this->resultSetType = $config['resultset_type']; } + // 数据返回类型 + if (isset($config['result_type'])) { + $this->fetchType = $config['result_type']; + } try { if (empty($config['dsn'])) { $config['dsn'] = $this->parseDsn($config); @@ -322,12 +328,12 @@ abstract class Connection * @param string $sql sql指令 * @param array $bind 参数绑定 * @param boolean $master 是否在主服务器读操作 - * @param bool|string $class 指定返回的数据集对象 + * @param bool $pdo 是否返回PDO对象 * @return mixed * @throws BindParamException * @throws PDOException */ - public function query($sql, $bind = [], $master = false, $class = false) + public function query($sql, $bind = [], $master = false, $pdo = false) { $this->initConnect($master); if (!$this->linkID) { @@ -356,7 +362,7 @@ abstract class Connection // 调试结束 $this->debug(false); $procedure = in_array(strtolower(substr(trim($sql), 0, 4)), ['call', 'exec']); - return $this->getResult($class, $procedure); + return $this->getResult($pdo, $procedure); } catch (\PDOException $e) { throw new PDOException($e, $this->config, $this->queryStr); } @@ -473,11 +479,11 @@ abstract class Connection /** * 获得数据集 * @access protected - * @param bool|string $class true 返回PDOStatement 字符串用于指定返回的类名 - * @param bool $procedure 是否存储过程 + * @param bool $pdo 是否返回PDOStatement + * @param bool $procedure 是否存储过程 * @return mixed */ - protected function getResult($class = '', $procedure = false) + protected function getResult($pdo = false, $procedure = false) { if (true === $class) { // 返回PDOStatement对象处理 @@ -485,7 +491,7 @@ abstract class Connection } if ($procedure) { // 存储过程返回结果 - return $this->procedure($class); + return $this->procedure(); } $result = $this->PDOStatement->fetchAll($this->fetchType); $this->numRows = count($result); @@ -500,14 +506,13 @@ abstract class Connection /** * 获得存储过程数据集 * @access protected - * @param bool|string $class true 返回PDOStatement 字符串用于指定返回的类名 * @return array */ - protected function procedure($class) + protected function procedure() { $item = []; do { - $result = $this->getResult($class); + $result = $this->getResult(); if ($result) { $item[] = $result; } -- Gitee From ba7ca1d562c0dd9b74921ccdf5142f2bb7f47d71 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 6 Jan 2017 16:17:35 +0800 Subject: [PATCH 0363/1170] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Connection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index 23bf00cb..0110aa28 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -485,7 +485,7 @@ abstract class Connection */ protected function getResult($pdo = false, $procedure = false) { - if (true === $class) { + if ($pdo) { // 返回PDOStatement对象处理 return $this->PDOStatement; } -- Gitee From 31ca473866b5019c177c32620dde7b0314e3bf45 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 6 Jan 2017 17:22:22 +0800 Subject: [PATCH 0364/1170] =?UTF-8?q?Revert=20"=E6=94=B9=E8=BF=9B=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E5=BC=95=E6=93=8E=E7=9A=84empty=E6=A0=87=E7=AD=BE"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit aecd3524a9deafdac7822532f034f7cacf6a6326. --- library/think/template/taglib/Cx.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/think/template/taglib/Cx.php b/library/think/template/taglib/Cx.php index 8132c178..1a23c764 100644 --- a/library/think/template/taglib/Cx.php +++ b/library/think/template/taglib/Cx.php @@ -431,7 +431,7 @@ class Cx extends Taglib { $name = $tag['name']; $name = $this->autoBuildVar($name); - $parseStr = 'isEmpty())): ?>' . $content . ''; + $parseStr = 'isEmpty())): ?>' . $content . ''; return $parseStr; } @@ -448,7 +448,7 @@ class Cx extends Taglib { $name = $tag['name']; $name = $this->autoBuildVar($name); - $parseStr = 'isEmpty()))): ?>' . $content . ''; + $parseStr = 'isEmpty()))): ?>' . $content . ''; return $parseStr; } -- Gitee From 7cb833ae45b2e18f137a640ec11e473d32ac0431 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 6 Jan 2017 17:36:36 +0800 Subject: [PATCH 0365/1170] =?UTF-8?q?Revert=20"=E4=BF=AE=E6=AD=A3=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 3275b70156ea2092e4ae830e7c09a1418e1d6475. # Conflicts: # tests/thinkphp/library/think/template/taglib/cxTest.php --- tests/thinkphp/library/think/template/taglib/cxTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/thinkphp/library/think/template/taglib/cxTest.php b/tests/thinkphp/library/think/template/taglib/cxTest.php index 54a8a931..c1c67413 100644 --- a/tests/thinkphp/library/think/template/taglib/cxTest.php +++ b/tests/thinkphp/library/think/template/taglib/cxTest.php @@ -389,7 +389,7 @@ default {/empty} EOF; $data = <<isEmpty())): ?> +isEmpty())): ?> default EOF; @@ -402,7 +402,7 @@ default {/notempty} EOF; $data = <<isEmpty()))): ?> +isEmpty()))): ?> default EOF; @@ -538,13 +538,13 @@ EOF; public function testUrl() { $template = new template(); - $content = <<display($content); $this->expectOutputString(\think\Url::build('Index/index')); } - + public function testFunction() { $template = new template(); -- Gitee From 22cf6f3318a429d12aba2de3806b89d9740bcfd4 Mon Sep 17 00:00:00 2001 From: Weijing Jay Lin Date: Mon, 9 Jan 2017 00:59:33 -0800 Subject: [PATCH 0366/1170] mobile friendly debug view --- tpl/think_exception.tpl | 58 +++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/tpl/think_exception.tpl b/tpl/think_exception.tpl index e80c57b2..2d898c30 100644 --- a/tpl/think_exception.tpl +++ b/tpl/think_exception.tpl @@ -79,15 +79,17 @@ - 系统发生错误 + <?php echo lang('System Error'); ?> +