Example #1
0
 /**
  * Creates a array of responses from the batch response body.
  * 
  * @param string            $body           The HTTP response body.
  * @param IMimeReaderWriter $mimeSerializer The MIME reader and writer.
  * 
  * @return array
  */
 private static function _constructResponses($body, $mimeSerializer)
 {
     $responses = array();
     $parts = $mimeSerializer->decodeMimeMultipart($body);
     // Decrease the count of parts to remove the batch response body and just
     // include change sets response body. We may need to undo this action in
     // case that batch response body has useful info.
     $count = count($parts);
     for ($i = 0; $i < $count; $i++) {
         $response = new \stdClass();
         // Split lines
         $lines = explode("\r\n", $parts[$i]);
         // Version Status Reason
         $statusTokens = explode(' ', $lines[0], 3);
         $response->version = $statusTokens[0];
         $response->statusCode = $statusTokens[1];
         $response->reason = $statusTokens[2];
         $headers = array();
         $j = 1;
         do {
             $headerLine = $lines[$j++];
             $headerTokens = explode(':', $headerLine);
             $headers[trim($headerTokens[0])] = isset($headerTokens[1]) ? trim($headerTokens[1]) : null;
         } while (Resources::EMPTY_STRING != $headerLine);
         $response->headers = $headers;
         $response->body = implode("\r\n", array_slice($lines, $j));
         $responses[] = $response;
     }
     return $responses;
 }
Example #2
0
 /**
  * Creates a array of responses from the batch response body.
  * 
  * @param string            $body           The HTTP response body.
  * @param IMimeReaderWriter $mimeSerializer The MIME reader and writer.
  * 
  * @return array
  */
 private static function _constructResponses($body, $mimeSerializer)
 {
     $responses = array();
     $parts = $mimeSerializer->decodeMimeMultipart($body);
     // Decrease the count of parts to remove the batch response body and just
     // include change sets response body. We may need to undo this action in
     // case that batch response body has useful info.
     $count = count($parts) - 1;
     for ($i = 0; $i < $count; $i++) {
         $lines = explode("\r\n", $parts[$i]);
         $response = new \HTTP_Request2_Response($lines[0]);
         $j = 1;
         do {
             $headerLine = $lines[$j++];
             $response->parseHeaderLine($headerLine);
         } while (Resources::EMPTY_STRING != $headerLine);
         $body = implode("\r\n", array_slice($lines, $j));
         $response->appendBody($body);
         $responses[] = $response;
     }
     return $responses;
 }