1 | <?php |
||
2 | |||
3 | namespace E2Consult\DNBApiClient; |
||
4 | |||
5 | use Aws\Signature\SignatureV4; |
||
6 | use Aws\Credentials\Credentials; |
||
7 | use Psr\Http\Message\RequestInterface; |
||
8 | |||
9 | class DNBRequestHandler |
||
10 | { |
||
11 | private $api_key; |
||
12 | private $customerId; |
||
13 | private $credentials; |
||
14 | |||
15 | protected $signer; |
||
16 | protected $token; |
||
17 | |||
18 | public function __construct(Credentials $credentials, $api_key, $customerId) |
||
19 | { |
||
20 | $this->api_key = $api_key; |
||
21 | $this->customerId = $customerId; |
||
22 | $this->credentials = $credentials; |
||
23 | |||
24 | $this->signer = new SignatureV4( |
||
25 | config('services.dnb.servcice') ?? 'execute-api', |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
26 | config('services.dnb.region') ?? 'eu-west-1' |
||
27 | ); |
||
28 | $this->token = new JwtToken($this->credentials, $this->api_key, $this->customerId); |
||
29 | } |
||
30 | |||
31 | public function __invoke(callable $handler) |
||
32 | { |
||
33 | return function (RequestInterface $request, array $options) use ($handler) { |
||
34 | return $handler( |
||
35 | $this->signer->signRequest( |
||
36 | $request->withAddedHeader('Accept', 'application/json') |
||
37 | ->withAddedHeader('Content-Type', 'application/json') |
||
38 | ->withAddedHeader('x-api-key', $this->api_key) |
||
39 | ->withAddedHeader('x-dnbapi-jwt', $this->token->getJwtToken()), |
||
40 | $this->credentials |
||
41 | ), $options); |
||
42 | }; |
||
43 | } |
||
44 | } |
||
45 |