1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace ApiClients\Client\Twitter; |
4
|
|
|
|
5
|
|
|
use ApiClients\Foundation\Hydrator\Options as HydratorOptions; |
6
|
|
|
use ApiClients\Foundation\Options; |
7
|
|
|
use ApiClients\Foundation\Transport\Options as TransportOptions; |
8
|
|
|
use ApiClients\Middleware\Json\JsonDecodeMiddleware; |
9
|
|
|
use ApiClients\Middleware\Oauth1\Oauth1Middleware; |
10
|
|
|
use ApiClients\Middleware\Oauth1\Options as Oauth1Options; |
11
|
|
|
use ApiClients\Middleware\UserAgent\Options as UserAgentMiddlewareOptions; |
12
|
|
|
use ApiClients\Middleware\UserAgent\UserAgentMiddleware; |
13
|
|
|
use ApiClients\Middleware\UserAgent\UserAgentStrategies; |
14
|
|
|
use ApiClients\Tools\Psr7\Oauth1\Definition; |
15
|
|
|
|
16
|
|
|
final class ApiSettings |
17
|
|
|
{ |
18
|
|
|
const NAMESPACE = 'ApiClients\\Client\\Twitter\\Resource'; |
19
|
|
|
|
20
|
|
|
const TRANSPORT_OPTIONS = [ |
21
|
|
|
Options::HYDRATOR_OPTIONS => [ |
22
|
|
|
HydratorOptions::NAMESPACE => self::NAMESPACE, |
23
|
|
|
HydratorOptions::NAMESPACE_DIR => __DIR__ . DIRECTORY_SEPARATOR . 'Resource' . DIRECTORY_SEPARATOR, |
24
|
|
|
], |
25
|
|
|
Options::TRANSPORT_OPTIONS => [ |
26
|
|
|
TransportOptions::HOST => 'api.twitter.com', |
27
|
|
|
TransportOptions::PATH => '/1.1/', |
28
|
|
|
TransportOptions::MIDDLEWARE => [ |
29
|
|
|
Oauth1Middleware::class, |
30
|
|
|
JsonDecodeMiddleware::class, |
31
|
|
|
UserAgentMiddleware::class, |
32
|
|
|
], |
33
|
|
|
TransportOptions::DEFAULT_REQUEST_OPTIONS => [ |
34
|
|
|
UserAgentMiddleware::class => [ |
35
|
|
|
UserAgentMiddlewareOptions::STRATEGY => UserAgentStrategies::PACKAGE_VERSION, |
36
|
|
|
UserAgentMiddlewareOptions::PACKAGE => 'api-clients/twitter', |
37
|
|
|
], |
38
|
|
|
], |
39
|
|
|
], |
40
|
|
|
]; |
41
|
|
|
|
42
|
2 |
|
public static function getOptions( |
43
|
|
|
string $consumerKey, |
44
|
|
|
string $consumerSecret, |
45
|
|
|
string $suffix, |
46
|
|
|
array $suppliedOptions = [] |
47
|
|
|
): array { |
48
|
|
|
// @codingStandardsIgnoreStart |
49
|
2 |
|
$options = array_replace_recursive(self::TRANSPORT_OPTIONS, $suppliedOptions); |
50
|
2 |
|
$options[Options::HYDRATOR_OPTIONS][HydratorOptions::NAMESPACE_SUFFIX] = $suffix; |
51
|
2 |
|
$options[Options::TRANSPORT_OPTIONS][TransportOptions::DEFAULT_REQUEST_OPTIONS][Oauth1Middleware::class][Oauth1Options::CONSUMER_KEY] = new Definition\ConsumerKey($consumerKey); |
52
|
2 |
|
$options[Options::TRANSPORT_OPTIONS][TransportOptions::DEFAULT_REQUEST_OPTIONS][Oauth1Middleware::class][Oauth1Options::CONSUMER_SECRET] = new Definition\ConsumerSecret($consumerSecret); |
53
|
|
|
// @codingStandardsIgnoreEnd |
54
|
2 |
|
return $options; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|