@@ -105,7 +105,7 @@ abstract class AmazonCore{
105
105
protected $ mockIndex = 0 ;
106
106
protected $ logpath ;
107
107
protected $ env ;
108
- protected $ lastResponse ;
108
+ protected $ rawResponses = array () ;
109
109
110
110
/**
111
111
* AmazonCore constructor sets up key information used in all Amazon requests.
@@ -590,17 +590,44 @@ protected function sendRequest($url,$param){
590
590
$ response = $ this ->fetchURL ($ url ,$ param );
591
591
}
592
592
593
- $ this ->lastResponse =$ response ;
593
+ $ this ->rawResponses [] =$ response ;
594
594
return $ response ;
595
595
}
596
596
597
597
/**
598
- * Gives the last response code received from Amazon.
599
- * @return int|boolean HTTP reponse code (200, 404, etc) or <b>FALSE</b> if not set yet
598
+ * Gives the latest response data received from Amazon.
599
+ * Response arrays contain the following keys:
600
+ * <ul>
601
+ * <li><b>head</b> - The raw HTTP head, including the response code and content length</li>
602
+ * <li><b>body</b> - The raw HTTP body, which will almost always be in XML format</li>
603
+ * <li><b>code</b> - The HTTP response code extracted from the head for convenience</li>
604
+ * <li><b>answer</b> - The HTTP response message extracted from the head for convenience</li>
605
+ * <li><b>ok</b> - Contains a <b>1</b> if the response was normal, or <b>0</b> if there was a problem</li>
606
+ * <li><b>headarray</b> - An associative array of the head data, for convenience</li>
607
+ * </ul>
608
+ * @param int $i [optional] <p>If set, retrieves the specific response instead of the last one.
609
+ * If the index for the response is not used, <b>FALSE</b> will be returned.</p>
610
+ * @return array associative array of HTTP response or <b>FALSE</b> if not set yet
611
+ */
612
+ public function getLastResponse ($ i =NULL ) {
613
+ if (!isset ($ i )) {
614
+ $ i =count ($ this ->rawResponses )-1 ;
615
+ }
616
+ if ($ i >= 0 && isset ($ this ->rawResponses [$ i ])) {
617
+ return $ this ->rawResponses [$ i ];
618
+ } else {
619
+ return false ;
620
+ }
621
+ }
622
+
623
+ /**
624
+ * Gives all response code received from Amazon.
625
+ * @return array list of associative arrays of HTTP response or <b>FALSE</b> if not set yet
626
+ * @see getLastResponse
600
627
*/
601
- public function getLastResponse () {
602
- if (isset ($ this ->lastResponse )) {
603
- return $ this ->lastResponse ;
628
+ public function getRawResponses () {
629
+ if (! empty ($ this ->rawResponses )) {
630
+ return $ this ->rawResponses ;
604
631
} else {
605
632
return false ;
606
633
}
0 commit comments