# Conflicts:
#	library/think/db/Connection.php
This commit is contained in:
thinkphp
2017-01-10 10:35:35 +08:00
10 changed files with 40 additions and 18 deletions

View File

@@ -203,6 +203,8 @@ return [
'type' => '', 'type' => '',
// 是否自动开启 SESSION // 是否自动开启 SESSION
'auto_start' => true, 'auto_start' => true,
'httponly' => true,
'secure' => true,
], ],
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------

View File

@@ -88,18 +88,19 @@ class Console
} }
/** /**
* @param $command * @param $command
* @param array $parameters * @param array $parameters
* @param string $driver
* @return Output|Buffer * @return Output|Buffer
*/ */
public static function call($command, array $parameters = []) public static function call($command, array $parameters = [], $driver = 'buffer')
{ {
$console = self::init(false); $console = self::init(false);
array_unshift($parameters, $command); array_unshift($parameters, $command);
$input = new Input($parameters); $input = new Input($parameters);
$output = new Output('buffer'); $output = new Output($driver);
$console->setCatchExceptions(false); $console->setCatchExceptions(false);
$console->find($command)->run($input, $output); $console->find($command)->run($input, $output);

View File

@@ -438,7 +438,11 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
// 类型转换 // 类型转换
$value = $this->readTransform($value, $this->type[$name]); $value = $this->readTransform($value, $this->type[$name]);
} elseif (in_array($name, [$this->createTime, $this->updateTime])) { } 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) { } elseif ($notFound) {
$method = Loader::parseName($name, 1, false); $method = Loader::parseName($name, 1, false);
if (method_exists($this, $method) && $this->$method() instanceof Relation) { if (method_exists($this, $method) && $this->$method() instanceof Relation) {
@@ -724,7 +728,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
$this->autoCompleteData($this->auto); $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); $this->setAttr($this->updateTime, null);
} }
@@ -781,7 +785,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
$this->autoCompleteData($this->insert); $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); $this->setAttr($this->createTime, null);
} }

View File

@@ -1097,7 +1097,7 @@ class Route
* 绑定到模块/控制器 * 绑定到模块/控制器
* @access public * @access public
* @param string $url URL地址 * @param string $url URL地址
* @param string $class 控制器类名(带命名空间) * @param string $controller 控制器类名(带命名空间)
* @param string $depr URL分隔符 * @param string $depr URL分隔符
* @return array * @return array
*/ */

View File

@@ -77,7 +77,12 @@ class Session
ini_set('session.gc_maxlifetime', $config['expire']); ini_set('session.gc_maxlifetime', $config['expire']);
ini_set('session.cookie_lifetime', $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'])) { if (isset($config['use_cookies'])) {
ini_set('session.use_cookies', $config['use_cookies'] ? 1 : 0); ini_set('session.use_cookies', $config['use_cookies'] ? 1 : 0);
} }

View File

