Forráskód Böngészése

update where condition

zjh 5 hónapja
szülő
commit
5484038476

+ 8 - 1
src/Base/Request.php

@@ -61,7 +61,8 @@ abstract class Request
         if(IS_CLI) {
             $routeInfo = $this->url->request->getCliPathArgs();
         }
-
+        // 防止异步请求因为中间有内容输出导致header输出失败
+        ob_start();
 		if(count($routeInfo) > 1)
 		{
 			$action = array_pop($routeInfo);
@@ -558,8 +559,14 @@ abstract class Request
     {
         if (is_bool($flag)) {
             $this->dispatched = $flag;
+            $content = ob_get_contents();
+            ob_end_clean();
+            echo ($content);
             return $this;
         }
+        $content = ob_get_contents();
+        ob_end_clean();
+        echo ($content);
         return false;
     }
 

+ 2 - 1
src/Base/Response.php

@@ -364,8 +364,9 @@ class Response
      */
     protected function sendHeaders()
     {
+        $isSent = headers_sent();
         //如果设置为不发送头信息,这里就不发
-        if($this->_sendHeader) {
+        if($this->_sendHeader && !$isSent) {
             foreach ($this->headers as $key => $header) {
                 header(
                     $header['name'] . ': ' . $header['value'],

+ 2 - 1
src/Cache/Memcached.php

@@ -123,8 +123,9 @@ class Memcached implements Intf
      */
     public function get($id)
     {
-        $data = $this->_conn->get($id);
+        $data = null;
         if($this->_conn instanceof \Memcache || $this->_conn instanceof \Memcached){
+            $data = $this->_conn->get($id);
             $data = unserialize($data);
         }
         return $data;

+ 9 - 0
src/Driver/Base.php

@@ -1100,6 +1100,11 @@ class Base
                 $tmpWhere[$index] = $val;
                 continue;
             }
+            if(is_array($val)) {
+                $slices[] = $this->groupContents($val)[0];
+                //print_r($this->groupContents($val));
+                continue;
+            }
             $isOperator = $this->isOperator($val);//如果是操作符,上一个不是操作符就清空tmpWhere,并放入slices
             $isValue = !$isOperator;
             if($lastIsValue && $isOperator)
@@ -1313,6 +1318,10 @@ class Base
         for($i = 0; $i < $count; $i++)
         {
             $v = $condition[$i];
+            if(!is_array($v) && $this->isOperator($v)) {
+                $whereCondition[] = ' and ';
+                continue;
+            }
             //如果有两个及上的操作符
             //默认第一个为连接其他条件的操作符,第二个位字段和值之间的操作符, 从第三个开始即为字段与字段之间的连接符
             //最里层的字段与值之间的操作符优先级最高

+ 26 - 10
src/Driver/Entity/Base.php

@@ -211,7 +211,11 @@ class Base {
      */
     public function setWhereHooker($hooker, $args = null) {
         $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;
     }
     /**
@@ -221,16 +225,24 @@ class Base {
      */
     public function getWhereHooker() {
         $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;
     }
@@ -344,7 +356,7 @@ class Base {
     /**
      * 设置缓存插件
      *
-     * @param Cache $cache 缓存类
+     * @param array $cache 缓存类
      * @return $this
      * @throws \Exception
      */
@@ -1876,7 +1888,11 @@ class Base {
             }
             $method = substr($method, 0, strlen($cache) * -1);
             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') {
                     return $func->del($key);
                 }

+ 10 - 0
src/Request/Http.php

@@ -228,6 +228,16 @@ final class Http extends Request
     public function set($key, $val) {
         $this->params[$key] = $val;
     }
+
+    /**
+     * 是请求的json格式数据
+     *
+     * @return false
+     */
+    public function isJSON() {
+        
+        return false;
+    }
     /**
      * isXmlHttpRequest
      *