예제 #1
0
 public static function processRequest()
 {
     // get our verb
     $request_method = strtolower($_SERVER['REQUEST_METHOD']);
     $element = $_GET['REST_element'];
     $id = null;
     $operation = null;
     if (isset($_GET['REST_id'])) {
         $id = $_GET['REST_id'];
     }
     if (isset($_GET['REST_operation'])) {
         $operation = $_GET['REST_operation'];
     }
     $return_obj = new RestRequest();
     // we'll store our data here
     $data = array();
     //TO recode
     switch ($request_method) {
         // gets are easy...
         //already got element and id
         case 'get':
             $data = $_GET;
             unset($data['REST_element']);
             unset($data['REST_id']);
             unset($data['REST_operation']);
             unset($data['REST_format']);
             break;
             // so are posts
             /*case 'post':
             		$data = $_POST;
             		break;*/
             // here's the tricky bit...
         // so are posts
         /*case 'post':
         		$data = $_POST;
         		break;*/
         // here's the tricky bit...
         case 'put':
         case 'post':
             // basically, we read a string from PHP's special input location,
             // and then parse it out into an array via parse_str... per the PHP docs:
             // Parses str  as if it were the query string passed via a URL and sets
             // variables in the current scope.
             $contents = file_get_contents('php://input');
             //die('-'.$contents.'-');
             $data = RestUtils::data_decode($contents, $_SERVER['CONTENT_TYPE']);
             //$data = $contents;
             break;
     }
     // store the data
     $return_obj->setData($data);
     // store the method
     $return_obj->setMethod($request_method);
     // store the method
     $return_obj->setOperation($operation);
     // store the element
     $return_obj->setElement($element);
     // store the id
     $return_obj->setID($id);
     // set the raw data, so we can access it if needed (there may be
     // other pieces to your requests)
     $return_obj->setRequestVars($data);
     return $return_obj;
 }