1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ApiClients\Client\Scrutinizer; |
6
|
|
|
|
7
|
|
|
use ApiClients\Client\Scrutinizer\Middleware\AccessTokenMiddleware; |
8
|
|
|
use ApiClients\Foundation\Hydrator\Options as HydratorOptions; |
9
|
|
|
use ApiClients\Foundation\Options as FoundationOptions; |
10
|
|
|
use ApiClients\Foundation\Transport\Options as TransportOptions; |
11
|
|
|
use ApiClients\Middleware\HttpExceptions\HttpExceptionsMiddleware; |
12
|
|
|
use ApiClients\Middleware\Json\JsonDecodeMiddleware; |
13
|
|
|
use ApiClients\Middleware\Json\JsonEncodeMiddleware; |
14
|
|
|
use ApiClients\Middleware\UserAgent\Options as UserAgentMiddlewareOptions; |
15
|
|
|
use ApiClients\Middleware\UserAgent\UserAgentMiddleware; |
16
|
|
|
use ApiClients\Middleware\UserAgent\UserAgentStrategies; |
17
|
|
|
use function ApiClients\Foundation\options_merge; |
18
|
|
|
|
19
|
|
|
final class ApiSettings |
20
|
|
|
{ |
21
|
|
|
const NAMESPACE = 'ApiClients\\Client\\Scrutinizer\\Resource'; |
22
|
|
|
const TRANSPORT_OPTIONS = [ |
23
|
|
|
FoundationOptions::HYDRATOR_OPTIONS => [ |
24
|
|
|
HydratorOptions::NAMESPACE => self::NAMESPACE, |
25
|
|
|
HydratorOptions::NAMESPACE_DIR => __DIR__ . DIRECTORY_SEPARATOR . 'Resource' . DIRECTORY_SEPARATOR, |
26
|
|
|
], |
27
|
|
|
FoundationOptions::TRANSPORT_OPTIONS => [ |
28
|
|
|
TransportOptions::HOST => 'scrutinizer-ci.com', |
29
|
|
|
TransportOptions::PATH => '/api/', |
30
|
|
|
TransportOptions::MIDDLEWARE => [ |
31
|
|
|
HttpExceptionsMiddleware::class, |
32
|
|
|
UserAgentMiddleware::class, |
33
|
|
|
JsonDecodeMiddleware::class, |
34
|
|
|
JsonEncodeMiddleware::class, |
35
|
|
|
AccessTokenMiddleware::class, |
36
|
|
|
], |
37
|
|
|
TransportOptions::DEFAULT_REQUEST_OPTIONS => [ |
38
|
|
|
UserAgentMiddleware::class => [ |
39
|
|
|
UserAgentMiddlewareOptions::STRATEGY => UserAgentStrategies::PACKAGE_VERSION, |
40
|
|
|
UserAgentMiddlewareOptions::PACKAGE => 'api-clients/scrutinizer', |
41
|
|
|
], |
42
|
|
|
], |
43
|
|
|
], |
44
|
|
|
]; |
45
|
|
|
|
46
|
1 |
|
public static function getOptions(string $token, array $suppliedOptions, string $suffix): array |
47
|
|
|
{ |
48
|
1 |
|
$options = options_merge(self::TRANSPORT_OPTIONS, $suppliedOptions); |
49
|
1 |
|
$options[FoundationOptions::HYDRATOR_OPTIONS][HydratorOptions::NAMESPACE_SUFFIX] = $suffix; |
50
|
|
|
|
51
|
1 |
|
$dro = $options[FoundationOptions::TRANSPORT_OPTIONS][TransportOptions::DEFAULT_REQUEST_OPTIONS]; |
52
|
1 |
|
$dro[AccessTokenMiddleware::class] = [ |
53
|
1 |
|
AccessTokenMiddleware::OPTION_ACCESS_TOKEN => $token, |
54
|
|
|
]; |
55
|
1 |
|
$options[FoundationOptions::TRANSPORT_OPTIONS][TransportOptions::DEFAULT_REQUEST_OPTIONS] = $dro; |
56
|
|
|
|
57
|
1 |
|
return $options; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|