本文整理汇总了PHP中Guzzle\Http\Message\Response::getHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::getHeaders方法的具体用法?PHP Response::getHeaders怎么用?PHP Response::getHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Message\Response
的用法示例。
在下文中一共展示了Response::getHeaders方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: request
/**
* Returns object with properties int:status object:body
* @param string $method
* @param string $path
* @param array $query
* @param bool $doAuth
* @throws \InvalidArgumentException
* @throws \Exception
* @return \stdClass
*/
public function request($method, $path, $query = array(), $doAuth = false)
{
$this->userAgent = 'Rocker REST Client v' . Server::VERSION;
$method = strtolower($method);
$request = $this->initiateRequest($method, $path, $query);
if ($doAuth) {
$this->addAuthHeader($request);
}
try {
$this->lastResponse = $request->send();
} catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {
$this->lastResponse = $e->getResponse();
if ($this->lastResponse->getStatusCode() == 401 && !$doAuth && !empty($this->user)) {
trigger_error('Doing unauthenticated requests to an URI that requires authentication (' . $path . ')', E_WARNING);
return $this->request($method, $path, $query, true);
}
}
if ($this->lastResponse->getStatusCode() == 400) {
throw new ClientException($this->lastResponse, 400);
}
if ($this->lastResponse->getStatusCode() == 204) {
return (object) array('status' => 204, 'body' => array());
}
if (strpos($this->lastResponse->getContentType(), 'json') === false) {
throw new ClientException($this->lastResponse, ClientException::ERR_UNEXPECTED_CONTENT_TYPE, 'Server responded with unexpected content type (' . $this->lastResponse->getContentType() . ')');
}
$str = (string) $this->lastResponse->getBody();
$body = json_decode($str);
return (object) array('status' => $this->lastResponse->getStatusCode(), 'headers' => $this->headerCollectionToArray($this->lastResponse->getHeaders()), 'body' => $body);
}
示例2: getResponseHeaders
public function getResponseHeaders()
{
$headers = array();
foreach ($this->response->getHeaders()->getAll() as $header => $headerObject) {
$allHeaderValues = $headerObject->toArray();
// only getting the first of the array, most of the cases this will
// work as expected
$headers[$header] = $allHeaderValues[0];
}
return $headers;
}
示例3: fromResponse
/**
* Factory method that allows for easy instantiation from a Response object.
*
* @param Response $response
* @param AbstractService $service
* @return static
*/
public static function fromResponse(Response $response, AbstractService $service)
{
$object = new static($service);
if (null !== ($headers = $response->getHeaders())) {
$object->setMetadata($headers, true);
}
return $object;
}
示例4: getHeaders
/**
* Get all response headers.
*
* @return array Associative array with $header => $value (value can be an array if it hasn't a single value)
*
* @throws \RuntimeException If request hasn't been send already
*/
public function getHeaders()
{
$headers = array();
foreach ($this->response->getHeaders()->getAll() as $header => $headerObject) {
$allHeaderValues = $headerObject->toArray();
$headers[strtolower($header)] = implode(';', $allHeaderValues);
}
return $headers;
}
示例5: getHeaders
/**
* Returns a list of headers as key/value pairs.
*
* @return array List of headers as key/value pairs.
*/
public function getHeaders()
{
$headers = array();
foreach (parent::getHeaders() as $header) {
$values = $header->toArray();
$headers[$header->getName()] = $values[0];
}
return $headers;
}
示例6: createResponse
/**
* Prepares an EmbeddedResponse from the original response and data
*
* @param Guzzle\Http\Message\Response $originalResponse
* @param array $data
*
* @return Desk\Relationship\Resource\EmbeddedResponse
*/
public function createResponse(Response $originalResponse, array $data)
{
$statusCode = $originalResponse->getStatusCode();
$reasonPhrase = $originalResponse->getReasonPhrase();
$headers = $originalResponse->getHeaders();
$body = json_encode($data);
// set reason phrase -- needs to be done vie
$response = $this->newResponse($statusCode, $headers, $body);
$response->setReasonPhrase($reasonPhrase);
return $response;
}
示例7: processPrefixedHeaders
protected function processPrefixedHeaders(Response $response, Parameter $param, &$value)
{
if ($prefix = $param->getSentAs()) {
$container = $param->getName();
$len = strlen($prefix);
foreach ($response->getHeaders()->toArray() as $key => $header) {
if (stripos($key, $prefix) === 0) {
$value[$container][substr($key, $len)] = count($header) == 1 ? end($header) : $header;
}
}
}
}
示例8: getMock
/**
* @param array $responseCollection
* @return \CanalTP\AbstractGuzzle\Guzzle
*/
public function getMock(array $responseCollection)
{
$plugin = new MockPlugin();
foreach ($responseCollection as $response) {
if ($response instanceof Psr7Response) {
$response = new Response($response->getStatusCode(), $response->getHeaders(), $response->getBody());
}
$plugin->addResponse($response);
}
$client = GuzzleFactory::createClient('');
$client->addSubscriber($plugin);
return $client;
}
示例9: createResponse
/**
* Reads response meta tags to guess content-type charset.
*/
protected function createResponse(GuzzleResponse $response)
{
$body = $response->getBody(true);
$statusCode = $response->getStatusCode();
$headers = $response->getHeaders()->getAll();
$contentType = $response->getContentType();
if (!$contentType || false === strpos($contentType, 'charset=')) {
if (preg_match('/\\<meta[^\\>]+charset *= *["\']?([a-zA-Z\\-0-9]+)/i', $body, $matches)) {
$contentType .= ';charset=' . $matches[1];
}
}
$headers['Content-Type'] = $contentType;
return new Response($body, $statusCode, $headers);
}
示例10: processPrefixedHeaders
/**
* Process a prefixed header array
*
* @param Response $response Response that contains the headers
* @param Parameter $param Parameter object
* @param array $value Value response array to modify
*/
protected function processPrefixedHeaders(Response $response, Parameter $param, &$value)
{
// Grab prefixed headers that should be placed into an array with the prefix stripped
if ($prefix = $param->getSentAs()) {
$container = $param->getName();
$len = strlen($prefix);
// Find all matching headers and place them into the containing element
foreach ($response->getHeaders() as $key => $header) {
if (stripos($key, $prefix) === 0) {
// Account for multi-value headers
$value[$container][substr($key, $len)] = count($header) == 1 ? end($header) : $header;
}
}
}
}
示例11: cache
/**
* {@inheritdoc}
*/
public function cache($key, Response $response, $ttl = null)
{
if ($ttl === null) {
$ttl = $this->defaultTtl;
}
if ($ttl) {
$response->setHeader('X-Guzzle-Cache', "key={$key}, ttl={$ttl}");
// Remove excluded headers from the response (see RFC 2616:13.5.1)
foreach ($this->excludeResponseHeaders as $header) {
$response->removeHeader($header);
}
// Add a Date header to the response if none is set (for validation)
if (!$response->getDate()) {
$response->setHeader('Date', Utils::getHttpDate('now'));
}
$this->cache->save($key, array($response->getStatusCode(), $response->getHeaders()->getAll(), $response->getBody(true)), $ttl);
}
}
示例12: cache
public function cache($key, Response $response, $ttl = null)
{
if ($ttl === null) {
$ttl = $this->defaultTtl;
}
$ttl += $response->getMaxAge();
if ($ttl) {
$response->setHeader('X-Guzzle-Cache', "key={$key}; ttl={$ttl}");
// Remove excluded headers from the response (see RFC 2616:13.5.1)
foreach ($this->excludeResponseHeaders as $header) {
$response->removeHeader($header);
}
// Add a Date header to the response if none is set (for validation)
if (!$response->getDate()) {
$response->setHeader('Date', gmdate(ClientInterface::HTTP_DATE));
}
$this->cache->save($key, array($response->getStatusCode(), $response->getHeaders()->toArray(), $response->getBody(true)), $ttl);
}
}
示例13: createResponse
protected function createResponse(GuzzleResponse $response)
{
$headers = $response->getHeaders()->toArray();
return new Response($response->getBody(true), $response->getStatusCode(), $headers);
}
示例14: populateFromResponse
/**
* Takes a response and stocks common values from both the body and the headers.
*
* @param Response $response
* @return $this
*/
public function populateFromResponse(Response $response)
{
$this->content = $response->getBody();
$headers = $response->getHeaders();
return $this->setMetadata($headers, true)->setContentType((string) $headers['Content-type'])->setLastModified((string) $headers['Last-Modified'])->setContentLength((string) $headers['Content-Length'])->setEtag((string) $headers['ETag']);
}
示例15: getHeaders
/**
* @param bool $asObjects
* @return \Guzzle\Common\Collection
*/
public function getHeaders($asObjects = false)
{
return $this->response->getHeaders($asObjects);
}