예제 #1
0
 /**
  * Parse the incoming request and store the request params and meta data into
  * the class variables.
  * 
  * @return RestServer
  */
 public static function process_request()
 {
     $request_method = strtolower($_SERVER['REQUEST_METHOD']);
     $request_params = $_SERVER['REQUEST_URI'];
     $request_params = strstr($request_params, WS_API_BASE_DIR);
     $request_params = explode(DIRECTORY_SEPARATOR, $request_params);
     array_shift($request_params);
     $return_obj = new RestServer();
     $data = array();
     switch ($request_method) {
         case 'get':
             $data = $_GET;
             break;
         case 'post':
             $data = $_POST;
             break;
         case 'put':
             parse_str(file_get_contents('php://input'), $put_vars);
             $data = $put_vars;
             break;
     }
     $return_obj->set_method($request_method);
     $return_obj->set_params($request_params);
     $data = Validate::sanitize($data);
     $return_obj->set_request_vars($data);
     if (isset($data['data'])) {
         $return_obj->set_data(json_decode($data['data']));
     }
     return $return_obj;
 }