1、内核修复

2、用户模块完善和bug修复
This commit is contained in:
2016-07-15 11:59:56 +08:00
parent 9ad5d5fd9c
commit ad1f4c029e
14 changed files with 122 additions and 174 deletions

View File

@@ -672,6 +672,8 @@ class Route
if ($checkDomain) {
self::checkDomain($request);
}
// 获取当前请求类型的路由规则
$rules = self::$rules[$request->method()];
// 检测URL绑定
$return = self::checkUrlBind($url, $rules, $depr);
@@ -679,9 +681,6 @@ class Route
return $return;
}
// 获取当前请求类型的路由规则
$rules = self::$rules[$request->method()];
if (isset($rules[$url])) {
// 静态路由规则检测
$rule = $rules[$url];

View File

@@ -19,9 +19,6 @@ use think\Route;
class Url
{
// 生成URL地址的root
protected static $root;
/**
* URL生成 支持路由反射
* @param string $url URL表达式
@@ -116,7 +113,7 @@ class Url
// 检测域名
$domain = self::parseDomain($url, $domain);
// URL组装
$url = $domain . (self::$root ?: Request::instance()->root()) . '/' . ltrim($url, '/');
$url = $domain . Request::instance()->root() . '/' . ltrim($url, '/');
return $url;
}
@@ -319,11 +316,4 @@ class Url
{
Cache::rm('think_route_map');
}
// 指定当前生成URL地址的root
public static function root($root)
{
self::$root = $root;
Request::instance()->root($root);
}
}
}

View File

@@ -48,6 +48,10 @@ class Validate
'alphaNum' => ':attribute只能是字母和数字',
'alphaDash' => ':attribute只能是字母、数字和下划线_及破折号-',
'activeUrl' => ':attribute不是有效的域名或者IP',
'chs' => ':attribute只能是汉字',
'chsAlpha' => ':attribute只能是汉字、字母',
'chsAlphaNum'=> ':attribute只能是汉字、字母和数字',
'chsDash' => ':attribute只能是汉字、字母、数字和下划线_及破折号-',
'url' => ':attribute不是有效的URL地址',
'ip' => ':attribute不是有效的IP地址',
'dateFormat' => ':attribute必须使用日期格式 :rule',
@@ -516,6 +520,22 @@ class Validate
// 只允许字母、数字和下划线 破折号
$result = $this->regex($value, '/^[A-Za-z0-9\-\_]+$/');
break;
case 'chs':
// 只允许汉字
$result = $this->regex($value, '/^[\x{4e00}-\x{9fa5}]+$/u');
break;
case 'chsAlpha':
// 只允许汉字、字母
$result = $this->regex($value, '/^[\x{4e00}-\x{9fa5}a-zA-Z]+$/u');
break;
case 'chsAlphaNum':
// 只允许汉字、字母和数字
$result = $this->regex($value, '/^[\x{4e00}-\x{9fa5}a-zA-Z0-9]+$/u');
break;
case 'chsDash':
// 只允许汉字、字母、数字和下划线_及破折号-
$result = $this->regex($value, '/^[\x{4e00}-\x{9fa5}a-zA-Z0-9\_\-]+$/u');
break;
case 'activeUrl':
// 是否为有效的网址
$result = checkdnsrr($value);

View File

@@ -24,7 +24,6 @@ class Sqlsrv extends Connection
PDO::ATTR_CASE => PDO::CASE_LOWER,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_STRINGIFY_FETCHES => false,
PDO::SQLSRV_ATTR_ENCODING => PDO::SQLSRV_ENCODING_UTF8,
];
/**

View File

@@ -43,6 +43,8 @@ class Relation
protected $alias;
// 当前关联的JOIN类型
protected $joinType;
// 关联模型查询对象
protected $query;
/**
* 架构函数
@@ -409,7 +411,7 @@ class Relation
$this->localKey = $localKey;
$this->alias = $alias;
$this->joinType = $joinType;
$this->query = (new $model)->db();
// 返回关联的模型对象
return $this;
}
@@ -433,7 +435,7 @@ class Relation
$this->localKey = $otherKey;
$this->alias = $alias;
$this->joinType = $joinType;
$this->query = (new $model)->db();
// 返回关联的模型对象
return $this;
}
@@ -455,7 +457,7 @@ class Relation
$this->foreignKey = $foreignKey;
$this->localKey = $localKey;
$this->alias = $alias;
$this->query = (new $model)->db();
// 返回关联的模型对象
return $this;
}
@@ -481,7 +483,7 @@ class Relation
$this->throughKey = $throughKey;
$this->localKey = $localKey;
$this->alias = $alias;
$this->query = (new $model)->db();
// 返回关联的模型对象
return $this;
}
@@ -505,7 +507,7 @@ class Relation
$this->localKey = $localKey;
$this->middle = $table;
$this->alias = $alias;
$this->query = (new $model)->db();
// 返回关联的模型对象
return $this;
}
@@ -653,14 +655,12 @@ class Relation
public function __call($method, $args)
{
if ($this->model) {
$model = new $this->model;
$db = $model->db();
if ($this->query) {
switch ($this->type) {
case self::HAS_MANY:
if (isset($this->parent->{$this->localKey})) {
// 关联查询带入关联条件
$db->where($this->foreignKey, $this->parent->{$this->localKey});
$this->query->where($this->foreignKey, $this->parent->{$this->localKey});
}
break;
case self::HAS_MANY_THROUGH:
@@ -671,13 +671,18 @@ class Relation
$pk = (new $this->model)->getPk();
$throughKey = $this->throughKey;
$modelTable = $this->parent->getTable();
$result = $db->field($alias . '.*')->alias($alias)
$result = $this->query->field($alias . '.*')->alias($alias)
->join($throughTable, $throughTable . '.' . $pk . '=' . $alias . '.' . $throughKey)
->join($modelTable, $modelTable . '.' . $this->localKey . '=' . $throughTable . '.' . $this->foreignKey)
->where($throughTable . '.' . $this->foreignKey, $this->parent->{$this->localKey});
break;
}
return call_user_func_array([$db, $method], $args);
$result = call_user_func_array([$this->query, $method], $args);
if ($result instanceof \think\db\Query) {
return $this;
} else {
return $result;
}
} else {
throw new Exception('method not exists:' . __CLASS__ . '->' . $method);
}

View File

@@ -19,8 +19,9 @@ class Json extends Response
protected $options = [
'json_encode_param' => JSON_UNESCAPED_UNICODE,
];
protected $contentType = 'application/json';
/**
* 处理数据
* @access protected
@@ -31,6 +32,11 @@ class Json extends Response
{
// 返回JSON数据格式到客户端 包含状态信息
$data = json_encode($data, $this->options['json_encode_param']);
if ($data === false) {
throw new \InvalidArgumentException(json_last_error_msg());
}
return $data;
}

View File

@@ -22,7 +22,7 @@ class Jsonp extends Response
'default_jsonp_handler' => 'jsonpReturn',
'json_encode_param' => JSON_UNESCAPED_UNICODE,
];
protected $contentType = 'application/javascript';
/**
@@ -35,8 +35,15 @@ class Jsonp extends Response
{
// 返回JSON数据格式到客户端 包含状态信息 [当url_common_param为false时是无法获取到$_GET的数据的故使用Request来获取<xiaobo.sun@qq.com>]
$var_jsonp_handler = Request::instance()->param($this->options['var_jsonp_handler'], "");
$handler = !empty($var_jsonp_handler) ? $var_jsonp_handler : $this->options['default_jsonp_handler'];
$data = $handler . '(' . json_encode($data, $this->options['json_encode_param']) . ');';
$handler = !empty($var_jsonp_handler) ? $var_jsonp_handler : $this->options['default_jsonp_handler'];
$data = json_encode($data, $this->options['json_encode_param']);
if ($data === false) {
throw new \InvalidArgumentException(json_last_error_msg());
}
$data = $handler . '(' . $data . ');';
return $data;
}