Exemplo n.º 1
0
 public static function processRequest()
 {
     // get our verb
     $request_method = strtolower($_SERVER['REQUEST_METHOD']);
     $return_obj = new RestRequest();
     // we'll store our data here
     $data = array();
     // only POST is available
     switch ($request_method) {
         case 'post':
             $data = $_POST;
             break;
     }
     // store the method
     $return_obj->setMethod($request_method);
     // set the raw data, so we can access it if needed (there may be
     // other pieces to your requests)
     $return_obj->setRequestVars($data);
     if (isset($data['service'])) {
         // translate the JSON to an Object for use however you want
         $return_obj->setService($data['service']);
     }
     if (isset($data['text'])) {
         $return_obj->setTextToProc($data['text']);
     }
     return $return_obj;
 }
Exemplo n.º 2
0
 public static function processRequest()
 {
     // get the request method
     $request_method = strtolower($_SERVER['REQUEST_METHOD']);
     $return_obj = new RestRequest();
     // store the request data
     $data = array();
     switch ($request_method) {
         // put data
         case 'put':
             $data = $_GET;
             break;
             // get data
         // get data
         case 'get':
             $data = $_GET;
             break;
             // post request
         // post request
         case 'post':
             $data = $_POST;
             break;
     }
     // store the method
     $return_obj->setMethod($request_method);
     // set the raw data, so we can access it if needed (there may be
     // other pieces to your requests)
     $return_obj->setRequestVars($data);
     if (isset($data['data'])) {
         // translate the JSON to an Object for use however you want
         $return_obj->setData($json->decode($data['data']));
     }
     return $return_obj;
 }
 public static function processRequest()
 {
     // get our verb
     $request_method = strtolower($_SERVER['REQUEST_METHOD']);
     $return_obj = new RestRequest();
     // we'll store our data here
     $data = array();
     switch ($request_method) {
         case 'get':
             $data = $_GET;
             break;
         case 'post':
             $data = $_POST;
             break;
         case 'put':
             // 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.
             parse_str(file_get_contents('php://input'), $put_vars);
             $data = $put_vars;
             break;
     }
     // store the method
     $return_obj->setMethod($request_method);
     // set the raw data, so we can access it if needed (there may be
     // other pieces to your requests)
     $return_obj->setRequestVars($data);
     if (isset($data['data'])) {
         // translate the JSON to an Object for use however you want
         $return_obj->setData(json_decode($data['data']));
     }
     return $return_obj;
 }
Exemplo n.º 4
0
 public static function processRequest()
 {
     $request_method = strtolower($_SERVER['REQUEST_METHOD']);
     $return_obj = new RestRequest();
     $data = array();
     switch ($request_method) {
         case 'get':
             $data = $_GET;
             break;
         case 'post':
             $data = $_POST;
             break;
         case 'put':
             // 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.
             parse_str(file_get_contents('php://input'), $put_vars);
             $data = $put_vars;
             break;
     }
     $return_obj->setMethod($request_method);
     $return_obj->setRequestVars($data);
     if (isset($data['data'])) {
         $return_obj->setData(json_decode($data['data']));
     }
     return $return_obj;
 }
Exemplo n.º 5
0
 public static function processRequest()
 {
     // get our verb
     $request_method = strtolower($_SERVER['REQUEST_METHOD']);
     $return_obj = new RestRequest();
     // store the method
     $return_obj->setMethod($request_method);
     //06.08.2012 naj - parse the uri elements
     $urirequest = $_SERVER['REQUEST_URI'];
     switch ($request_method) {
         case 'get':
             //here we need to strip off only the method call that was
             //tagged at the end of the URL
             $pos = strpos($urirequest, '?');
             $requesttype = strtolower(substr($urirequest, 1, $pos - 1));
             $urirequest = substr($urirequest, $pos + 1);
             parse_str($urirequest, $data);
             break;
         case 'post':
             $pos = strpos($urirequest, '?');
             $requesttype = strtolower(substr($urirequest, 1, $pos - 1));
             $urirequest = substr($urirequest, $pos + 1);
             parse_str($urirequest, $data);
             $data['Data'] = $_POST;
             break;
     }
     //06.08.2012 naj - set the request type
     $return_obj->setRequestType($requesttype);
     //06.08.2012 naj - set the request vars
     $return_obj->setRequestVars($data);
     return $return_obj;
 }
