Upgrade to ExtJS 3.2.0 - Released 03/30/2010
[extjs.git] / examples / writer / remote / lib / request.php
index 906669c..8d50662 100644 (file)
@@ -5,6 +5,7 @@
  */
 class Request {
     public $restful, $method, $controller, $action, $id, $params;
+
     public function __construct($params) {
         $this->restful = (isset($params["restful"])) ? $params["restful"] : false;
         $this->method = $_SERVER["REQUEST_METHOD"];
@@ -13,9 +14,6 @@ class Request {
     public function isRestful() {
         return $this->restful;
     }
-    public function to_string() {
-        return "controller: " . $this->controller . ', action: ' . $this->action . ', id: ' . $this->id;
-    }
     protected function parseRequest() {
         if ($this->method == 'PUT') {   // <-- Have to jump through hoops to get PUT data
             $raw  = '';
@@ -26,19 +24,36 @@ class Request {
             fclose($httpContent);
             $params = array();
             parse_str($raw, $params);
-            $this->id = (isset($params['id'])) ? $params['id'] : null;
-            $this->params = (isset($params['data'])) ? json_decode(stripslashes($params['data']), true) : null;
+
+            if (isset($params['data'])) {
+                $this->params =  json_decode(stripslashes($params['data']));
+            } else {
+                $params = json_decode(stripslashes($raw));
+                $this->params = $params->data;
+            }
         } else {
             // grab JSON data if there...
-            $this->params = (isset($_REQUEST['data'])) ? json_decode(stripslashes($_REQUEST['data']), true) : null;
-            $this->id = (isset($_REQUEST['id'])) ? json_decode(stripslashes($_REQUEST['id']), true) : null;
+            $this->params = (isset($_REQUEST['data'])) ? json_decode(stripslashes($_REQUEST['data'])) : null;
+
+            if (isset($_REQUEST['data'])) {
+                $this->params =  json_decode(stripslashes($_REQUEST['data']));
+            } else {
+                $raw  = '';
+                $httpContent = fopen('php://input', 'r');
+                while ($kb = fread($httpContent, 1024)) {
+                    $raw .= $kb;
+                }
+                $params = json_decode(stripslashes($raw));
+                $this->params = $params->data;
+            }
+
         }
-        // parse path info
+        // Quickndirty PATH_INFO parser
         if (isset($_SERVER["PATH_INFO"])){
-            $cai = '/^\/([a-z]+\w)\/([a-z]+\w)\/([0-9]+)$/';    // /controller/action/id
-            $ca =  '/^\/([a-z]+\w)\/([a-z]+\w)$/';              // /controller/action
+            $cai = '/^\/([a-z]+\w)\/([a-z]+\w)\/([0-9]+)$/';  // /controller/action/id
+            $ca =  '/^\/([a-z]+\w)\/([a-z]+)$/';              // /controller/action
             $ci = '/^\/([a-z]+\w)\/([0-9]+)$/';               // /controller/id
-            $c =  '/^\/([a-z]+)$/';                             // /controller
+            $c =  '/^\/([a-z]+\w)$/';                             // /controller
             $i =  '/^\/([0-9]+)$/';                             // /id
             $matches = array();
             if (preg_match($cai, $_SERVER["PATH_INFO"], $matches)) {