-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathMindboxClientFactory.php
More file actions
64 lines (59 loc) · 2.2 KB
/
Copy pathMindboxClientFactory.php
File metadata and controls
64 lines (59 loc) · 2.2 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
61
62
63
64
<?php
namespace Mindbox\Clients;
use Mindbox\XMLHelper\MindboxXMLSerializer;
use Mindbox\Exceptions\MindboxConfigException;
use Mindbox\HttpClients\IHttpClient;
use Psr\Log\LoggerInterface;
/**
* Класс, отвечающий за инициализацию Mindbox API клиента, согласно пользовательской конфигурации.
* Class MindboxClientFactory
*
* @package Mindbox\Clients
*/
class MindboxClientFactory
{
/**
* Конструктор MindboxClientFactory.
*
* @param string $apiVersion Версия Mindbox API.
* @param string $endpointId Уникальный идентификатор сайта/мобильного приложения/и т.п.
* @param string $secretKey Секретный ключ.
* @param string $domain Домен.
* @param IHttpClient $httpClient Экземпляр HTTP клиента.
* @param LoggerInterface $logger Экземпляр логгера.
*
* @return AbstractMindboxClient
*/
public function createMindboxClient(
$apiVersion,
$endpointId,
$secretKey,
$domain,
IHttpClient $httpClient,
LoggerInterface $logger
) {
if (empty($secretKey)) {
throw new MindboxConfigException('Secret key cant`t be empty');
}
switch ($apiVersion) {
case 'v3':
if (empty($endpointId)) {
throw new MindboxConfigException('Endpoint id cant`t be empty for v3 API');
}
return new MindboxClientV3($endpointId, $secretKey, $httpClient, $logger, $domain);
case 'v2.1':
if (empty($domain)) {
throw new MindboxConfigException('Domain cant`t be empty for v2.1 API');
}
return new MindboxClientV2(
$domain,
$secretKey,
$httpClient,
$logger,
new MindboxXMLSerializer()
);
default:
throw new MindboxConfigException('The api version must be set to "v3", "v2.1"');
}
}
}