-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathApiSettings.php
More file actions
60 lines (53 loc) · 2.47 KB
/
ApiSettings.php
File metadata and controls
60 lines (53 loc) · 2.47 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
<?php declare(strict_types=1);
namespace ApiClients\Client\Github;
use ApiClients\Client\Github\Middleware\ErrorMiddleware;
use ApiClients\Client\Github\Middleware\RateLimitStateMiddleware;
use ApiClients\Foundation\Hydrator\Options as HydratorOptions;
use ApiClients\Foundation\Options as FoundationOptions;
use function ApiClients\Foundation\options_merge;
use ApiClients\Foundation\Transport\Options as TransportOptions;
use ApiClients\Middleware\HttpExceptions\HttpExceptionsMiddleware;
use ApiClients\Middleware\Json\JsonDecodeMiddleware;
use ApiClients\Middleware\Json\JsonEncodeMiddleware;
use ApiClients\Middleware\UserAgent\Options as UserAgentMiddlewareOptions;
use ApiClients\Middleware\UserAgent\UserAgentMiddleware;
use ApiClients\Middleware\UserAgent\UserAgentStrategies;
final class ApiSettings
{
const NAMESPACE = 'ApiClients\\Client\\Github\\Resource';
const TRANSPORT_OPTIONS = [
FoundationOptions::HYDRATOR_OPTIONS => [
HydratorOptions::NAMESPACE => self::NAMESPACE,
HydratorOptions::NAMESPACE_DIR => __DIR__ . \DIRECTORY_SEPARATOR . 'Resource' . \DIRECTORY_SEPARATOR,
],
FoundationOptions::TRANSPORT_OPTIONS => [
TransportOptions::HOST => 'api.github.com',
TransportOptions::MIDDLEWARE => [
JsonDecodeMiddleware::class,
JsonEncodeMiddleware::class,
UserAgentMiddleware::class,
RateLimitStateMiddleware::class,
HttpExceptionsMiddleware::class,
ErrorMiddleware::class,
],
TransportOptions::DEFAULT_REQUEST_OPTIONS => [
UserAgentMiddleware::class => [
UserAgentMiddlewareOptions::STRATEGY => UserAgentStrategies::PACKAGE_VERSION,
UserAgentMiddlewareOptions::PACKAGE => 'api-clients/github',
],
],
],
];
public static function getOptions(
AuthenticationInterface $auth,
array $suppliedOptions,
string $suffix
): array {
$options = options_merge(self::TRANSPORT_OPTIONS, $auth->getOptions());
$options = options_merge($options, $suppliedOptions);
$options[FoundationOptions::HYDRATOR_OPTIONS][HydratorOptions::NAMESPACE_SUFFIX] = $suffix;
$acceptHeader = AcceptHeader::getHeader(AcceptHeader::PRESET_DEFAULT);
$options[FoundationOptions::TRANSPORT_OPTIONS][TransportOptions::HEADERS]['Accept'] = $acceptHeader;
return $options;
}
}