1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Request Provider Class |
6
|
|
|
* @category Ticaje |
7
|
|
|
* @author Max Demian <[email protected]> |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Ticaje\AeSdk\Infrastructure\Provider\Request; |
11
|
|
|
|
12
|
|
|
use Ticaje\AeSdk\Infrastructure\Interfaces\Provider\Request\RequestDtoInterface; |
13
|
|
|
use Ticaje\AeSdk\Infrastructure\Interfaces\Provider\Request\Builder\PublicBuilderInterface; |
14
|
|
|
use Ticaje\AeSdk\Infrastructure\Interfaces\Provider\Request\Builder\ServiceBuilderInterface; |
15
|
|
|
use Ticaje\AeSdk\Infrastructure\Interfaces\Provider\Request\RequesterInterface; |
16
|
|
|
use Ticaje\AeSdk\Infrastructure\Interfaces\Provider\Signature\SignerInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class Requester |
20
|
|
|
* @package Ticaje\AeSdk\Infrastructure\Provider\Request |
21
|
|
|
* This class is responsible for compiling the whole request to AE API. |
22
|
|
|
* It contains complies with to components of AE communication constraints: Public and Service parameters |
23
|
|
|
*/ |
24
|
|
|
class Requester implements RequesterInterface |
25
|
|
|
{ |
26
|
|
|
private $signer; |
27
|
|
|
|
28
|
|
|
private $publicBuilder; |
29
|
|
|
|
30
|
|
|
private $serviceBuilder; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Requester constructor. |
34
|
|
|
* @param SignerInterface $signer |
35
|
|
|
* @param PublicBuilderInterface $publicBuilder |
36
|
|
|
* @param ServiceBuilderInterface $serviceBuilder |
37
|
|
|
*/ |
38
|
|
|
public function __construct( |
39
|
|
|
SignerInterface $signer, |
40
|
|
|
PublicBuilderInterface $publicBuilder, |
41
|
|
|
ServiceBuilderInterface $serviceBuilder |
42
|
|
|
) { |
43
|
|
|
$this->signer = $signer; |
44
|
|
|
$this->publicBuilder = $publicBuilder; |
45
|
|
|
$this->serviceBuilder = $serviceBuilder; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @inheritDoc |
50
|
|
|
*/ |
51
|
|
|
public function compile(RequestDtoInterface $dto): string |
52
|
|
|
{ |
53
|
|
|
$public = $this->compilePublic($dto); |
54
|
|
|
$service = $this->compileService($dto); |
55
|
|
|
$signature = $this->compileSignature($dto); |
56
|
|
|
return "{$public}{$service}{$signature}"; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param $dto |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
|
|
private function compilePublic($dto) |
64
|
|
|
{ |
65
|
|
|
return $this->publicBuilder->compile($dto); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param $dto |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
|
|
private function compileSignature($dto) |
73
|
|
|
{ |
74
|
|
|
$sortedForSigning = $this->publicBuilder->compileToSignature($dto); |
75
|
|
|
$signature = $this->signer->sign($sortedForSigning, $dto); |
76
|
|
|
return "sign={$signature}"; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param $dto |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
|
|
private function compileService($dto) |
84
|
|
|
{ |
85
|
|
|
$request = $dto->getRequest(); |
86
|
|
|
return $this->serviceBuilder->compile($request); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|