当前位置: 首页>>代码示例>>PHP>>正文


PHP Response::getHeaders方法代码示例

本文整理汇总了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);
 }
开发者ID:NavalKishor,项目名称:PHP-Rocker,代码行数:40,代码来源:Client.php

示例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;
 }
开发者ID:brookinsconsulting,项目名称:ezecosystem,代码行数:11,代码来源:GuzzleClient.php

示例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;
 }
开发者ID:huhugon,项目名称:sso,代码行数:15,代码来源:AbstractResource.php

示例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;
 }
开发者ID:ezsystems,项目名称:ezpublish-kernel,代码行数:16,代码来源:GuzzleDriver.php

示例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;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:14,代码来源:Response.php

示例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;
 }
开发者ID:kameshwariv,项目名称:testexample,代码行数:19,代码来源:EmbeddedCommandFactory.php

示例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;
             }
         }
     }
 }
开发者ID:Ryu0621,项目名称:SaNaVi,代码行数:12,代码来源:HeaderVisitor.php

示例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;
 }
开发者ID:canaltp,项目名称:abstract-guzzle,代码行数:17,代码来源:Guzzle3Mock.php

示例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);
 }
开发者ID:NaszvadiG,项目名称:ImageCMS,代码行数:17,代码来源:Client.php

示例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;
             }
         }
     }
 }
开发者ID:KANU82,项目名称:guzzle,代码行数:22,代码来源:HeaderVisitor.php

示例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);
     }
 }
开发者ID:KANU82,项目名称:guzzle,代码行数:21,代码来源:DefaultCacheStorage.php

示例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);
     }
 }
开发者ID:creazy412,项目名称:vmware-win10-c65-drupal7,代码行数:19,代码来源:DefaultCacheStorage.php

示例13: createResponse

 protected function createResponse(GuzzleResponse $response)
 {
     $headers = $response->getHeaders()->toArray();
     return new Response($response->getBody(true), $response->getStatusCode(), $headers);
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:5,代码来源:Client.php

示例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']);
 }
开发者ID:fandikurnia,项目名称:CiiMS,代码行数:12,代码来源:DataObject.php

示例15: getHeaders

 /**
  * @param bool $asObjects
  * @return \Guzzle\Common\Collection
  */
 public function getHeaders($asObjects = false)
 {
     return $this->response->getHeaders($asObjects);
 }
开发者ID:robmasters,项目名称:optimus,代码行数:8,代码来源:GuzzleAdapter.php


注:本文中的Guzzle\Http\Message\Response::getHeaders方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。