-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathClient.php
153 lines (129 loc) · 4.41 KB
/
Client.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
/**
* (c) Packagist Conductors GmbH <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PrivatePackagist\ApiClient;
use Http\Client\Common\Plugin;
use Http\Discovery\Psr17FactoryDiscovery;
use PrivatePackagist\ApiClient\HttpClient\HttpPluginClientBuilder;
use PrivatePackagist\ApiClient\HttpClient\Message\ResponseMediator;
use PrivatePackagist\ApiClient\HttpClient\Plugin\ExceptionThrower;
use PrivatePackagist\ApiClient\HttpClient\Plugin\PathPrepend;
use PrivatePackagist\ApiClient\HttpClient\Plugin\RequestSignature;
class Client
{
/** @var HttpPluginClientBuilder */
private $httpClientBuilder;
/** @var ResponseMediator */
private $responseMediator;
/** @param string $privatePackagistUrl */
public function __construct(?HttpPluginClientBuilder $httpClientBuilder = null, $privatePackagistUrl = null, ?ResponseMediator $responseMediator = null)
{
$this->httpClientBuilder = $builder = $httpClientBuilder ?: new HttpPluginClientBuilder();
$privatePackagistUrl = $privatePackagistUrl ? : 'https://packagist.com';
$this->responseMediator = $responseMediator ? : new ResponseMediator();
$builder->addPlugin(new Plugin\AddHostPlugin(Psr17FactoryDiscovery::findUriFactory()->createUri($privatePackagistUrl)));
$builder->addPlugin(new PathPrepend('/api'));
$builder->addPlugin(new Plugin\RedirectPlugin());
$headers = [
'User-Agent' => 'php-private-packagist-api (https://github.com/packagist/private-packagist-api-client)',
];
if ($apiClientVersion = $this->getApiClientVersion()) {
$headers['API-CLIENT-VERSION'] = $apiClientVersion;
}
$builder->addPlugin(new Plugin\HeaderDefaultsPlugin($headers));
$builder->addPlugin(new ExceptionThrower($this->responseMediator));
}
/**
* @param string $key
* @param string $secret
*/
public function authenticate(
#[\SensitiveParameter]
$key,
#[\SensitiveParameter]
$secret
) {
$this->httpClientBuilder->removePlugin(RequestSignature::class);
$this->httpClientBuilder->addPlugin(new RequestSignature($key, $secret));
}
public function credentials()
{
return new Api\Credentials($this, $this->responseMediator);
}
public function teams()
{
return new Api\Teams($this, $this->responseMediator);
}
public function customers()
{
return new Api\Customers($this, $this->responseMediator);
}
/**
* @deprecated Use Client::subrepositories instead
*/
#[\Deprecated('Use Client::subrepositories instead', '1.16.1')]
public function projects()
{
return new Api\Subrepositories($this, $this->responseMediator);
}
public function subrepositories()
{
return new Api\Subrepositories($this, $this->responseMediator);
}
public function organization()
{
return new Api\Organization($this, $this->responseMediator);
}
public function packages()
{
return new Api\Packages($this, $this->responseMediator);
}
public function securityIssues()
{
return new Api\SecurityIssues($this, $this->responseMediator);
}
public function jobs()
{
return new Api\Jobs($this, $this->responseMediator);
}
public function mirroredRepositories()
{
return new Api\MirroredRepositories($this, $this->responseMediator);
}
public function tokens()
{
return new Api\Tokens($this, $this->responseMediator);
}
public function synchronizations()
{
return new Api\Synchronizations($this, $this->responseMediator);
}
public function vendorBundles()
{
return new Api\VendorBundles($this, $this->responseMediator);
}
public function getHttpClient()
{
return $this->getHttpClientBuilder()->getHttpClient();
}
public function getResponseMediator()
{
return $this->responseMediator;
}
protected function getHttpClientBuilder()
{
return $this->httpClientBuilder;
}
private function getApiClientVersion()
{
try {
return \Composer\InstalledVersions::getVersion('private-packagist/api-client');
} catch (\OutOfBoundsException $exception) {
return null;
}
}
}