|
@@ -211,7 +211,11 @@ class Base {
|
|
*/
|
|
*/
|
|
public function setWhereHooker($hooker, $args = null) {
|
|
public function setWhereHooker($hooker, $args = null) {
|
|
$this->checkCallable($hooker);
|
|
$this->checkCallable($hooker);
|
|
- $this->setHooker('where', $hooker, $args);
|
|
|
|
|
|
+
|
|
|
|
+ if(!isset($this->hooker['where'])) {
|
|
|
|
+ $this->hooker['where'] = [];
|
|
|
|
+ }
|
|
|
|
+ $this->hooker['where'][] = ['func' => $hooker, 'args' => $args];
|
|
return $this;
|
|
return $this;
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
@@ -221,16 +225,24 @@ class Base {
|
|
*/
|
|
*/
|
|
public function getWhereHooker() {
|
|
public function getWhereHooker() {
|
|
$where = $this->properties();
|
|
$where = $this->properties();
|
|
- if(isset($this->hooker['where']) && is_callable($this->hooker['where']['func'])) {
|
|
|
|
- if($this->alias != ""){
|
|
|
|
- foreach ($where as $key => $value) {
|
|
|
|
- if(!preg_match("/{$this->alias}\.{$key}/", $key)) {
|
|
|
|
- $where[$this->alias .'.'. $key] = $value;
|
|
|
|
- unset($where[$key]);
|
|
|
|
|
|
+ if(!isset($this->hooker['where']) || !is_array($this->hooker['where'])) {
|
|
|
|
+ return $where;
|
|
|
|
+ }
|
|
|
|
+ // 遍历
|
|
|
|
+ foreach ($this->hooker['where'] as $item) {
|
|
|
|
+ if(is_callable($item['func'])) {
|
|
|
|
+ $subWhere = call_user_func($item['func'], $where, $item['args']);
|
|
|
|
+ foreach ($subWhere as $key => $value) {
|
|
|
|
+ if($this->alias != "") {
|
|
|
|
+ if(!preg_match("/{$this->alias}\.{$key}/", $key)) {
|
|
|
|
+ $where[$this->alias . '.' . $key] = $value;
|
|
|
|
+ unset($subWhere[$key]);
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ $where[$key] = $value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- $where = call_user_func($this->hooker['where']['func'], $where, $this->hooker['where']['args']);
|
|
|
|
}
|
|
}
|
|
return $where;
|
|
return $where;
|
|
}
|
|
}
|
|
@@ -344,7 +356,7 @@ class Base {
|
|
/**
|
|
/**
|
|
* 设置缓存插件
|
|
* 设置缓存插件
|
|
*
|
|
*
|
|
- * @param Cache $cache 缓存类
|
|
|
|
|
|
+ * @param array $cache 缓存类
|
|
* @return $this
|
|
* @return $this
|
|
* @throws \Exception
|
|
* @throws \Exception
|
|
*/
|
|
*/
|
|
@@ -1876,7 +1888,11 @@ class Base {
|
|
}
|
|
}
|
|
$method = substr($method, 0, strlen($cache) * -1);
|
|
$method = substr($method, 0, strlen($cache) * -1);
|
|
if (method_exists($this, $method)) {
|
|
if (method_exists($this, $method)) {
|
|
- $key = get_called_class() .':'. $method .':'. substr(md5(serialize($this->properties())), -16);
|
|
|
|
|
|
+ if($cacheID != '') {
|
|
|
|
+ $key = $cacheID;
|
|
|
|
+ }else{
|
|
|
|
+ $key = get_called_class() .':'. $method .':'. substr(md5(serialize($this->properties())), -16);
|
|
|
|
+ }
|
|
if($cache == 'byclean') {
|
|
if($cache == 'byclean') {
|
|
return $func->del($key);
|
|
return $func->del($key);
|
|
}
|
|
}
|