當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Response::hasHeader方法代碼示例

本文整理匯總了PHP中GuzzleHttp\Psr7\Response::hasHeader方法的典型用法代碼示例。如果您正苦於以下問題:PHP Response::hasHeader方法的具體用法?PHP Response::hasHeader怎麽用?PHP Response::hasHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在GuzzleHttp\Psr7\Response的用法示例。


在下文中一共展示了Response::hasHeader方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: __construct

 public function __construct(\GuzzleHttp\Psr7\Response $response)
 {
     $json = false;
     $data = $response->getBody();
     $this->rawData = $data;
     $this->response = $response;
     if ($response->hasHeader('Content-Type')) {
         // Let's see if it is JSON
         $contentType = $response->getHeader('Content-Type');
         if (strstr($contentType[0], 'json')) {
             $json = true;
             $data = json_decode($data);
         }
     }
     if (!$json) {
         // We can do another test here
         $decoded = json_decode($response->getBody());
         if ($decoded) {
             $json = true;
             $data = $decoded;
         }
     }
     $this->setData($data);
     $this->setIsJson($json);
 }
開發者ID:webmakersteve,項目名稱:instagram-php,代碼行數:25,代碼來源:Response.php

示例2: testCreatesResponseWithAddedHeaderArray

 public function testCreatesResponseWithAddedHeaderArray()
 {
     $r = new Response();
     $r2 = $r->withAddedHeader('foo', ['baz', 'bar']);
     $this->assertFalse($r->hasHeader('foo'));
     $this->assertEquals('baz, bar', $r2->getHeaderLine('foo'));
 }
開發者ID:shomimn,項目名稱:builder,代碼行數:7,代碼來源:ResponseTest.php

示例3: getCacheTtl

 /**
  * Get cache ttl value
  *
  * @param Response $response
  *
  * @return int
  */
 protected function getCacheTtl(Response $response)
 {
     if ($this->useHeaderTtl && $response->hasHeader('Cache-Control')) {
         $cacheControl = $response->getHeader('Cache-Control')[0];
         if (preg_match('`max-age=(\\d+)`', $cacheControl, $match)) {
             return intval($match[1]);
         }
     }
     return $this->defaultTtl;
 }
開發者ID:AlliterativeAnimals,項目名稱:GuzzleHttpBundle,代碼行數:17,代碼來源:CacheTrait.php

示例4: create

 /**
  * @param ObjectInterface $object
  * @param array           $data
  * @param Response        $response
  * @return ObjectInterface
  */
 public function create(ObjectInterface $object, array $data, Response $response = null)
 {
     // If object had relationId, we pass it to new object
     if ($object->getAttribute("relationId")) {
         $relationId = $object->getAttribute("relationId");
         $object = new $object($relationId);
     } else {
         $object = new $object();
     }
     if (isset($data['items']) or isset($data[0])) {
         // If we have list of items
         $object = $this->createList($object, $data);
     } else {
         if (isset($data["id"])) {
             // TODO: Some things don't provide ID, possible BUG, that it isn't implemented in CREST
             $object->setAttribute("id", $data['id']);
             $uri = $object->getAttribute("uri") . $object->getAttribute("id") . "/";
             $object->setAttribute("uri", $uri);
         } elseif (!empty($data['href']) && is_numeric(basename($data["href"]))) {
             // TODO: Meybe not bug, so we just take it from href
             $object->setAttribute("id", (int) basename($data["href"]));
             $uri = $object->getAttribute("uri") . $object->getAttribute("id") . "/";
             $object->setAttribute("uri", $uri);
         }
         foreach ($data as $key => $value) {
             if (array_key_exists($key, $object->getRelations())) {
                 // ˇˇ
                 if (is_string($value)) {
                     // TODO: Sometimes relationship is only a string with href, not array like usually.
                     // TODO: When crest behaves as it should, remove this!
                     // Seen in GET crest.../wars/21/  value "killmails"
                     $object->setValue($key, $value);
                     continue;
                 }
                 // ^^
                 // Create new relation object with relation_id
                 $relation = $object->getRelations($key);
                 $object->setValue($key, $this->create(new $relation($object->getAttribute("id")), $value));
             } else {
                 $object->setValue($key, $value);
             }
         }
     }
     // Add cache-control header to Object, but only if this Endpoint made request
     //  we cant add cache-control for relationships, as we don't have data for them
     // Add HTTP Code, might be useful
     if ($response) {
         // On POST/PUT/DELETE responses cache-control isn't provided.
         if ($response->hasHeader("cache-control")) {
             $object->setAttribute("cache", $response->getHeader("cache-control")[0]);
         }
         $object->setAttribute("httpCode", $response->getStatusCode());
     }
     return $object;
 }
開發者ID:mentos1386,項目名稱:opencrest,代碼行數:61,代碼來源:Factory.php

示例5: parser

 /**
  * @inheritdoc
  */
 public function parser(Response $response)
 {
     return $response->hasHeader('ETag');
 }
開發者ID:joyshion,項目名稱:AliyunOSS,代碼行數:7,代碼來源:CopyObjectCommand.php

示例6: header

 /**
  * Get HTTP header.
  *
  * @param $key
  * @param mixed $default
  *
  * @return mixed
  */
 public function header($key, $default = null)
 {
     return $this->response->hasHeader($key) ? $this->response->getHeaderLine($key) : $default;
 }
開發者ID:bugotech,項目名稱:rfm,代碼行數:12,代碼來源:Response.php

示例7: parser

 /**
  * @inheritdoc
  */
 public function parser(Response $response)
 {
     return $response->getStatusCode() == 200 && $response->hasHeader('ETag');
 }
開發者ID:joyshion,項目名稱:AliyunOSS,代碼行數:7,代碼來源:PutObjectCommand.php

示例8: testWithoutHeaderThatExists

 public function testWithoutHeaderThatExists()
 {
     $r = new Response(200, ['Foo' => 'Bar', 'Baz' => 'Bam']);
     $r2 = $r->withoutHeader('foO');
     $this->assertTrue($r->hasHeader('foo'));
     $this->assertSame(['Foo' => ['Bar'], 'Baz' => ['Bam']], $r->getHeaders());
     $this->assertFalse($r2->hasHeader('foo'));
     $this->assertSame(['Baz' => ['Bam']], $r2->getHeaders());
 }
開發者ID:drickferreira,項目名稱:rastreador,代碼行數:9,代碼來源:ResponseTest.php


注:本文中的GuzzleHttp\Psr7\Response::hasHeader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。