Ejemplo n.º 1
0
 public function RawRequest()
 {
     global $v2BatchDebug;
     if (!array_key_exists('CONTENT_TYPE', $_SERVER) && UrlUtils::RequestMethod() != "post") {
         HttpUtils::ApiError(405, "The HTTP verb used is not allowed.");
     }
     $a_data = array();
     // read incoming data
     $input = file_get_contents('php://input');
     if ($v2BatchDebug) {
         file_put_contents("batch.log", "REQUEST:" . $input . "\r\n", FILE_APPEND);
         file_put_contents("batch.log", "\r\n", FILE_APPEND);
     }
     // grab multipart boundary from content type header
     preg_match('/boundary=(.*)$/', $_SERVER['CONTENT_TYPE'], $matches);
     // content type is probably regular form-encoded
     if (!count($matches)) {
         return null;
     }
     $boundary = $matches[1];
     $parsed = $this->ParseData($boundary, $input);
     $result = array();
     if ($v2BatchDebug) {
         file_put_contents("batch.log", "PARSING:" . sizeof($parsed) . "\r\n", FILE_APPEND);
         file_put_contents("batch.log", "\r\n", FILE_APPEND);
     }
     for ($i = 0; $i < sizeof($parsed); $i++) {
         $item = $parsed[$i];
         $item->ResultStatus = 200;
         if ($item->Method == "get") {
             $item->ResultData = HttpUtils::HttpGet($item->Action);
         } else {
             if ($item->Method == "get") {
                 $item->ResultData = HttpUtils::HttpPost($item->Action, $item->Data, "application/atom+xml");
             }
         }
         array_push($result, $item);
     }
     $response = Batcher::Elaborate($result);
     if ($v2BatchDebug) {
         file_put_contents("batch.log", "RESULT:" . $response . "\r\n", FILE_APPEND);
         file_put_contents("batch.log", "\r\n", FILE_APPEND);
     }
 }