Kaynağa Gözat

Merge pull request #285 from keyingGitHub/master

添加了Http对Restful请求的参数解析
walkor 7 yıl önce
ebeveyn
işleme
19dcd87a56
2 değiştirilmiş dosya ile 25 ekleme ve 1 silme
  1. 10 0
      Connection/TcpConnection.php
  2. 15 1
      Protocols/Http.php

+ 10 - 0
Connection/TcpConnection.php

@@ -839,6 +839,16 @@ class TcpConnection extends ConnectionInterface
         }
         return false;
     }
+    
+    /**
+     * Whether send buffer is Empty.
+     *
+     * @return bool
+     */
+    public function bufferIsEmpty()
+    {
+    	return empty($this->_sendBuffer);
+    }
 
     /**
      * Destroy connection.

+ 15 - 1
Protocols/Http.php

@@ -174,9 +174,23 @@ class Http
                     case 'application/x-www-form-urlencoded':
                         parse_str($http_body, $_POST);
                         break;
+                    case 'application/json':
+                    	$_POST = json_decode($http_body, true);
+                    	break;
                 }
             }
         }
+        
+        // 解析其他HTTP动作参数
+        if ($_SERVER['REQUEST_METHOD'] != 'GET' && $_SERVER['REQUEST_METHOD'] != "POST") {
+        	$data = array();
+        	if ($_SERVER['HTTP_CONTENT_TYPE'] === "application/x-www-form-urlencoded") {
+        		parse_str($http_body, $data);
+        	} elseif ($_SERVER['HTTP_CONTENT_TYPE'] === "application/json") {
+        		$data = json_decode($http_body, true);
+        	}
+        	$_REQUEST = array_merge($_REQUEST, $data);
+        }
 
         // HTTP_RAW_REQUEST_DATA HTTP_RAW_POST_DATA
         $GLOBALS['HTTP_RAW_REQUEST_DATA'] = $GLOBALS['HTTP_RAW_POST_DATA'] = $http_body;
@@ -191,7 +205,7 @@ class Http
         }
 
         // REQUEST
-        $_REQUEST = array_merge($_GET, $_POST);
+        $_REQUEST = array_merge($_GET, $_POST, $_REQUEST);
 
         // REMOTE_ADDR REMOTE_PORT
         $_SERVER['REMOTE_ADDR'] = $connection->getRemoteIp();