Exemplo n.º 1
0
 public static function processRequest()
 {
     global $logger;
     $request = $rawResponse = $response = null;
     try {
         /* Authenticate */
         $valid = self::authenticateRequest($_SERVER);
         /* Fetch POST data */
         $post = file_get_contents("php://input");
         $logger->debug("POST Data Received: " . $post);
         /* Formulate the request object */
         $request = RequestParser::parseInput($_SERVER, $_GET, $post);
         $logger->debug("REQUEST Object: " . $request->toString());
         /* Handle the request */
         $rawResponse = RequestHandler::process($request);
         $logger->debug("RESPONSE Object: " . json_encode($rawResponse));
     } catch (ApiException $e) {
         /* Generate response from Exception details */
         $logger->error("ApiException encountered!! " . $e->toString());
         $rawResponse = array('httpStatusCode' => $e->getHttpStatusCode(), 'httpStatusCodeMessage' => $e->getHttpStatusCodeMessage(), 'otherHeaders' => $e->getOtherHeaders(), 'code' => $e->getCode(), 'message' => $e->getMessage(), 'debug' => false, 'data' => null);
     }
     // Format the $rawResponse variable and output
     $format = !isset($request) ? 'json' : $request->getFormat();
     $debug = !isset($request) ? false : $request->getDebug();
     $response = ResponseHandler::respond($rawResponse, $format, $debug);
     $logger->debug("Output: " . $response);
 }