1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace ApiClients\Client\Github; |
4
|
|
|
|
5
|
|
|
use ApiClients\Client\Github\Middleware\RateLimitStateMiddleware; |
6
|
|
|
use ApiClients\Foundation\Hydrator\Options as HydratorOptions; |
7
|
|
|
use ApiClients\Foundation\Options as FoundationOptions; |
8
|
|
|
use ApiClients\Foundation\Transport\Middleware\JsonDecodeMiddleware; |
9
|
|
|
use ApiClients\Foundation\Transport\Middleware\JsonEncodeMiddleware; |
10
|
|
|
use ApiClients\Foundation\Transport\Options as TransportOptions; |
11
|
|
|
use ApiClients\Middleware\HttpExceptions\HttpExceptionsMiddleware; |
12
|
|
|
use ApiClients\Middleware\UserAgent\Options as UserAgentMiddlewareOptions; |
13
|
|
|
use ApiClients\Middleware\UserAgent\UserAgentMiddleware; |
14
|
|
|
use ApiClients\Middleware\UserAgent\UserAgentStrategies; |
15
|
|
|
use function ApiClients\Foundation\options_merge; |
16
|
|
|
|
17
|
|
|
final class ApiSettings |
18
|
|
|
{ |
19
|
|
|
const NAMESPACE = 'ApiClients\\Client\\Github\\Resource'; |
20
|
|
|
|
21
|
|
|
const ACCEPT_HEADER = [ |
22
|
|
|
// License on repository object: https://developer.github.com/v3/licenses/#licenses |
23
|
|
|
'application/vnd.github.drax-preview+json', |
24
|
|
|
|
25
|
|
|
// Topics on repository object: https://developer.github.com/v3/repos/#repositories |
26
|
|
|
'application/vnd.github.mercy-preview+json', |
27
|
|
|
|
28
|
|
|
// Community Health: https://developer.github.com/v3/repos/community/#community-health |
29
|
|
|
'application/vnd.github.black-panther-preview+json', |
30
|
|
|
|
31
|
|
|
// Default header: https://developer.github.com/v3/#current-version |
32
|
|
|
'application/vnd.github.v3+json', |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
const TRANSPORT_OPTIONS = [ |
36
|
|
|
FoundationOptions::HYDRATOR_OPTIONS => [ |
37
|
|
|
HydratorOptions::NAMESPACE => self::NAMESPACE, |
38
|
|
|
HydratorOptions::NAMESPACE_DIR => __DIR__ . DIRECTORY_SEPARATOR . 'Resource' . DIRECTORY_SEPARATOR, |
39
|
|
|
], |
40
|
|
|
FoundationOptions::TRANSPORT_OPTIONS => [ |
41
|
|
|
TransportOptions::HOST => 'api.github.com', |
42
|
|
|
TransportOptions::MIDDLEWARE => [ |
43
|
|
|
JsonDecodeMiddleware::class, |
44
|
|
|
JsonEncodeMiddleware::class, |
45
|
|
|
HttpExceptionsMiddleware::class, |
46
|
|
|
UserAgentMiddleware::class, |
47
|
|
|
RateLimitStateMiddleware::class, |
48
|
|
|
], |
49
|
|
|
TransportOptions::DEFAULT_REQUEST_OPTIONS => [ |
50
|
|
|
UserAgentMiddleware::class => [ |
51
|
|
|
UserAgentMiddlewareOptions::STRATEGY => UserAgentStrategies::PACKAGE_VERSION, |
52
|
|
|
UserAgentMiddlewareOptions::PACKAGE => 'api-clients/github', |
53
|
|
|
], |
54
|
|
|
], |
55
|
|
|
], |
56
|
|
|
]; |
57
|
|
|
|
58
|
|
|
public static function getOptions( |
59
|
|
|
AuthenticationInterface $auth, |
60
|
|
|
array $suppliedOptions, |
61
|
|
|
string $suffix |
62
|
|
|
): array { |
63
|
|
|
$options = options_merge(self::TRANSPORT_OPTIONS, $auth->getOptions()); |
64
|
|
|
$options = options_merge($options, $suppliedOptions); |
65
|
|
|
$options[FoundationOptions::HYDRATOR_OPTIONS][HydratorOptions::NAMESPACE_SUFFIX] = $suffix; |
66
|
|
|
|
67
|
|
|
$acceptHeader = implode('; ', self::ACCEPT_HEADER); |
68
|
|
|
$options[FoundationOptions::TRANSPORT_OPTIONS][TransportOptions::HEADERS]['Accept'] = $acceptHeader; |
69
|
|
|
|
70
|
|
|
return $options; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|