@@ -21,7 +21,7 @@ class File extends Driver
{ {
protected $options = [ protected $options = [
'expire' => 0, 'expire' => 0,
'cache_subdir' => false, 'cache_subdir' => true,
'prefix' => '', 'prefix' => '',
'path' => CACHE_PATH, 'path' => CACHE_PATH,
'data_compress' => false, 'data_compress' => false,

View File

@@ -95,6 +95,8 @@ abstract class Connection
'slave_no' => '', 'slave_no' => '',
// 是否严格检查字段是否存在 // 是否严格检查字段是否存在
'fields_strict' => true, 'fields_strict' => true,
// 数据返回类型
'result_type' => PDO::FETCH_ASSOC,
// 数据集返回类型 // 数据集返回类型
'resultset_type' => 'array', 'resultset_type' => 'array',
// 自动写入时间戳字段 // 自动写入时间戳字段
@@ -272,6 +274,10 @@ abstract class Connection
if (isset($config['resultset_type'])) { if (isset($config['resultset_type'])) {
$this->resultSetType = $config['resultset_type']; $this->resultSetType = $config['resultset_type'];
} }
// 数据返回类型
if (isset($config['result_type'])) {
$this->fetchType = $config['result_type'];
}
try { try {
if (empty($config['dsn'])) { if (empty($config['dsn'])) {
$config['dsn'] = $this->parseDsn($config); $config['dsn'] = $this->parseDsn($config);
@@ -326,6 +332,10 @@ abstract class Connection
* @param array $bind 参数绑定 * @param array $bind 参数绑定
* @param bool $master 是否在主服务器读操作 * @param bool $master 是否在主服务器读操作
* @param bool $class 是否返回PDO对象 * @param bool $class 是否返回PDO对象
* @param string $sql sql指令
* @param array $bind 参数绑定
* @param boolean $master 是否在主服务器读操作
* @param bool $pdo 是否返回PDO对象
* @return mixed * @return mixed
* @throws BindParamException * @throws BindParamException
* @throws PDOException * @throws PDOException
@@ -369,7 +379,7 @@ abstract class Connection
// 调试结束 // 调试结束
$this->debug(false); $this->debug(false);
// 返回结果集 // 返回结果集
return $this->getResult($class, $procedure); return $this->getResult($pdo, $procedure);
} catch (\PDOException $e) { } catch (\PDOException $e) {
throw new PDOException($e, $this->config, $this->getLastsql()); throw new PDOException($e, $this->config, $this->getLastsql());
} }

View File

@@ -308,7 +308,7 @@ class BelongsToMany extends Relation
* @param bool $relationDel 是否同时删除关联表数据 * @param bool $relationDel 是否同时删除关联表数据
* @return integer * @return integer
*/ */
public function detach($data, $relationDel = false) public function detach($data = null, $relationDel = false)
{ {
if (is_array($data)) { if (is_array($data)) {
$id = $data; $id = $data;

View File

@@ -431,7 +431,7 @@ class Cx extends Taglib
{ {
$name = $tag['name']; $name = $tag['name'];
$name = $this->autoBuildVar($name); $name = $this->autoBuildVar($name);
$parseStr = '<?php $_var = ' . $name . ';if(empty($_var) || ($_var instanceof \think\Collection && $_var->isEmpty())): ?>' . $content . '<?php endif; ?>'; $parseStr = '<?php if(empty(' . $name . ') || (' . $name . ' instanceof \think\Collection && ' . $name . '->isEmpty())): ?>' . $content . '<?php endif; ?>';
return $parseStr; return $parseStr;
} }
@@ -448,7 +448,7 @@ class Cx extends Taglib
{ {
$name = $tag['name']; $name = $tag['name'];
$name = $this->autoBuildVar($name); $name = $this->autoBuildVar($name);
$parseStr = '<?php $_var = ' . $name . ';if(!(empty($_var) || ($_var instanceof \think\Collection && $_var->isEmpty()))): ?>' . $content . '<?php endif; ?>'; $parseStr = '<?php if(!(empty(' . $name . ') || (' . $name . ' instanceof \think\Collection && ' . $name . '->isEmpty()))): ?>' . $content . '<?php endif; ?>';
return $parseStr; return $parseStr;
} }

View File

@@ -389,7 +389,7 @@ default
{/empty} {/empty}
EOF; EOF;
$data = <<<EOF $data = <<<EOF
<?php \$_var = \$var;if(empty(\$_var) || (\$_var instanceof \\think\\Collection && \$_var->isEmpty())): ?> <?php if(empty(\$var) || (\$var instanceof \\think\\Collection && \$var->isEmpty())): ?>
default default
<?php endif; ?> <?php endif; ?>
EOF; EOF;
@@ -402,7 +402,7 @@ default
{/notempty} {/notempty}
EOF; EOF;
$data = <<<EOF $data = <<<EOF
<?php \$_var = \$var;if(!(empty(\$_var) || (\$_var instanceof \\think\\Collection && \$_var->isEmpty()))): ?> <?php if(!(empty(\$var) || (\$var instanceof \\think\\Collection && \$var->isEmpty()))): ?>
default default
<?php endif; ?> <?php endif; ?>
EOF; EOF;
@@ -538,7 +538,7 @@ EOF;
public function testUrl() public function testUrl()
{ {
$template = new template(); $template = new template();
$content = <<<EOF $content = <<<EOF
{url link="Index/index" /} {url link="Index/index" /}
EOF; EOF;
$template->display($content); $template->display($content);