Repository navigation
Expand file tree
/
Copy pathAcceptHeaderTrait.php
More file actions
66 lines (54 loc) · 1.95 KB
/
Copy pathAcceptHeaderTrait.php
File metadata and controls
66 lines (54 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
namespace Github\Api;
use Psr\Http\Message\ResponseInterface;
/**
* A trait to make sure we add accept headers on all requests.
*
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
trait AcceptHeaderTrait
{
/** @var string */
protected $acceptHeaderValue;
protected function get(string $path, array $parameters = [], array $requestHeaders = [])
{
return parent::get($path, $parameters, $this->mergeHeaders($requestHeaders));
}
protected function head(string $path, array $parameters = [], array $requestHeaders = []): ResponseInterface
{
return parent::head($path, $parameters, $this->mergeHeaders($requestHeaders));
}
protected function post(string $path, array $parameters = [], array $requestHeaders = [])
{
return parent::post($path, $parameters, $this->mergeHeaders($requestHeaders));
}
protected function postRaw(string $path, $body, array $requestHeaders = [])
{
return parent::postRaw($path, $body, $this->mergeHeaders($requestHeaders));
}
protected function patch(string $path, array $parameters = [], array $requestHeaders = [])
{
return parent::patch($path, $parameters, $this->mergeHeaders($requestHeaders));
}
protected function put(string $path, array $parameters = [], array $requestHeaders = [])
{
return parent::put($path, $parameters, $this->mergeHeaders($requestHeaders));
}
protected function delete(string $path, array $parameters = [], array $requestHeaders = [])
{
return parent::delete($path, $parameters, $this->mergeHeaders($requestHeaders));
}
/**
* Append a new accept header on all requests.
*
* @return array
*/
private function mergeHeaders(array $headers = []): array
{
$default = [];
if ($this->acceptHeaderValue) {
$default = ['Accept' => $this->acceptHeaderValue];
}
return array_merge($default, $headers);
}
}