1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Gateway Client Class |
6
|
|
|
* @category Ticaje |
7
|
|
|
* @author Max Demian <[email protected]> |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Ticaje\AConnector\Gateway\Client; |
11
|
|
|
|
12
|
|
|
use Ticaje\AConnector\Interfaces\Implementors\Client\Rest\RestClientImplementorInterface; |
13
|
|
|
use Ticaje\Contract\Factory\FactoryInterface; |
14
|
|
|
use Ticaje\Contract\Patterns\Interfaces\Decorator\ResponderInterface; |
15
|
|
|
|
16
|
|
|
use Ticaje\AConnector\Interfaces\Protocol\RestClientInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class Rest |
20
|
|
|
* @package Ticaje\Connector\Gateway\Client |
21
|
|
|
*/ |
22
|
|
|
class Rest extends Base implements RestClientInterface |
23
|
|
|
{ |
24
|
|
|
private $baseUriKey; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Rest constructor. |
28
|
|
|
* @param ResponderInterface $responder |
29
|
|
|
* @param FactoryInterface $clientFactory |
30
|
|
|
* @param RestClientImplementorInterface $implementor |
31
|
|
|
* @param string $baseUriKey |
32
|
|
|
*/ |
33
|
|
|
public function __construct( |
34
|
|
|
ResponderInterface $responder, |
35
|
|
|
FactoryInterface $clientFactory, |
36
|
|
|
RestClientImplementorInterface $implementor, |
37
|
|
|
string $baseUriKey |
38
|
|
|
) { |
39
|
|
|
$this->baseUriKey = $baseUriKey; |
40
|
|
|
parent::__construct($responder, $clientFactory, $implementor); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @inheritDoc |
45
|
|
|
*/ |
46
|
|
|
public function generateClient($credentials) |
47
|
|
|
{ |
48
|
|
|
$client = $this->clientFactory->create([$this->baseUriKey => $credentials[self::BASE_URI_KEY]]); |
49
|
|
|
return $this->implementor->setClient($client); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @inheritDoc |
54
|
|
|
*/ |
55
|
|
|
public function request($verb, $endpoint, array $headers = [], array $params) |
56
|
|
|
{ |
57
|
|
|
$result = $this->implementor->request($verb, $endpoint, $headers, $params); |
|
|
|
|
58
|
|
|
return $this->responder->process($result); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @inheritDoc |
63
|
|
|
*/ |
64
|
|
|
public function requestAsync($verb, $endpoint, array $headers = [], array $params) |
65
|
|
|
{ |
66
|
|
|
$result = $this->implementor->requestAsync($verb, $endpoint, $headers, $params); |
|
|
|
|
67
|
|
|
return $this->responder->process($result); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|