1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Elmage\TextNg; |
4
|
|
|
|
5
|
|
|
use Elmage\TextNg\Authentication\ApiKeyAuthentication; |
6
|
|
|
use GuzzleHttp\Client as GuzzleClient; |
7
|
|
|
use GuzzleHttp\ClientInterface; |
8
|
|
|
|
9
|
|
|
class Configuration |
10
|
|
|
{ |
11
|
|
|
const DEFAULT_API_URL = 'https://api.textng.xyz'; |
12
|
|
|
const DEFAULT_API_VERSION = '1'; |
13
|
|
|
|
14
|
|
|
private ApiKeyAuthentication $authentication; |
15
|
|
|
private $apiUrl; |
16
|
|
|
private $sender; |
17
|
|
|
private $apiVersion; |
18
|
|
|
private $logger; |
19
|
|
|
|
20
|
8 |
|
public function __construct(ApiKeyAuthentication $authentication, string $sender) |
21
|
|
|
{ |
22
|
8 |
|
$this->authentication = $authentication; |
23
|
8 |
|
$this->apiUrl = self::DEFAULT_API_URL; |
24
|
8 |
|
$this->apiVersion = self::DEFAULT_API_VERSION; |
25
|
8 |
|
$this->sender = $sender; |
26
|
8 |
|
} |
27
|
|
|
|
28
|
|
|
/** @return HttpClient */ |
29
|
2 |
|
public function createHttpClient(ClientInterface $transport = null) |
30
|
|
|
{ |
31
|
2 |
|
$httpClient = new HttpClient( |
32
|
2 |
|
$this->apiUrl, |
33
|
2 |
|
$this->apiVersion, |
34
|
2 |
|
$this->authentication, |
35
|
2 |
|
$this->sender, |
36
|
2 |
|
$transport ?: new GuzzleClient() |
37
|
|
|
); |
38
|
|
|
|
39
|
2 |
|
$httpClient->setLogger($this->logger); |
40
|
|
|
|
41
|
2 |
|
return $httpClient; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Creates a new configuration with API key authentication. |
46
|
|
|
* |
47
|
|
|
* @param string $apiKey An API key |
48
|
|
|
* @param string $sender sender name |
49
|
|
|
* @param string $apiSecret An API secret |
50
|
|
|
* |
51
|
|
|
* @return Configuration A new configuration instance |
52
|
|
|
*/ |
53
|
1 |
|
public static function apiKey(string $apiKey, string $sender = '') |
54
|
|
|
{ |
55
|
1 |
|
return new static( |
56
|
1 |
|
new ApiKeyAuthentication($apiKey), |
57
|
|
|
$sender |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
1 |
|
public function getAuthentication() |
62
|
|
|
{ |
63
|
1 |
|
return $this->authentication; |
64
|
|
|
} |
65
|
|
|
|
66
|
1 |
|
public function setAuthentication(ApiKeyAuthentication $authentication) |
67
|
|
|
{ |
68
|
1 |
|
$this->authentication = $authentication; |
69
|
1 |
|
} |
70
|
|
|
|
71
|
2 |
|
public function getApiUrl() |
72
|
|
|
{ |
73
|
2 |
|
return $this->apiUrl; |
74
|
|
|
} |
75
|
|
|
|
76
|
1 |
|
public function setApiUrl($apiUrl) |
77
|
|
|
{ |
78
|
1 |
|
$this->apiUrl = $apiUrl; |
79
|
1 |
|
} |
80
|
|
|
|
81
|
2 |
|
public function getApiVersion() |
82
|
|
|
{ |
83
|
2 |
|
return $this->apiVersion; |
84
|
|
|
} |
85
|
|
|
|
86
|
1 |
|
public function setApiVersion($apiVersion) |
87
|
|
|
{ |
88
|
1 |
|
$this->apiVersion = $apiVersion; |
89
|
1 |
|
} |
90
|
|
|
|
91
|
1 |
|
public function getSender() |
92
|
|
|
{ |
93
|
1 |
|
return $this->sender; |
94
|
|
|
} |
95
|
|
|
|
96
|
1 |
|
public function setSender(string $sender) |
97
|
|
|
{ |
98
|
1 |
|
$this->sender = $sender; |
99
|
1 |
|
} |
100
|
|
|
} |
101
|
|
|
|