From 0b8327d135adbd25a4493090182451d8bd3dd851 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 10 Oct 2016 10:51:32 +0800 Subject: [PATCH 1/7] =?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]; From cbfd825311d49a034bdeae3e869d4334cc22464c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 10 Oct 2016 12:17:48 +0800 Subject: [PATCH 2/7] =?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; From f2d44a4775eac9cca5eb327a894dfa27408044c6 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 10 Oct 2016 12:27:32 +0800 Subject: [PATCH 3/7] =?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'); ?>



From e3466b43833e5afaa94f40c3907027d2c6d51f75 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 10 Oct 2016 16:29:47 +0800 Subject: [PATCH 4/7] =?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); From c67eb5adc87596772cb5a1e6632c01e49d24f6e8 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 10 Oct 2016 17:25:37 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BB=E7=9A=84va?= =?UTF-8?q?lue=E6=96=B9=E6=B3=95=E7=BC=93=E5=AD=98=E5=88=A4=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']); } From 6440a640cdda724cf28f4fbf60392ef5c80a70b1 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 10 Oct 2016 18:11:45 +0800 Subject: [PATCH 6/7] =?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]; } From 5ff97ce68d36a9e3e3dc2ddb77c87303c760008c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 11 Oct 2016 12:27:22 +0800 Subject: [PATCH 7/7] =?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; } }