Skip to content

Commit

Permalink
Merge pull request #24 from Peardian/logtools
Browse files Browse the repository at this point in the history
All responses now stored and all can be retrieved
  • Loading branch information
carl689 committed Apr 28, 2014
2 parents b0ca8e2 + 2d7627a commit e9b7624
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions includes/classes/AmazonCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ abstract class AmazonCore{
protected $mockIndex = 0;
protected $logpath;
protected $env;
protected $lastResponse;
protected $rawResponses = array();

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

$this->lastResponse=$response;
$this->rawResponses[]=$response;
return $response;
}

/**
* Gives the last response code received from Amazon.
* @return int|boolean HTTP reponse code (200, 404, etc) or <b>FALSE</b> if not set yet
* Gives the latest response data received from Amazon.
* Response arrays contain the following keys:
* <ul>
* <li><b>head</b> - The raw HTTP head, including the response code and content length</li>
* <li><b>body</b> - The raw HTTP body, which will almost always be in XML format</li>
* <li><b>code</b> - The HTTP response code extracted from the head for convenience</li>
* <li><b>answer</b> - The HTTP response message extracted from the head for convenience</li>
* <li><b>ok</b> - Contains a <b>1</b> if the response was normal, or <b>0</b> if there was a problem</li>
* <li><b>headarray</b> - An associative array of the head data, for convenience</li>
* </ul>
* @param int $i [optional] <p>If set, retrieves the specific response instead of the last one.
* If the index for the response is not used, <b>FALSE</b> will be returned.</p>
* @return array associative array of HTTP response or <b>FALSE</b> if not set yet
*/
public function getLastResponse($i=NULL) {
if (!isset($i)) {
$i=count($this->rawResponses)-1;
}
if ($i >= 0 && isset($this->rawResponses[$i])) {
return $this->rawResponses[$i];
} else {
return false;
}
}

/**
* Gives all response code received from Amazon.
* @return array list of associative arrays of HTTP response or <b>FALSE</b> if not set yet
* @see getLastResponse
*/
public function getLastResponse() {
if (isset($this->lastResponse)) {
return $this->lastResponse;
public function getRawResponses() {
if (!empty($this->rawResponses)) {
return $this->rawResponses;
} else {
return false;
}
Expand Down

0 comments on commit e9b7624

Please sign in to comment.