本文整理汇总了PHP中Guzzle\Http\Message\RequestInterface::getResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::getResponse方法的具体用法?PHP RequestInterface::getResponse怎么用?PHP RequestInterface::getResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Message\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::getResponse方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: writeResponseBody
/**
* Write data to the response body of a request
*
* @param resource $curl Curl handle
* @param string $write Data that was received
*
* @return int
*/
public function writeResponseBody($curl, $write)
{
if ($this->emitIo) {
$this->request->dispatch('curl.callback.write', array('request' => $this->request, 'write' => $write));
}
return $this->request->getResponse()->getBody()->write($write);
}
示例2: add
/**
* Add a request to the history
*
* @param RequestInterface $request Request to add
* @param Response $response Response of the request
*
* @return HistoryPlugin
*/
public function add(RequestInterface $request, Response $response = null)
{
if (!$response && $request->getResponse()) {
$response = $request->getResponse();
}
$this->transactions[] = array('request' => $request, 'response' => $response);
if (count($this->transactions) > $this->getlimit()) {
array_shift($this->transactions);
}
return $this;
}
示例3: writeResponseBody
/**
* Write data to the response body of a request
*
* @param resource $curl Curl handle
* @param string $write Data that was received
*
* @return int
*/
public function writeResponseBody($curl, $write)
{
if ($this->emitIo) {
$this->request->dispatch('curl.callback.write', array('request' => $this->request, 'write' => $write));
}
if ($response = $this->request->getResponse()) {
return $response->getBody()->write($write);
} else {
// Unexpected data received before response headers - abort transfer
return 0;
}
}
示例4: __construct
/**
* Create a new response object from a Clickatell request and response.
*
* @param \Guzzle\Http\Message\RequestInterface $request The request object
* associated with the response.
* @throws \UnexpectedValueException when the request does not have a response.
*/
public function __construct($request)
{
$response = $request->getResponse();
if (!$response) {
throw new \UnexpectedValueException('Request must have have a response.');
}
$this->request = $request;
$this->parsedResponse = $this->parseBody($response->getBody());
}
示例5: add
/**
* Add a request to the history
*
* @param RequestInterface $request Request to add
*
* @return HistoryPlugin
*/
public function add(RequestInterface $request)
{
if ($request->getResponse()) {
$this->requests[] = $request;
if (count($this->requests) > $this->getlimit()) {
array_shift($this->requests);
}
}
return $this;
}
示例6: sendRequest
/**
* Sends a request
*
* @param RequestInterface $request
* @return Response
* @throws ForbiddenException
* @throws MetricaException
*/
protected function sendRequest(RequestInterface $request)
{
try {
$request->setHeader('User-Agent', $this->getUserAgent());
$response = $request->send();
} catch (ClientErrorResponseException $ex) {
$result = $request->getResponse();
$code = $result->getStatusCode();
$message = $result->getReasonPhrase();
if ($code === 403) {
throw new ForbiddenException($message);
}
throw new MetricaException('Service responded with error code: "' . $code . '" and message: "' . $message . '"');
}
return $response;
}
示例7: updateRequestFromTransfer
/**
* Update a request based on the log messages of the CurlHandle
*
* @param RequestInterface $request Request to update
*/
public function updateRequestFromTransfer(RequestInterface $request)
{
if (!$request->getResponse()) {
return;
}
// Update the transfer stats of the response
$request->getResponse()->setInfo($this->getInfo());
if (!($log = $this->getStderr(true))) {
return;
}
// Parse the cURL stderr output for outgoing requests
$headers = '';
fseek($log, 0);
while (($line = fgets($log)) !== false) {
if ($line && $line[0] == '>') {
$headers = substr(trim($line), 2) . "\r\n";
while (($line = fgets($log)) !== false) {
if ($line[0] == '*' || $line[0] == '<') {
break;
} else {
$headers .= trim($line) . "\r\n";
}
}
}
}
// Add request headers to the request exactly as they were sent
if ($headers) {
$parsed = ParserRegistry::getInstance()->getParser('message')->parseRequest($headers);
if (!empty($parsed['headers'])) {
$request->setHeaders(array());
foreach ($parsed['headers'] as $name => $value) {
$request->setHeader($name, $value);
}
}
if (!empty($parsed['version'])) {
$request->setProtocolVersion($parsed['version']);
}
}
}
示例8: validateResponseWasSet
/**
* @link https://github.com/guzzle/guzzle/issues/710
*/
private function validateResponseWasSet(RequestInterface $request)
{
if ($request->getResponse()) {
return true;
}
$body = $request instanceof EntityEnclosingRequestInterface ? $request->getBody() : null;
if (!$body) {
$rex = new RequestException('No response was received for a request with no body. This' . ' could mean that you are saturating your network.');
$rex->setRequest($request);
$this->removeErroredRequest($request, $rex);
} elseif (!$body->isSeekable() || !$body->seek(0)) {
// Nothing we can do with this. Sorry!
$rex = new RequestException('The connection was unexpectedly closed. The request would' . ' have been retried, but attempting to rewind the' . ' request body failed.');
$rex->setRequest($request);
$this->removeErroredRequest($request, $rex);
} else {
$this->remove($request);
// Add the request back to the batch to retry automatically.
$this->requests[] = $request;
$this->addHandle($request);
}
return false;
}
示例9: collectTime
/**
* Collect time for a Guzzle request
*
* @param Guzzle\Http\Message\RequestInterface $request
*
* @return array
*/
private function collectTime(GuzzleRequestInterface $request)
{
$response = $request->getResponse();
return array('total' => $response->getInfo('total_time'), 'connection' => $response->getInfo('connect_time'));
}
示例10: sendRequest
/**
* @param $request RequestInterface
* @return mixed
* @throws Exception
*/
private function sendRequest(RequestInterface $request)
{
try {
$request->send();
} catch (ClientErrorResponseException $e) {
$data = json_decode($request->getResponse()->getBody(true), true);
if ($e->getResponse()->getStatusCode() == 404) {
throw new CredentialsNotFoundException($data["message"], null, $e);
} else {
throw new Exception('Error from Provisioning API: ' . $data["message"], null, $e);
}
} catch (BadResponseException $e) {
throw new Exception('Error receiving response from Provisioning API', null, $e);
}
$result = $this->parseResponse($request->getResponse()->getBody(true));
return $result;
}
示例11: throwTooManyRedirectsException
/**
* Throw a too many redirects exception for a request
*
* @param RequestInterface $request Request
* @throws TooManyRedirectsException when too many redirects have been issued
*/
protected function throwTooManyRedirectsException(RequestInterface $request)
{
$lines = array();
$response = $request->getResponse();
do {
$lines[] = '> ' . $response->getRequest()->getRawHeaders() . "\n\n< " . $response->getRawHeaders();
$response = $response->getPreviousResponse();
} while ($response);
throw new TooManyRedirectsException("Too many redirects were issued for this transaction:\n" . implode("* Sending redirect request\n", array_reverse($lines)));
}
示例12: sendRequest
/**
* @param RequestInterface $request
* @return array
* @throws CommunicationError
* @throws ExpiredAuthRequestError
* @throws InvalidCredentialsError
* @throws InvalidRequestError
* @throws InvalidResponseError
* @throws LaunchKeyEngineError
* @throws NoPairedDevicesError
* @throws NoSuchUserError
* @throws RateLimitExceededError
*/
private function sendRequest(RequestInterface $request)
{
try {
$response = $request->send();
$this->debugLog("Response received", array("response" => $response->getMessage()));
} catch (ClientErrorResponseException $e) {
$message = $e->getMessage();
$code = $e->getCode();
try {
$data = $this->jsonDecodeData($request->getResponse()->getBody());
$this->throwExceptionForErrorResponse($data, $e);
} catch (InvalidResponseError $de) {
throw new InvalidRequestError($message, $code, $e);
}
} catch (ServerErrorResponseException $e) {
throw new CommunicationError("Error performing request", $e->getCode(), $e);
}
$data = $this->jsonDecodeData($response->getBody(true));
// If debug response with data in the "response" attribute return that
return isset($data["response"]) ? $data["response"] : $data;
}
示例13: throwTooManyRedirectsException
/**
* Throw a too many redirects exception for a request
*
* @param RequestInterface $request Request
* @throws TooManyRedirectsException when too many redirects have been issued
*/
protected function throwTooManyRedirectsException(RequestInterface $request)
{
$responses = array();
// Create a nice message to use when throwing the exception that shows each request/response transaction
do {
$response = $request->getResponse();
$responses[] = '> ' . $request->getRawHeaders() . "\n\n< " . $response->getRawHeaders();
$request = $response->getPreviousResponse() ? $response->getPreviousResponse()->getRequest() : null;
} while ($request);
$transaction = implode("* Sending redirect request\n", array_reverse($responses));
throw new TooManyRedirectsException("Too many redirects were issued for this transaction:\n{$transaction}");
}
示例14: runRequest
/**
* Run guzzle request
*
* @param RequestInterface $request
*
* @return array
*/
private function runRequest(RequestInterface $request)
{
try {
$request->send();
//send the req and return the json
return $request->getResponse()->json();
} catch (Exception $e) {
return array('error' => $request->getResponse()->json());
}
}