Exemplo n.º 6
0
 public static function processRequest()
 {
     // get our verb
     $request_method = strtolower($_SERVER['REQUEST_METHOD']);
     $return_obj = new RestRequest();
     // we'll store our data here
     $data = array();
     switch ($request_method) {
         // gets are easy...
         case 'get':
             $data = $_GET;
             break;
             // so are posts
         // so are posts
         case 'post':
             $data = $_POST;
             break;
             // here's the tricky bit...
         // here's the tricky bit...
         case 'put':
             parse_str(file_get_contents('php://input'), $put_vars);
             $data = $put_vars;
             break;
     }
     // store the method
     $return_obj->setMethod($request_method);
     // set the raw data, so we can access it if needed (there may be
     // other pieces to your requests)
     $return_obj->setRequestVars($data);
     if (isset($data['data'])) {
         // translate the JSON to an Object for use however you want
         $return_obj->setData(json_decode($data['data']));
     }
     return $return_obj;
 }
Exemplo n.º 7
0
 public static function initProcess()
 {
     $requestMethod = strtolower($_SERVER['REQUEST_METHOD']);
     $obj = new RestRequest();
     $data = array();
     $files = array();
     $_PUT_VARS = null;
     switch ($requestMethod) {
         case 'get':
             $data = $_GET;
             break;
         case 'post':
             $data = $_POST;
             if (isset($_FILES) && !empty($_FILES)) {
                 $files = $_FILES;
             }
             break;
         case 'put':
             parse_str(file_get_contents('php://input'), $_PUT_VARS);
             $data = $_PUT_VARS;
             break;
     }
     $obj->setMethod($requestMethod);
     $obj->setRequestVars($data);
     if (isset($data['data'])) {
         $obj->setData(json_decode($data['data']));
     }
     if (isset($files)) {
         $obj->setFiles($files);
     }
     return $obj;
 }
Exemplo n.º 8
0
 public static function processRequest()
 {
     include 'config.php';
     $auth_username = $user;
     $auth_pass = $password;
     // figure out if we need to challenge the user
     if (empty($_SERVER['PHP_AUTH_DIGEST'])) {
         header('HTTP/1.1 401 Unauthorized');
         header('WWW-Authenticate: Digest realm="' . AUTH_REALM . '",qop="auth",nonce="' . uniqid() . '",opaque="' . md5(AUTH_REALM) . '"');
         // show the error if they hit cancel
         die(RestUtils::sendResponse(401));
     }
     // now, analayze the PHP_AUTH_DIGEST var
     if (!($data = self::http_digest_parse($_SERVER['PHP_AUTH_DIGEST'])) || $auth_username != $data['username']) {
         // show the error due to bad auth
         die(RestUtils::sendResponse(401));
     }
     // so far, everything's good, let's now check the response a bit more...
     $A1 = md5($data['username'] . ':' . AUTH_REALM . ':' . $auth_pass);
     $A2 = md5($_SERVER['REQUEST_METHOD'] . ':' . $data['uri']);
     $valid_response = md5($A1 . ':' . $data['nonce'] . ':' . $data['nc'] . ':' . $data['cnonce'] . ':' . $data['qop'] . ':' . $A2);
     // last check..
     if ($data['response'] != $valid_response) {
         die(RestUtils::sendResponse(401));
     }
     // get our verb
     $request_method = strtolower($_SERVER['REQUEST_METHOD']);
     $return_obj = new RestRequest();
     // we'll store our data here
     $data = array();
     if (strcmp($request_method, 'post') == 0) {
         $data = $_POST;
         // store the method
         $return_obj->setMethod($request_method);
         // set the raw data, so we can access it if needed (there may be
         // other pieces to your requests)
         $return_obj->setRequestVars($data);
         if (isset($data['data'])) {
             // translate the JSON to an Object for use however you want
             $return_obj->setData(json_decode($data['data']));
         }
         return $return_obj;
     }
 }
