1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Bokbasen\ApiClient; |
4
|
|
|
|
5
|
|
|
use Bokbasen\ApiClient\Exceptions\MissingParameterException; |
6
|
|
|
use Psr\Http\Message\ResponseInterface; |
7
|
|
|
|
8
|
|
|
abstract class AuthenticatedApi |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var string |
12
|
|
|
*/ |
13
|
|
|
private $loginEndpoint; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
private $loginUsername; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
private $loginPassword; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var Client |
27
|
|
|
*/ |
28
|
|
|
private $client; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var CacheItemPoolInterface |
|
|
|
|
32
|
|
|
*/ |
33
|
|
|
protected $cache; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var LoggerInterface |
|
|
|
|
37
|
|
|
*/ |
38
|
|
|
protected $logger; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $endpoint; |
44
|
|
|
|
45
|
|
|
public function get(string $path, array $headers = [], bool $authenticate = true): ResponseInterface |
46
|
|
|
{ |
47
|
|
|
return $this->getClient()->get($path, $headers, $authenticate); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function post(string $path, $body, array $headers = [], $authenticate = true): ResponseInterface |
51
|
|
|
{ |
52
|
|
|
return $this->getClient()->post($path, $body, $headers, $authenticate); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function patch(string $path, array $headers = [], bool $authenticate = true): ResponseInterface |
56
|
|
|
{ |
57
|
|
|
return $this->getClient()->patch($path, $headers, $authenticate); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function put(string $path, $body, array $headers = [], $authenticate = true): ResponseInterface |
61
|
|
|
{ |
62
|
|
|
return $this->getClient()->put($path, $body, $headers, $authenticate); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
protected function getClient(): Client |
66
|
|
|
{ |
67
|
|
|
$this->isReady(); |
68
|
|
|
|
69
|
|
|
if (!$this->client) { |
70
|
|
|
$login = new Login($this->loginUsername, $this->password, $this->loginEndpoint, $this->cache, $this->logger); |
|
|
|
|
71
|
|
|
$this->client = new Client($login, $this->orderEndpoint); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $this->client; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function setEndpoint(string $endpoint): void |
78
|
|
|
{ |
79
|
|
|
$this->endpoint = $endpoint; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function setCredentials(string $username, string $password, string $endpoint): void |
83
|
|
|
{ |
84
|
|
|
$this->username = $username; |
|
|
|
|
85
|
|
|
$this->password = $password; |
|
|
|
|
86
|
|
|
$this->loginEndpoint = sprintf('%s/v1/tickets', $endpoint); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function setLogger(LoggerInterface $logger = null): void |
90
|
|
|
{ |
91
|
|
|
$this->logger = $logger; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function setCache(CacheItemPoolInterface $cacheItemPool = null): void |
95
|
|
|
{ |
96
|
|
|
$this->cache = $cacheItemPool; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
private function isReady(): bool |
100
|
|
|
{ |
101
|
|
|
$params = [ |
102
|
|
|
'loginEndpoint', |
103
|
|
|
'loginUsername', |
104
|
|
|
'loginPassword', |
105
|
|
|
'endpoint', |
106
|
|
|
]; |
107
|
|
|
|
108
|
|
|
foreach ($params as $param) { |
109
|
|
|
if (!$this->$param) { |
110
|
|
|
throw new MissingParameterException($param); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
return true; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths