更新TP内核文件

This commit is contained in:
2017-06-11 13:35:42 +08:00
parent 9d6a9e1c9c
commit deef5d9d52
15 changed files with 130 additions and 76 deletions

View File

@@ -4,7 +4,8 @@ return [
// +----------------------------------------------------------------------
// | 应用设置
// +----------------------------------------------------------------------
// 默认Host地址
'app_host' => '',
// 应用调试模式
'app_debug' => true,
// 应用Trace
@@ -89,8 +90,6 @@ return [
'url_route_must' => false,
// 域名部署
'url_domain_deploy' => false,
// 默认Host地址
'default_host' => '',
// 域名根如thinkphp.cn
'url_domain_root' => '',
// 是否自动转换URL中的控制器和操作名

View File

@@ -492,7 +492,7 @@ class App
$dir = CONF_PATH . $module . 'extra';
$files = scandir($dir);
foreach ($files as $file) {
if (strpos($file, CONF_EXT)) {
if (pathinfo($file, PATHINFO_EXTENSION) === CONF_EXT) {
$filename = $dir . DS . $file;
Config::load($filename, pathinfo($file, PATHINFO_FILENAME));
}

View File

@@ -193,6 +193,10 @@ class Build
protected static function buildCommon($module)
{
$filename = CONF_PATH . ($module ? $module . DS : '') . 'config.php';
if (!is_dir(dirname($filename))) {
mkdir(dirname($filename, 0755, true));
}
if (!is_file($filename)) {
file_put_contents($filename, "<?php\n//配置文件\nreturn [\n\n];");
}

View File

@@ -23,6 +23,11 @@ class Env
{
$result = getenv(ENV_PREFIX . strtoupper(str_replace('.', '_', $name)));
if (false !== $result) {
if ('false' === $result) {
$result = false;
} elseif ('true' === $result) {
$result = true;
}
return $result;
} else {
return $default;

View File

@@ -13,7 +13,7 @@ namespace think;
use InvalidArgumentException;
use think\db\Query;
use think\Exception\ValidateException;
use think\exception\ValidateException;
use think\model\Collection as ModelCollection;
use think\model\Relation;
use think\model\relation\BelongsTo;
@@ -324,6 +324,18 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
}
}
/**
* 是否需要自动写入时间字段
* @access public
* @param bool $auto
* @return $this
*/
public function isAutoWriteTimestamp($auto)
{
$this->autoWriteTimestamp = $auto;
return $this;
}
/**
* 修改器 设置数据对象值
* @access public
@@ -958,14 +970,14 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
// 自动更新
$this->autoCompleteData($this->update);
// 获取有更新的数据
$data = $this->getChangedData();
// 事件回调
if (false === $this->trigger('before_update', $this)) {
return false;
}
// 获取有更新的数据
$data = $this->getChangedData();
if (empty($data) || (count($data) == 1 && is_string($pk) && isset($data[$pk]))) {
// 关联更新
if (isset($relation)) {
@@ -1120,6 +1132,66 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
return $data;
}
/**
* 字段值(延迟)增长
* @access public
* @param string $field 字段名
* @param integer $step 增长值
* @param integer $lazyTime 延时时间(s)
* @return integer|true
* @throws Exception
*/
public function setInc($field, $step = 1, $lazyTime = 0)
{
// 删除条件
$pk = $this->getPk();
if (is_string($pk) && isset($this->data[$pk])) {
$where = [$pk => $this->data[$pk]];
} elseif (!empty($this->updateWhere)) {
$where = $this->updateWhere;
} else {
$where = null;
}
$result = $this->getQuery()->where($where)->setInc($field, $step, $lazyTime);
if (true !== $result) {
$this->data[$field] += $step;
}
return $result;
}
/**
* 字段值(延迟)增长
* @access public
* @param string $field 字段名
* @param integer $step 增长值
* @param integer $lazyTime 延时时间(s)
* @return integer|true
* @throws Exception
*/
public function setDec($field, $step = 1, $lazyTime = 0)
{
// 删除条件
$pk = $this->getPk();
if (is_string($pk) && isset($this->data[$pk])) {
$where = [$pk => $this->data[$pk]];
} elseif (!empty($this->updateWhere)) {
$where = $this->updateWhere;
} else {
$where = null;
}
$result = $this->getQuery()->where($where)->setDec($field, $step, $lazyTime);
if (true !== $result) {
$this->data[$field] -= $step;
}
return $result;
}
/**
* 保存多个数据到当前数据对象
* @access public

View File

@@ -602,7 +602,7 @@ class Request
}
/**
* 获取获取当前请求的参数
* 获取当前请求的参数
* @access public
* @param string|array $name 变量名
* @param mixed $default 默认值
@@ -639,7 +639,7 @@ class Request
}
/**
* 设置获取获取路由参数
* 设置获取路由参数
* @access public
* @param string|array $name 变量名
* @param mixed $default 默认值
@@ -656,7 +656,7 @@ class Request
}
/**
* 设置获取获取GET参数
* 设置获取GET参数
* @access public
* @param string|array $name 变量名
* @param mixed $default 默认值
@@ -676,7 +676,7 @@ class Request
}
/**
* 设置获取获取POST参数
* 设置获取POST参数
* @access public
* @param string $name 变量名
* @param mixed $default 默认值
@@ -701,7 +701,7 @@ class Request
}
/**
* 设置获取获取PUT参数
* 设置获取PUT参数
* @access public
* @param string|array $name 变量名
* @param mixed $default 默认值
@@ -727,7 +727,7 @@ class Request
}
/**
* 设置获取获取DELETE参数
* 设置获取DELETE参数
* @access public
* @param string|array $name 变量名
* @param mixed $default 默认值
@@ -740,7 +740,7 @@ class Request
}
/**
* 设置获取获取PATCH参数
* 设置获取PATCH参数
* @access public
* @param string|array $name 变量名
* @param mixed $default 默认值

View File

@@ -235,7 +235,7 @@ class Url
$rootDomain = Config::get('url_domain_root');
if (true === $domain) {
// 自动判断域名
$domain = Config::get('default_host') ?: $request->host();
$domain = Config::get('app_host') ?: $request->host();
$domains = Route::rules('domain');
if ($domains) {
@@ -265,14 +265,19 @@ class Url
} else {
if (empty($rootDomain)) {
$host = Config::get('default_host') ?: $request->host();
$host = Config::get('app_host') ?: $request->host();
$rootDomain = substr_count($host, '.') > 1 ? substr(strstr($host, '.'), 1) : $host;
}
if (substr_count($domain, '.') < 2 && !strpos($domain, $rootDomain)) {
$domain .= '.' . $rootDomain;
}
}
return ($request->isSsl() ? 'https://' : 'http://') . $domain;
if (false !== strpos($domain, ':')) {
$scheme = '';
} else {
$scheme = $request->isSsl() || Config::get('is_https') ? 'https://' : 'http://';
}
return $scheme . $domain;
}
// 解析URL后缀

View File

@@ -165,7 +165,7 @@ class Validate
}
/**
* 获取验证规则的默认提示信息
* 设置验证规则的默认提示信息
* @access protected
* @param string|array $type 验证规则类型名称或者数组
* @param string $msg 验证提示信息

View File

@@ -376,7 +376,7 @@ abstract class Builder
if ($value instanceof \Closure) {
$whereStr .= $key . ' ' . $exp . ' ' . $this->parseClosure($value);
} else {
$value = is_array($value) ? $value : explode(',', $value);
$value = array_unique(is_array($value) ? $value : explode(',', $value));
if (array_key_exists($field, $binds)) {
$bind = [];
$array = [];

View File

@@ -395,7 +395,7 @@ class Query
public function value($field, $default = null, $force = false)
{
$result = false;
if (empty($options['fetch_sql']) && !empty($this->options['cache'])) {
if (empty($this->options['fetch_sql']) && !empty($this->options['cache'])) {
// 判断查询缓存
$cache = $this->options['cache'];
if (empty($this->options['table'])) {
@@ -438,7 +438,7 @@ class Query
public function column($field, $key = '')
{
$result = false;
if (empty($options['fetch_sql']) && !empty($this->options['cache'])) {
if (empty($this->options['fetch_sql']) && !empty($this->options['cache'])) {
// 判断查询缓存
$cache = $this->options['cache'];
if (empty($this->options['table'])) {

View File

@@ -51,7 +51,6 @@ class Mysql extends Connection
*/
public function getFields($tableName)
{
$this->initConnect(false);
list($tableName) = explode(' ', $tableName);
if (false === strpos($tableName, '`')) {
if (strpos($tableName, '.')) {
@@ -59,12 +58,8 @@ class Mysql extends Connection
}
$tableName = '`' . $tableName . '`';
}
$sql = 'SHOW COLUMNS FROM ' . $tableName;
// 调试开始
$this->debug(true);
$pdo = $this->linkID->query($sql);
// 调试结束
$this->debug(false, $sql);
$sql = 'SHOW COLUMNS FROM ' . $tableName;
$pdo = $this->query($sql, [], false, true);
$result = $pdo->fetchAll(PDO::FETCH_ASSOC);
$info = [];
if ($result) {
@@ -91,13 +86,8 @@ class Mysql extends Connection
*/
public function getTables($dbName = '')
{
$this->initConnect(false);
$sql = !empty($dbName) ? 'SHOW TABLES FROM ' . $dbName : 'SHOW TABLES ';
// 调试开始
$this->debug(true);
$pdo = $this->linkID->query($sql);
// 调试结束
$this->debug(false, $sql);
$sql = !empty($dbName) ? 'SHOW TABLES FROM ' . $dbName : 'SHOW TABLES ';
$pdo = $this->query($sql, [], false, true);
$result = $pdo->fetchAll(PDO::FETCH_ASSOC);
$info = [];
foreach ($result as $key => $val) {

View File

@@ -44,14 +44,11 @@ class Pgsql extends Connection
*/
public function getFields($tableName)
{
$this->initConnect(false);
list($tableName) = explode(' ', $tableName);
$sql = 'select fields_name as "field",fields_type as "type",fields_not_null as "null",fields_key_name as "key",fields_default as "default",fields_default as "extra" from table_msg(\'' . $tableName . '\');';
// 调试开始
$this->debug(true);
$pdo = $this->linkID->query($sql);
// 调试结束
$this->debug(false, $sql);
$pdo = $this->query($sql, [], false, true);
$result = $pdo->fetchAll(PDO::FETCH_ASSOC);
$info = [];
if ($result) {
@@ -78,13 +75,8 @@ class Pgsql extends Connection
*/
public function getTables($dbName = '')
{
$this->initConnect(false);
$sql = "select tablename as Tables_in_test from pg_tables where schemaname ='public'";
// 调试开始
$this->debug(true);
$pdo = $this->linkID->query($sql);
// 调试结束
$this->debug(false, $sql);
$sql = "select tablename as Tables_in_test from pg_tables where schemaname ='public'";
$pdo = $this->query($sql, [], false, true);
$result = $pdo->fetchAll(PDO::FETCH_ASSOC);
$info = [];
foreach ($result as $key => $val) {

View File

@@ -42,14 +42,10 @@ class Sqlite extends Connection
*/
public function getFields($tableName)
{
$this->initConnect(false);
list($tableName) = explode(' ', $tableName);
$sql = 'PRAGMA table_info( ' . $tableName . ' )';
// 调试开始
$this->debug(true);
$pdo = $this->linkID->query($sql);
// 调试结束
$this->debug(false, $sql);
$pdo = $this->query($sql, [], false, true);
$result = $pdo->fetchAll(PDO::FETCH_ASSOC);
$info = [];
if ($result) {
@@ -76,15 +72,12 @@ class Sqlite extends Connection
*/
public function getTables($dbName = '')
{
$this->initConnect(false);
$sql = "SELECT name FROM sqlite_master WHERE type='table' "
. "UNION ALL SELECT name FROM sqlite_temp_master "
. "WHERE type='table' ORDER BY name";
// 调试开始
$this->debug(true);
$pdo = $this->linkID->query($sql);
// 调试结束
$this->debug(false, $sql);
$pdo = $this->query($sql, [], false, true);
$result = $pdo->fetchAll(PDO::FETCH_ASSOC);
$info = [];
foreach ($result as $key => $val) {

View File

@@ -49,7 +49,6 @@ class Sqlsrv extends Connection
*/
public function getFields($tableName)
{
$this->initConnect(false);
list($tableName) = explode(' ', $tableName);
$sql = "SELECT column_name, data_type, column_default, is_nullable
FROM information_schema.tables AS t
@@ -58,11 +57,8 @@ class Sqlsrv extends Connection
AND t.table_schema = c.table_schema
AND t.table_name = c.table_name
WHERE t.table_name = '$tableName'";
// 调试开始
$this->debug(true);
$pdo = $this->linkID->query($sql);
// 调试结束
$this->debug(false, $sql);
$pdo = $this->query($sql, [], false, true);
$result = $pdo->fetchAll(PDO::FETCH_ASSOC);
$info = [];
if ($result) {
@@ -99,16 +95,12 @@ class Sqlsrv extends Connection
*/
public function getTables($dbName = '')
{
$this->initConnect(false);
$sql = "SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
";
// 调试开始
$this->debug(true);
$pdo = $this->linkID->query($sql);
// 调试结束
$this->debug(false, $sql);
$pdo = $this->query($sql, [], false, true);
$result = $pdo->fetchAll(PDO::FETCH_ASSOC);
$info = [];
foreach ($result as $key => $val) {

View File

@@ -93,7 +93,7 @@ class BelongsToMany extends Relation
}
}
}
$model->pivot = $this->newPivot($pivot);
$model->setRelation('pivot', $this->newPivot($pivot));
}
}
@@ -162,7 +162,9 @@ class BelongsToMany extends Relation
public function find($data = null)
{
$result = $this->buildQuery()->find($data);
$this->hydratePivot([$result]);
if ($result) {
$this->hydratePivot([$result]);
}
return $result;
}
@@ -357,7 +359,7 @@ class BelongsToMany extends Relation
}
}
}
$set->pivot = $this->newPivot($pivot);
$set->setRelation('pivot', $this->newPivot($pivot));
$data[$pivot[$this->localKey]][] = $set;
}
return $data;