Exemplo n.º 9
0
 public static function processRequest()
 {
     // cogemos el metodo
     $request_method = strtolower($_SERVER['REQUEST_METHOD']);
     $return_obj = new RestRequest();
     // aqui almacenaremos los datos$data = array();
     switch ($request_method) {
         // para get y post esto sera sencillo
         case 'get':
             $data = $_GET;
             break;
         case 'post':
             $data = $_POST;
             break;
             // Aqui esta lo "complicado"
         // Aqui esta lo "complicado"
         case 'put':
             //para put y delete usamos una cadena desde una localizacion de inputespecial de PHP y la parseamos con parse_str.
             parse_str(file_get_contents('php://input'), $put_vars);
             $data = $put_vars;
             break;
         case 'delete':
             $data = '';
             //delete no acepta parametros
             break;
     }
     // almacenamos el metodo
     $return_obj->setMethod($request_method);
     // Almacenamos los parametros pasados en crudo, por si necesitamo sacceder a ellos
     $return_obj->setRequestVars($data);
     if (isset($data['data'])) {
         // asumimos que los datos estan pasados en forjato JSON
         $return_obj->setData(json_decode($data['data']));
     } else {
         if ($request_method == "get") {
             $return_obj->setData($data);
         }
     }
     return $return_obj;
 }
Exemplo n.º 10
0
 public static function processRequest()
 {
     $request_method = strtolower($_SERVER['REQUEST_METHOD']);
     $return_obj = new RestRequest();
     // store our data here
     $data = array();
     switch ($request_method) {
         case 'get':
             $data = $_GET;
             break;
         case 'post':
             $data = $_POST;
             break;
     }
     $return_obj->setMethod($request_method);
     $return_obj->setRequestVars($data);
     if (isset($data['data'])) {
         // translate the JSON to an Object for use however we want
         $return_obj->setData(json_decode($data['data'], true));
     }
     return $return_obj;
 }
Exemplo n.º 11
0
 public static function processRequest()
 {
     // get our verb
     $request_method = strtolower($_SERVER['REQUEST_METHOD']);
     $return_obj = new RestRequest();
     // we'll store our query here
     $query = array();
     switch ($request_method) {
         // gets are easy...
         case 'get':
             $query = $_GET;
             break;
             // so are posts
         // so are posts
         case 'post':
             $query = $_POST;
             break;
             // here's the tricky bit...
         // here's the tricky bit...
         case 'put':
             // 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.
             parse_str(file_get_contents('php://input'), $put_vars);
             $query = $put_vars;
             break;
     }
     // store the method
     $return_obj->setMethod($request_method);
     $request_vars = explode('/', $_GET['url']);
     $return_obj->setRequestVars($request_vars);
     $data = $query;
     unset($data['url']);
     $return_obj->setData($data);
     return $return_obj;
 }
Exemplo n.º 12
0
 public static function processRequest()
 {
     // get our verb
     $request_method = strtolower($_SERVER['REQUEST_METHOD']);
     $return_obj = new RestRequest();
     // we'll store our data here
     $data = array();
     $pathArray = array();
     $pathURIArray = array();
     $pathURIArray = parse_url(strtolower($_SERVER["REQUEST_URI"]));
     // breaks the query string and path out
     // strip leading '/' TO DO - I was stripping the leading '/' - why was this? Win / Linux diff?
     // $path = $pathURIArray['path'];
     //	if (strlen($path) > 1 && substr($path,0,1) ==='/') {
     //		$path = substr($path, 1, strlen($path)-1);
     //	}
     // modified to use trim and to strip the first and final /
     // isset reqd for www.mydomain.com//news caused error
     if (isset($pathURIArray['path'])) {
         $path = trim($pathURIArray['path'], '/');
     } else {
         $path = "";
     }
     $pathArray = explode("/", $path);
     // error_log(print_r($pathArray,true));
     $return_obj->setPathArray($pathArray);
     // Get the URL variables / POST variables
     switch ($request_method) {
         // gets are easy...
         case 'get':
             // it's not as simple is the example I started from.  I'm looking for a ? in the URI as couldn't just use isset($_GET).
             //error_log($pathURI . ' - ' . strpos($pathURI, '?'));
             if (strpos($_SERVER["REQUEST_URI"], '?') !== FALSE) {
                 $data = $_GET;
                 //error_log (print_r($_GET,true));
                 //error_log (print_r($data,true));
             }
             //				else {
             //					$data = $pathURIArray;
             //				}
             break;
             // so are posts
             // TO DO TEST THIS
         // so are posts
         // TO DO TEST THIS
         case 'post':
             $data = $_POST;
             break;
             // here's the tricky bit...
             // TO DO TEST THIS
         // here's the tricky bit...
         // TO DO TEST THIS
         case 'put':
             // 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.
             parse_str(file_get_contents('php://input'), $put_vars);
             $data = $put_vars;
             break;
     }
     // store the method
     $return_obj->setMethod($request_method);
     // 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;
 }
