当前位置: 首页>>代码示例>>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;未经允许,请勿转载。