本文整理汇总了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);
}
示例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'));
}
示例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;
}
示例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;
}
示例5: parser
/**
* @inheritdoc
*/
public function parser(Response $response)
{
return $response->hasHeader('ETag');
}
示例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;
}
示例7: parser
/**
* @inheritdoc
*/
public function parser(Response $response)
{
return $response->getStatusCode() == 200 && $response->hasHeader('ETag');
}
示例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());
}