Exemplo n.º 13
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;
 }
Exemplo n.º 14
0
 public static function processRequest()
 {
     //Get our request method and data storage var
     $request_method = strtolower($_SERVER['REQUEST_METHOD']);
     $return_obj = new RestRequest();
     $data = array();
     //Verify request method
     switch ($request_method) {
         //GET
         case 'get':
             $data = $_GET;
             break;
             //POST
         //POST
         case 'post':
             $data = $_POST;
             break;
             //PUT
         //PUT
         case 'put':
             parse_str(file_get_contents('php://input'), $put_vars);
             $data = $put_vars;
             break;
             //DELETE
         //DELETE
         case 'delete':
             $data = $_GET;
             break;
             //OTHERS
         //OTHERS
         default:
             $data = $_GET;
             break;
     }
     //Store the method
     if (isset($_SERVER['HTTP_METHOD'])) {
         $request_method = strtolower($_SERVER['HTTP_METHOD']);
     } elseif (isset($data['method'])) {
         $request_method = strtolower($data['method']);
     }
     $return_obj->setMethod($request_method);
     //Store the data
     $return_obj->setRequestVars($data);
     //Store the JSON object
     if (isset($data['data'])) {
         $return_obj->setData(json_decode($data['data']));
     } else {
         $return_obj->setData($data);
     }
     //Return
     return $return_obj;
 }
Exemplo n.º 15
0
 public static function processRequest()
 {
     // What is the method used ?
     $request_method = strtolower($_SERVER['REQUEST_METHOD']);
     $request = new RestRequest();
     // Storing the requested data
     $data = array();
     switch ($request_method) {
         /* *** GET *** */
         case 'get':
             // Because of the htaccess ...
             // Extra parameters in the request URI
             $params = array();
             $parts = preg_split("~=|&~", $_SERVER['REQUEST_URI'], -1, PREG_SPLIT_NO_EMPTY);
             // Skip through the segments by 2
             for ($i = 0; $i < count($parts); $i = $i + 2) {
                 // First segment needs a lift because it contains the script name (method actually)
                 if ($i == 0) {
                     $parts[$i] = preg_replace("/(\\/[^\\?]*\\?)(.*)/", "\$2", $parts[$i]);
                 }
                 if (isset($parts[$i]) && isset($parts[$i + 1])) {
                     // First segment is the param name, second is the value
                     $params[$parts[$i]] = $parts[$i + 1];
                 }
             }
             $data = $params;
             $request->validateRequest();
             break;
             /* *** POST *** */
         /* *** POST *** */
         case 'post':
             $data = $_POST;
             $request->invalidateRequest();
             break;
             /* *** PUT *** */
         /* *** PUT *** */
         case 'put':
             // 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.
             parse_str(file_get_contents('php://input'), $put_vars);
             $data = $put_vars;
             $request->invalidateRequest();
             break;
     }
     // Storing the data into data (redundant for GET, but well)
     $request->setData((object) $data);
     // Storing the method used
     $request->setMethod($request_method);
     // Set the raw data, so we can access it if needed (there may be
     // other pieces to your requests)
     $request->setRequestVars($data);
     // If we have data (as per in a post request), we store it
     if (isset($data['data'])) {
         // translate the JSON to an Object for use however you want
         $request->setData(json_decode($data['data']));
     }
     // If we force JSON or XML instead of ACCEPT
     if (isset($data['alt']) && ($data['alt'] == 'json' || $data['alt'] == 'xml')) {
         $request->setHttpAccept($data['alt']);
     }
     return $request;
 }