|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
|
5
|
|
|
* @license https://github.com/flipbox/relay-hubspot/blob/master/LICENSE |
|
6
|
|
|
* @link https://github.com/flipbox/relay-hubspot |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Flipbox\Relay\HubSpot\Builder; |
|
10
|
|
|
|
|
11
|
|
|
use Flipbox\Relay\Builder\RelayBuilder; |
|
12
|
|
|
use Flipbox\Relay\HubSpot\AuthorizationInterface; |
|
13
|
|
|
use Flipbox\Relay\HubSpot\Middleware\Authorization as AuthorizationMiddleware; |
|
14
|
|
|
use Flipbox\Relay\HubSpot\Middleware\Client as ClientMiddleware; |
|
15
|
|
|
use Psr\Log\LoggerInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @author Flipbox Factory <[email protected]> |
|
19
|
|
|
* @since 1.0.0 |
|
20
|
|
|
*/ |
|
21
|
|
|
class HttpRelayBuilder extends RelayBuilder |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @param AuthorizationInterface $authorization |
|
25
|
|
|
* @param LoggerInterface|null $logger |
|
26
|
|
|
* @param array $config |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct( |
|
29
|
|
|
AuthorizationInterface $authorization, |
|
30
|
|
|
LoggerInterface $logger = null, |
|
31
|
|
|
array $config = [] |
|
32
|
|
|
) { |
|
33
|
|
|
parent::__construct( |
|
34
|
|
|
$config |
|
35
|
|
|
); |
|
36
|
|
|
|
|
37
|
|
|
$this->addClient($logger) |
|
38
|
|
|
->addAuthorization($authorization, $logger); |
|
39
|
|
|
} |
|
40
|
|
|
/** |
|
41
|
|
|
* @param AuthorizationInterface $authorization |
|
42
|
|
|
* @param LoggerInterface|null $logger |
|
43
|
|
|
* @return $this |
|
44
|
|
|
*/ |
|
45
|
|
|
protected function addAuthorization( |
|
46
|
|
|
AuthorizationInterface $authorization, |
|
47
|
|
|
LoggerInterface $logger = null |
|
48
|
|
|
) { |
|
49
|
|
|
return $this->addBefore('token', [ |
|
50
|
|
|
'class' => AuthorizationMiddleware::class, |
|
51
|
|
|
'logger' => $logger ?: $this->getLogger(), |
|
52
|
|
|
'authorization' => $authorization |
|
53
|
|
|
], 'client'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param LoggerInterface|null $logger |
|
58
|
|
|
* @return $this |
|
59
|
|
|
*/ |
|
60
|
|
|
protected function addClient(LoggerInterface $logger = null) |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->addAfter('client', [ |
|
63
|
|
|
'class' => ClientMiddleware::class, |
|
64
|
|
|
'logger' => $logger ?: $this->getLogger(), |
|
65
|
|
|
]); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|