Skip to content

Commit e9b7624

Browse files
committed
Merge pull request #24 from Peardian/logtools
All responses now stored and all can be retrieved
2 parents b0ca8e2 + 2d7627a commit e9b7624

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

includes/classes/AmazonCore.php

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ abstract class AmazonCore{
105105
protected $mockIndex = 0;
106106
protected $logpath;
107107
protected $env;
108-
protected $lastResponse;
108+
protected $rawResponses = array();
109109

110110
/**
111111
* AmazonCore constructor sets up key information used in all Amazon requests.
@@ -590,17 +590,44 @@ protected function sendRequest($url,$param){
590590
$response = $this->fetchURL($url,$param);
591591
}
592592

593-
$this->lastResponse=$response;
593+
$this->rawResponses[]=$response;
594594
return $response;
595595
}
596596

597597
/**
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
600627
*/
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;
604631
} else {
605632
return false;
606633
}

0 commit comments

Comments
 (0)