From 883574dea270a484a351526e1d301f5f46d130c2 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 5 Jan 2017 15:43:37 +0800 Subject: [PATCH 1/9] =?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); } From 07fe0e0ae77fdc5b61aa22cfb7253d6336d38975 Mon Sep 17 00:00:00 2001 From: birdy0815 Date: Fri, 6 Jan 2017 14:02:36 +0800 Subject: [PATCH 2/9] =?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); From d81a52f8d2a885f74b0c93265f99fa5290e3b9ee Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 6 Jan 2017 14:14:21 +0800 Subject: [PATCH 3/9] =?UTF-8?q?Session=E7=B1=BB=E5=A2=9E=E5=8A=A0=E5=AE=89?= =?UTF-8?q?=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); } 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 4/9] 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; From fd2546730b0afa0046ce05aef66ce719ee8fe65a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 6 Jan 2017 16:12:27 +0800 Subject: [PATCH 5/9] =?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; } From ba7ca1d562c0dd9b74921ccdf5142f2bb7f47d71 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 6 Jan 2017 16:17:35 +0800 Subject: [PATCH 6/9] =?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; } From 31ca473866b5019c177c32620dde7b0314e3bf45 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 6 Jan 2017 17:22:22 +0800 Subject: [PATCH 7/9] =?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; } From 7cb833ae45b2e18f137a640ec11e473d32ac0431 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 6 Jan 2017 17:36:36 +0800 Subject: [PATCH 8/9] =?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(); From 663d9e7a1e3bd8b33104f291a1212b0b29c95f7a Mon Sep 17 00:00:00 2001 From: hooklife Date: Mon, 9 Jan 2017 17:55:25 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E4=BF=AE=E6=AD=A3PHPDoc=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 4f08e911..1629d636 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1097,7 +1097,7 @@ class Route * 绑定到模块/控制器 * @access public * @param string $url URL地址 - * @param string $class 控制器类名(带命名空间) + * @param string $controller 控制器类名(带命名空间) * @param string $depr URL分隔符 * @return array */