内核更新
This commit is contained in:
@@ -59,5 +59,5 @@ return [
|
|||||||
'tag error' => '模板标签错误',
|
'tag error' => '模板标签错误',
|
||||||
'cache write error' => '缓存写入失败',
|
'cache write error' => '缓存写入失败',
|
||||||
'sae mc write error' => 'SAE mc 写入错误',
|
'sae mc write error' => 'SAE mc 写入错误',
|
||||||
'route name not exists' => '路由命名标识不存在',
|
'route name not exists' => '路由标识不存在(或参数不够)',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -138,12 +138,14 @@ class Route
|
|||||||
/**
|
/**
|
||||||
* 设置路由绑定
|
* 设置路由绑定
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $name 路由命名标识
|
* @param string|array $name 路由命名标识 数组表示批量设置
|
||||||
* @return string|array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function name($name = '')
|
public static function name($name = '')
|
||||||
{
|
{
|
||||||
if ('' === $name) {
|
if (is_array($name)) {
|
||||||
|
return self::$name = $name;
|
||||||
|
} elseif ('' === $name) {
|
||||||
return self::$name;
|
return self::$name;
|
||||||
} else {
|
} else {
|
||||||
return isset(self::$name[$name]) ? self::$name[$name] : null;
|
return isset(self::$name[$name]) ? self::$name[$name] : null;
|
||||||
@@ -301,7 +303,7 @@ class Route
|
|||||||
}
|
}
|
||||||
$vars = self::parseVar($rule);
|
$vars = self::parseVar($rule);
|
||||||
if (isset($name)) {
|
if (isset($name)) {
|
||||||
self::$name[$name] = [$rule, $vars, self::$domain];
|
self::$name[$name][] = [$rule, $vars, self::$domain];
|
||||||
}
|
}
|
||||||
if ($group) {
|
if ($group) {
|
||||||
if ('*' != $type) {
|
if ('*' != $type) {
|
||||||
|
|||||||
@@ -22,11 +22,8 @@ class Url
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* URL生成 支持路由反射
|
* URL生成 支持路由反射
|
||||||
* @param string $url URL表达式,
|
* @param string $url 路由地址
|
||||||
* 格式:'[模块/控制器/操作]?参数1=值1&参数2=值2...@域名'
|
* @param string|array $vars 参数(支持数组和字符串)a=val&b=val2... ['a'=>'val1', 'b'=>'val2']
|
||||||
* @控制器/操作?参数1=值1&参数2=值2...
|
|
||||||
* \\命名空间类\\方法?参数1=值1&参数2=值2...
|
|
||||||
* @param string|array $vars 传入的参数,支持数组和字符串
|
|
||||||
* @param string|bool $suffix 伪静态后缀,默认为true表示获取配置值
|
* @param string|bool $suffix 伪静态后缀,默认为true表示获取配置值
|
||||||
* @param boolean|string $domain 是否显示域名 或者直接传入域名
|
* @param boolean|string $domain 是否显示域名 或者直接传入域名
|
||||||
* @return string
|
* @return string
|
||||||
@@ -77,10 +74,10 @@ class Url
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!empty($rule) && $match = self::getRuleUrl($rule, $vars)) {
|
if (!empty($rule) && $match = self::getRuleUrl($rule, $vars)) {
|
||||||
// 匹配路由命名标识 快速生成
|
// 匹配路由命名标识
|
||||||
$url = $match;
|
$url = $match[0];
|
||||||
if (!empty($rule[2])) {
|
if (!empty($match[1])) {
|
||||||
$domain = $rule[2];
|
$domain = $match[1];
|
||||||
}
|
}
|
||||||
} elseif (!empty($rule) && isset($name)) {
|
} elseif (!empty($rule) && isset($name)) {
|
||||||
throw new \InvalidArgumentException('route name not exists:' . $name);
|
throw new \InvalidArgumentException('route name not exists:' . $name);
|
||||||
@@ -90,7 +87,7 @@ class Url
|
|||||||
parse_str($info['query'], $params);
|
parse_str($info['query'], $params);
|
||||||
$vars = array_merge($params, $vars);
|
$vars = array_merge($params, $vars);
|
||||||
}
|
}
|
||||||
// 路由不存在 直接解析
|
// 路由标识不存在 直接解析
|
||||||
$url = self::parseUrl($url, $domain);
|
$url = self::parseUrl($url, $domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,11 +209,15 @@ class Url
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} elseif (!strpos($domain, '.')) {
|
||||||
$domain .= strpos($domain, '.') ? '' : strstr($request->host(), '.');
|
$rootDomain = Config::get('url_domain_root');
|
||||||
|
if (empty($rootDomain)) {
|
||||||
|
$host = $request->host();
|
||||||
|
$rootDomain = substr_count($host, '.') > 1 ? substr(strstr($host, '.'), 1) : $host;
|
||||||
|
}
|
||||||
|
$domain .= '.' . $rootDomain;
|
||||||
}
|
}
|
||||||
$domain = ($request->isSsl() ? 'https://' : 'http://') . $domain;
|
return ($request->isSsl() ? 'https://' : 'http://') . $domain;
|
||||||
return $domain;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析URL后缀
|
// 解析URL后缀
|
||||||
@@ -234,18 +235,28 @@ class Url
|
|||||||
// 匹配路由地址
|
// 匹配路由地址
|
||||||
public static function getRuleUrl($rule, &$vars = [])
|
public static function getRuleUrl($rule, &$vars = [])
|
||||||
{
|
{
|
||||||
list($url, $pattern) = $rule;
|
foreach ($rule as $item) {
|
||||||
foreach ($pattern as $key => $val) {
|
list($url, $pattern, $domain) = $item;
|
||||||
if (isset($vars[$key])) {
|
if (empty($pattern)) {
|
||||||
$url = str_replace(['[:' . $key . ']', '<' . $key . '?>', ':' . $key . '', '<' . $key . '>'], $vars[$key], $url);
|
return [$url, $domain];
|
||||||
unset($vars[$key]);
|
}
|
||||||
} elseif (2 == $val) {
|
foreach ($pattern as $key => $val) {
|
||||||
$url = str_replace(['/[:' . $key . ']', '[:' . $key . ']', '<' . $key . '?>'], '', $url);
|
if (isset($vars[$key])) {
|
||||||
} else {
|
$url = str_replace(['[:' . $key . ']', '<' . $key . '?>', ':' . $key . '', '<' . $key . '>'], $vars[$key], $url);
|
||||||
return false;
|
unset($vars[$key]);
|
||||||
|
$result = [$url, $domain];
|
||||||
|
} elseif (2 == $val) {
|
||||||
|
$url = str_replace(['/[:' . $key . ']', '[:' . $key . ']', '<' . $key . '?>'], '', $url);
|
||||||
|
$result = [$url, $domain];
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isset($result)) {
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $url;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 指定当前生成URL地址的root
|
// 指定当前生成URL地址的root
|
||||||
|
|||||||
@@ -41,6 +41,12 @@ class Query
|
|||||||
protected $table = '';
|
protected $table = '';
|
||||||
// 当前数据表名称(不含前缀)
|
// 当前数据表名称(不含前缀)
|
||||||
protected $name = '';
|
protected $name = '';
|
||||||
|
// 当前数据表主键
|
||||||
|
protected $pk;
|
||||||
|
// 当前表字段类型信息
|
||||||
|
protected $fieldType = [];
|
||||||
|
// 当前允许的字段列表
|
||||||
|
protected $allowField = [];
|
||||||
// 当前数据表前缀
|
// 当前数据表前缀
|
||||||
protected $prefix = '';
|
protected $prefix = '';
|
||||||
// 查询参数
|
// 查询参数
|
||||||
@@ -48,7 +54,7 @@ class Query
|
|||||||
// 参数绑定
|
// 参数绑定
|
||||||
protected $bind = [];
|
protected $bind = [];
|
||||||
// 数据表信息
|
// 数据表信息
|
||||||
protected $info = [];
|
protected static $info = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 架构函数
|
* 架构函数
|
||||||
@@ -727,11 +733,11 @@ class Query
|
|||||||
}
|
}
|
||||||
if (true === $field) {
|
if (true === $field) {
|
||||||
// 获取全部字段
|
// 获取全部字段
|
||||||
$fields = isset($this->options['allow_field']) ? $this->options['allow_field'] : $this->getTableInfo($tableName ?: (isset($this->options['table']) ? $this->options['table'] : ''), 'fields');
|
$fields = !empty($this->allowField) && ('' == $tableName || $this->getTable() == $tableName) ? $this->allowField : $this->getTableInfo($tableName ?: (isset($this->options['table']) ? $this->options['table'] : ''), 'fields');
|
||||||
$field = $fields ?: ['*'];
|
$field = $fields ?: ['*'];
|
||||||
} elseif ($except) {
|
} elseif ($except) {
|
||||||
// 字段排除
|
// 字段排除
|
||||||
$fields = isset($this->options['allow_field']) ? $this->options['allow_field'] : $this->getTableInfo($tableName ?: (isset($this->options['table']) ? $this->options['table'] : ''), 'fields');
|
$fields = !empty($this->allowField) && ('' == $tableName || $this->getTable() == $tableName) ? $this->allowField : $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) {
|
||||||
@@ -1255,7 +1261,7 @@ class Query
|
|||||||
} elseif (is_string($field)) {
|
} elseif (is_string($field)) {
|
||||||
$field = explode(',', $field);
|
$field = explode(',', $field);
|
||||||
}
|
}
|
||||||
$this->options['allow_field'] = $field;
|
$this->allowField = $field;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1267,7 +1273,7 @@ class Query
|
|||||||
*/
|
*/
|
||||||
public function setFieldType($fieldType = [])
|
public function setFieldType($fieldType = [])
|
||||||
{
|
{
|
||||||
$this->options['field_type'] = $fieldType;
|
$this->fieldType = $fieldType;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1279,7 +1285,7 @@ class Query
|
|||||||
*/
|
*/
|
||||||
public function pk($pk)
|
public function pk($pk)
|
||||||
{
|
{
|
||||||
$this->options['pk'] = $pk;
|
$this->pk = $pk;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1356,7 +1362,7 @@ class Query
|
|||||||
}
|
}
|
||||||
|
|
||||||
$guid = $tableName;
|
$guid = $tableName;
|
||||||
if (!isset($this->info[$guid])) {
|
if (!isset(self::$info[$guid])) {
|
||||||
$info = $this->connection->getFields($tableName);
|
$info = $this->connection->getFields($tableName);
|
||||||
$fields = array_keys($info);
|
$fields = array_keys($info);
|
||||||
$bind = $type = [];
|
$bind = $type = [];
|
||||||
@@ -1374,9 +1380,9 @@ class Query
|
|||||||
} else {
|
} else {
|
||||||
$pk = null;
|
$pk = null;
|
||||||
}
|
}
|
||||||
$this->info[$guid] = ['fields' => $fields, 'type' => $type, 'bind' => $bind, 'pk' => $pk];
|
self::$info[$guid] = ['fields' => $fields, 'type' => $type, 'bind' => $bind, 'pk' => $pk];
|
||||||
}
|
}
|
||||||
return $fetch ? $this->info[$guid][$fetch] : $this->info[$guid];
|
return $fetch ? self::$info[$guid][$fetch] : self::$info[$guid];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1387,10 +1393,8 @@ class Query
|
|||||||
*/
|
*/
|
||||||
public function getPk($options = '')
|
public function getPk($options = '')
|
||||||
{
|
{
|
||||||
if (!empty($options['pk'])) {
|
if (!empty($this->pk)) {
|
||||||
$pk = $options['pk'];
|
$pk = $this->pk;
|
||||||
} elseif (isset($this->options['pk'])) {
|
|
||||||
$pk = $this->options['pk'];
|
|
||||||
} else {
|
} else {
|
||||||
$pk = $this->getTableInfo(is_array($options) ? $options['table'] : $options, 'pk');
|
$pk = $this->getTableInfo(is_array($options) ? $options['table'] : $options, 'pk');
|
||||||
}
|
}
|
||||||
@@ -1400,13 +1404,13 @@ class Query
|
|||||||
// 获取当前数据表字段信息
|
// 获取当前数据表字段信息
|
||||||
public function getTableFields($options)
|
public function getTableFields($options)
|
||||||
{
|
{
|
||||||
return !empty($options['allow_field']) ? $options['allow_field'] : $this->getTableInfo($options['table'], 'fields');
|
return !empty($this->allowField) ? $this->allowField : $this->getTableInfo($options['table'], 'fields');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取当前数据表字段类型
|
// 获取当前数据表字段类型
|
||||||
public function getFieldsType($options)
|
public function getFieldsType($options)
|
||||||
{
|
{
|
||||||
return !empty($options['field_type']) ? $options['field_type'] : $this->getTableInfo($options['table'], 'type');
|
return !empty($this->fieldType) ? $this->fieldType : $this->getTableInfo($options['table'], 'type');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取当前数据表绑定信息
|
// 获取当前数据表绑定信息
|
||||||
|
|||||||
Reference in New Issue
Block a user