更新内核
This commit is contained in:
@@ -147,7 +147,7 @@ if (!function_exists('widget')) {
|
|||||||
/**
|
/**
|
||||||
* 渲染输出Widget
|
* 渲染输出Widget
|
||||||
* @param string $name Widget名称
|
* @param string $name Widget名称
|
||||||
* @param array $data 传人的参数
|
* @param array $data 传入的参数
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function widget($name, $data = [])
|
function widget($name, $data = [])
|
||||||
@@ -272,8 +272,8 @@ if (!function_exists('url')) {
|
|||||||
/**
|
/**
|
||||||
* Url生成
|
* Url生成
|
||||||
* @param string $url 路由地址
|
* @param string $url 路由地址
|
||||||
* @param string|array $value 变量
|
* @param string|array $vars 变量
|
||||||
* @param bool|string $suffix 前缀
|
* @param bool|string $suffix 生成的URL后缀
|
||||||
* @param bool|string $domain 域名
|
* @param bool|string $domain 域名
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@@ -361,7 +361,7 @@ if (!function_exists('cache')) {
|
|||||||
}
|
}
|
||||||
if ('' === $value) {
|
if ('' === $value) {
|
||||||
// 获取缓存
|
// 获取缓存
|
||||||
return Cache::get($name);
|
return 0 === strpos($name, '?') ? Cache::has(substr($name, 1)) : Cache::get($name);
|
||||||
} elseif (is_null($value)) {
|
} elseif (is_null($value)) {
|
||||||
// 删除缓存
|
// 删除缓存
|
||||||
return Cache::rm($name);
|
return Cache::rm($name);
|
||||||
|
|||||||
@@ -156,24 +156,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
$query->name($this->name);
|
$query->name($this->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($this->field)) {
|
|
||||||
if (true === $this->field) {
|
|
||||||
$type = $this->db()->getTableInfo('', 'type');
|
|
||||||
} else {
|
|
||||||
$type = [];
|
|
||||||
foreach ((array) $this->field as $key => $val) {
|
|
||||||
if (is_int($key)) {
|
|
||||||
$key = $val;
|
|
||||||
$val = 'varchar';
|
|
||||||
}
|
|
||||||
$type[$key] = $val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$query->setFieldType($type);
|
|
||||||
$this->field = array_keys($type);
|
|
||||||
$query->allowField($this->field);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($this->pk)) {
|
if (!empty($this->pk)) {
|
||||||
$query->pk($this->pk);
|
$query->pk($this->pk);
|
||||||
}
|
}
|
||||||
@@ -631,7 +613,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
|
|
||||||
// 检测字段
|
// 检测字段
|
||||||
if (!empty($this->field)) {
|
if (!empty($this->field)) {
|
||||||
$this->db();
|
|
||||||
foreach ($this->data as $key => $val) {
|
foreach ($this->data as $key => $val) {
|
||||||
if (!in_array($key, $this->field)) {
|
if (!in_array($key, $this->field)) {
|
||||||
unset($this->data[$key]);
|
unset($this->data[$key]);
|
||||||
@@ -781,9 +762,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
public function allowField($field)
|
public function allowField($field)
|
||||||
{
|
{
|
||||||
if (true === $field) {
|
if (true === $field) {
|
||||||
$field = $this->db()->getTableInfo('', 'type');
|
$field = $this->db()->getTableInfo('', 'fields');
|
||||||
$this->db()->setFieldType($field);
|
|
||||||
$field = array_keys($field);
|
|
||||||
}
|
}
|
||||||
$this->field = $field;
|
$this->field = $field;
|
||||||
return $this;
|
return $this;
|
||||||
|
|||||||
@@ -300,6 +300,9 @@ abstract class Builder
|
|||||||
$bindType = isset($binds[$field]) ? $binds[$field] : PDO::PARAM_STR;
|
$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 (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 (strpos($value, ':') !== 0 || !$this->query->isBind(substr($value, 1))) {
|
||||||
|
if ($this->query->isBind($bindName)) {
|
||||||
|
$bindName .= '_' . uniqid();
|
||||||
|
}
|
||||||
$this->query->bind($bindName, $value, $bindType);
|
$this->query->bind($bindName, $value, $bindType);
|
||||||
$value = ':' . $bindName;
|
$value = ':' . $bindName;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,10 +43,6 @@ class Query
|
|||||||
protected $name = '';
|
protected $name = '';
|
||||||
// 当前数据表主键
|
// 当前数据表主键
|
||||||
protected $pk;
|
protected $pk;
|
||||||
// 当前表字段类型信息
|
|
||||||
protected $fieldType = [];
|
|
||||||
// 当前允许的字段列表
|
|
||||||
protected $allowField = [];
|
|
||||||
// 当前数据表前缀
|
// 当前数据表前缀
|
||||||
protected $prefix = '';
|
protected $prefix = '';
|
||||||
// 查询参数
|
// 查询参数
|
||||||
@@ -741,11 +737,11 @@ class Query
|
|||||||
}
|
}
|
||||||
if (true === $field) {
|
if (true === $field) {
|
||||||
// 获取全部字段
|
// 获取全部字段
|
||||||
$fields = !empty($this->allowField) && ('' == $tableName || $this->getTable() == $tableName) ? $this->allowField : $this->getTableInfo($tableName ?: (isset($this->options['table']) ? $this->options['table'] : ''), 'fields');
|
$fields = $this->getTableInfo($tableName ?: (isset($this->options['table']) ? $this->options['table'] : ''), 'fields');
|
||||||
$field = $fields ?: ['*'];
|
$field = $fields ?: ['*'];
|
||||||
} elseif ($except) {
|
} elseif ($except) {
|
||||||
// 字段排除
|
// 字段排除
|
||||||
$fields = !empty($this->allowField) && ('' == $tableName || $this->getTable() == $tableName) ? $this->allowField : $this->getTableInfo($tableName ?: (isset($this->options['table']) ? $this->options['table'] : ''), 'fields');
|
$fields = $this->getTableInfo($tableName ?: (isset($this->options['table']) ? $this->options['table'] : ''), 'fields');
|
||||||
$field = $fields ? array_diff($fields, $field) : $field;
|
$field = $fields ? array_diff($fields, $field) : $field;
|
||||||
}
|
}
|
||||||
if ($tableName) {
|
if ($tableName) {
|
||||||
@@ -1260,35 +1256,6 @@ class Query
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置数据表字段
|
|
||||||
* @access public
|
|
||||||
* @param string|array $field 字段信息
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function allowField($field)
|
|
||||||
{
|
|
||||||
if (true === $field) {
|
|
||||||
$field = $this->getTableInfo('', 'fields');
|
|
||||||
} elseif (is_string($field)) {
|
|
||||||
$field = explode(',', $field);
|
|
||||||
}
|
|
||||||
$this->allowField = $field;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置字段类型
|
|
||||||
* @access public
|
|
||||||
* @param array $fieldType 字段类型信息
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function setFieldType($fieldType = [])
|
|
||||||
{
|
|
||||||
$this->fieldType = $fieldType;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 指定数据表主键
|
* 指定数据表主键
|
||||||
* @access public
|
* @access public
|
||||||
@@ -1375,7 +1342,12 @@ class Query
|
|||||||
|
|
||||||
list($guid) = explode(' ', $tableName);
|
list($guid) = explode(' ', $tableName);
|
||||||
if (!isset(self::$info[$guid])) {
|
if (!isset(self::$info[$guid])) {
|
||||||
$info = $this->connection->getFields($tableName);
|
// 读取缓存
|
||||||
|
if (is_file(RUNTIME_PATH . 'schema/' . $guid . '.php')) {
|
||||||
|
$info = include RUNTIME_PATH . 'schema/' . $guid . '.php';
|
||||||
|
} else {
|
||||||
|
$info = $this->connection->getFields($guid);
|
||||||
|
}
|
||||||
$fields = array_keys($info);
|
$fields = array_keys($info);
|
||||||
$bind = $type = [];
|
$bind = $type = [];
|
||||||
foreach ($info as $key => $val) {
|
foreach ($info as $key => $val) {
|
||||||
@@ -1416,13 +1388,13 @@ class Query
|
|||||||
// 获取当前数据表字段信息
|
// 获取当前数据表字段信息
|
||||||
public function getTableFields($options)
|
public function getTableFields($options)
|
||||||
{
|
{
|
||||||
return !empty($this->allowField) ? $this->allowField : $this->getTableInfo($options['table'], 'fields');
|
return $this->getTableInfo($options['table'], 'fields');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取当前数据表字段类型
|
// 获取当前数据表字段类型
|
||||||
public function getFieldsType($options)
|
public function getFieldsType($options)
|
||||||
{
|
{
|
||||||
return !empty($this->fieldType) ? $this->fieldType : $this->getTableInfo($options['table'], 'type');
|
return $this->getTableInfo($options['table'], 'type');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取当前数据表绑定信息
|
// 获取当前数据表绑定信息
|
||||||
@@ -1998,9 +1970,6 @@ class Query
|
|||||||
$model = $this->model;
|
$model = $this->model;
|
||||||
$data = new $model($data);
|
$data = new $model($data);
|
||||||
$data->isUpdate(true, isset($options['where']['AND']) ? $options['where']['AND'] : null);
|
$data->isUpdate(true, isset($options['where']['AND']) ? $options['where']['AND'] : null);
|
||||||
if ($this->allowField) {
|
|
||||||
$data->allowField($this->allowField);
|
|
||||||
}
|
|
||||||
// 关联查询
|
// 关联查询
|
||||||
if (!empty($options['relation'])) {
|
if (!empty($options['relation'])) {
|
||||||
$data->relationQuery($options['relation']);
|
$data->relationQuery($options['relation']);
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ class Mysql extends Connection
|
|||||||
*/
|
*/
|
||||||
public function getTables($dbName = '')
|
public function getTables($dbName = '')
|
||||||
{
|
{
|
||||||
|
$this->initConnect(true);
|
||||||
$sql = !empty($dbName) ? 'SHOW TABLES FROM ' . $dbName : 'SHOW TABLES ';
|
$sql = !empty($dbName) ? 'SHOW TABLES FROM ' . $dbName : 'SHOW TABLES ';
|
||||||
// 调试开始
|
// 调试开始
|
||||||
$this->debug(true);
|
$this->debug(true);
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ class Pgsql extends Connection
|
|||||||
*/
|
*/
|
||||||
public function getTables($dbName = '')
|
public function getTables($dbName = '')
|
||||||
{
|
{
|
||||||
|
$this->initConnect(true);
|
||||||
$sql = "select tablename as Tables_in_test from pg_tables where schemaname ='public'";
|
$sql = "select tablename as Tables_in_test from pg_tables where schemaname ='public'";
|
||||||
// 调试开始
|
// 调试开始
|
||||||
$this->debug(true);
|
$this->debug(true);
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ class Sqlite extends Connection
|
|||||||
*/
|
*/
|
||||||
public function getTables($dbName = '')
|
public function getTables($dbName = '')
|
||||||
{
|
{
|
||||||
|
$this->initConnect(true);
|
||||||
$sql = "SELECT name FROM sqlite_master WHERE type='table' "
|
$sql = "SELECT name FROM sqlite_master WHERE type='table' "
|
||||||
. "UNION ALL SELECT name FROM sqlite_temp_master "
|
. "UNION ALL SELECT name FROM sqlite_temp_master "
|
||||||
. "WHERE type='table' ORDER BY name";
|
. "WHERE type='table' ORDER BY name";
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ class Sqlsrv extends Connection
|
|||||||
*/
|
*/
|
||||||
public function getTables($dbName = '')
|
public function getTables($dbName = '')
|
||||||
{
|
{
|
||||||
|
$this->initConnect(true);
|
||||||
$sql = "SELECT TABLE_NAME
|
$sql = "SELECT TABLE_NAME
|
||||||
FROM INFORMATION_SCHEMA.TABLES
|
FROM INFORMATION_SCHEMA.TABLES
|
||||||
WHERE TABLE_TYPE = 'BASE TABLE'
|
WHERE TABLE_TYPE = 'BASE TABLE'
|
||||||
|
|||||||
@@ -141,7 +141,11 @@ class Php
|
|||||||
*/
|
*/
|
||||||
public function config($name, $value = null)
|
public function config($name, $value = null)
|
||||||
{
|
{
|
||||||
|
if (is_array($name)) {
|
||||||
|
$this->config = array_merge($this->config, $name);
|
||||||
|
} else {
|
||||||
|
$this->config[$name] = $value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,8 +140,10 @@ class Think
|
|||||||
{
|
{
|
||||||
if (is_array($name)) {
|
if (is_array($name)) {
|
||||||
$this->template->config($name);
|
$this->template->config($name);
|
||||||
|
$this->config = array_merge($this->config, $name);
|
||||||
} else {
|
} else {
|
||||||
$this->template->$name = $value;
|
$this->template->$name = $value;
|
||||||
|
$this->config[$name] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user