本文整理汇总了PHP中GuzzleHttp\Psr7\Response::getHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::getHeaders方法的具体用法?PHP Response::getHeaders怎么用?PHP Response::getHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Psr7\Response
的用法示例。
在下文中一共展示了Response::getHeaders方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dump
public function dump($extended = false)
{
if ($extended) {
dump($this->response->getStatusCode());
dump($this->response->getHeaders());
}
dd($this->result);
}
示例2: deduce
/**
* @return ErrorResponse|SuccessResponse
*/
public function deduce()
{
/* @var array $response */
$response = (array) json_decode($this->response->getBody()->getContents());
if (array_key_exists('type', $response) && $response['type'] === 'error') {
return new ErrorResponse($this->response->getStatusCode(), $this->response->getHeaders(), $this->response->getBody());
}
return new SuccessResponse($this->response->getStatusCode(), $this->response->getHeaders(), $this->response->getBody());
}
示例3: isError
protected function isError(Response $response)
{
if (\array_get($response->getHeaders(), 'RETS-Error', [null])[0] == 1) {
return true;
}
$content_type = \array_get($response->getHeaders(), 'Content-Type', [null])[0];
if ($content_type and strpos($content_type, 'xml') !== false) {
return true;
}
return false;
}
示例4: lastResponseHeaders
/**
* Returns the SOAP headers from the last response.
*
* @return mix The last SOAP response headers.
*/
public function lastResponseHeaders()
{
if ($this->response instanceof Response) {
return $this->response->getHeaders();
}
return [];
}
示例5: getHeaders
/**
* Get the response headers as an array.
*
* @return array
* @throws \Hedii\ZoteroApi\Exceptions\BadMethodCallException
*/
public function getHeaders()
{
if (!$this->response) {
throw new BadMethodCallException('Cannot call getHeaders() on null');
}
return $this->response->getHeaders();
}
示例6: Response
function it_should_encode_a_responses_collection()
{
$response = new Response(200);
$responses = array($response);
$format = ['code' => $response->getStatusCode(), 'headers' => $response->getHeaders(), 'body' => (string) $response->getBody()];
$formatted = json_encode(array($format), JSON_PRETTY_PRINT);
$this->encodeResponsesCollection($responses)->shouldEqual($formatted);
}
示例7: setParams
/**
* Set Values to the class members
*
* @param Response $response
*/
private function setParams(Response $response)
{
$this->protocol = $response->getProtocolVersion();
$this->statusCode = (int) $response->getStatusCode();
$this->headers = $response->getHeaders();
$this->body = json_decode($response->getBody()->getContents());
$this->extractBodyParts();
}
示例8: createLocalResponse
/**
* Attempt to create local response type from guzzle response
*
* @param GuzzleResponse $guzzleResponse
*
* @return Response
*/
protected static function createLocalResponse(GuzzleResponse $guzzleResponse)
{
$response = new Response($guzzleResponse->getBody(), $guzzleResponse->getStatusCode());
$headers = $guzzleResponse->getHeaders();
array_walk($headers, function ($values, $name) use($response) {
$response->header($name, implode(', ', $values), true);
});
return $response;
}
示例9: __construct
/**
* ServerResponseException constructor.
*
* @param GuzzleResponse $response
*/
public function __construct(GuzzleResponse $response)
{
$code = $response->getStatusCode();
$responseHeader = $response->getHeaders();
$responseBody = $response->getBody()->getContents();
if (array_keys($responseHeader, "Retry-After")) {
$this->retryAfter = $responseHeader["Retry-After"];
}
parent::__construct($responseBody, $code);
}
示例10: getSerializedResponse
protected function getSerializedResponse(Response $response)
{
$cached = new \SplFixedArray(5);
$cached[0] = $response->getStatusCode();
$cached[1] = $response->getHeaders();
$cached[2] = $response->getBody()->__toString();
$cached[3] = $response->getProtocolVersion();
$cached[4] = $response->getReasonPhrase();
return serialize($cached);
}
示例11: out
/**
* @param Response $response
*/
function out(Response $response)
{
header(sprintf('%s %s %s', $response->getProtocolVersion(), $response->getStatusCode(), $response->getReasonPhrase()));
foreach ($response->getHeaders() as $name => $values) {
foreach ($values as $value) {
header(sprintf('%s: %s', $name, $value), false);
}
}
stream_copy_to_stream(\GuzzleHttp\Psr7\StreamWrapper::getResource($response->getBody()), fopen('php://output', 'w'));
}
示例12: formatResponse
private function formatResponse(Response $response)
{
$headers = array();
foreach ($response->getHeaders() as $key => $values) {
foreach ($values as $value) {
$headers[] = sprintf('%s: %s', $key, $value);
}
}
return sprintf("%s\n\n%s", implode("\n", $headers), $response->getBody());
}
示例13: completed
/**
*
*/
public function completed()
{
//echo '#';
$response = new Response($this->response->getStatusCode(), $this->response->getHeaders(), $this->buffer);
foreach ($this->observers as $observer) {
/* @var \Rx\ObserverInterface $observer */
$observer->onNext($response);
$observer->onCompleted();
}
$this->onCompleted();
$this->buffer = "";
}
示例14: doExecute
/**
* Executes a Psr\Http\Message\RequestInterface
*
* @param Google_Client $client
* @param Psr\Http\Message\RequestInterface $request
* @return array decoded result
* @throws Google_Service_Exception on server side error (ie: not authenticated,
* invalid or malformed post body, invalid url)
*/
public static function doExecute(ClientInterface $client, RequestInterface $request, $expectedClass = null)
{
try {
$httpHandler = HttpHandlerFactory::build($client);
$response = $httpHandler($request);
} catch (RequestException $e) {
// if Guzzle throws an exception, catch it and handle the response
if (!$e->hasResponse()) {
throw $e;
}
$response = $e->getResponse();
// specific checking for Guzzle 5: convert to PSR7 response
if ($response instanceof \GuzzleHttp\Message\ResponseInterface) {
$response = new Response($response->getStatusCode(), $response->getHeaders() ?: [], $response->getBody(), $response->getProtocolVersion(), $response->getReasonPhrase());
}
}
return self::decodeHttpResponse($response, $request, $expectedClass);
}
示例15: sendResponse
/**
* Will send the response, standard PHP way
*
* @param Response $response
* @return null
*/
public function sendResponse($response)
{
header("HTTP/" . $response->getProtocolVersion() . " " . $response->getStatusCode() . " " . $response->getReasonPhrase());
foreach ($response->getHeaders() as $name => $values) {
foreach ($values as $value) {
header(sprintf('%s: %s', $name, $value), false);
}
}
$body = $response->getBody();
while (!$body->eof()) {
$buf = $body->read(1048576);
// Using a loose equality here to match on '' and false.
if ($buf == null) {
break;
} else {
echo $buf;
}
}
}