-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVaasBuilder.php
97 lines (88 loc) · 3.02 KB
/
VaasBuilder.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
<?php
namespace VaasSdk;
use Amp\Http\Client\HttpClient;
use Amp\Http\Client\HttpClientBuilder;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use VaasSdk\Authentication\AuthenticatorInterface;
use VaasSdk\Exceptions\VaasClientException;
use VaasSdk\Options\VaasOptions;
class VaasBuilder
{
private HttpClient $httpClient;
private AuthenticatorInterface $authenticator;
private VaasOptions $options;
private LoggerInterface $logger;
/**
* Optional parameters for the Vaas client like
* - the URL of the VaaS backend
* - whether to use the cache (default: true)
* - whether to use the G DATA cloud for hash lookups (default: true)
* - the timeout in seconds for the file upload to the VaaS backend (default: 300)
* @param VaasOptions $options Options for the Vaas client
* @return $this
*/
public function withOptions(VaasOptions $options): self
{
$this->options = $options;
return $this;
}
/**
* @param HttpClient $httpClient Your optional custom http client.
* @return $this
*/
public function withHttpClient(HttpClient $httpClient): self
{
$this->httpClient = $httpClient;
return $this;
}
/**
* Either use the `ClientCredentialsGrantAuthenticator` or `ResourceOwnerPasswordGrantAuthenticator`
* Use the `ClientCredentialsGrantAuthenticator` if you have a client id and client secret.
* Use the `ResourceOwnerPasswordGrantAuthenticator` if you have a username and password.
* Last one is the choice if you have registered yourself on https://vaas.gdata.de/login. In this case, the client id is `vaas-customer`.
* @param AuthenticatorInterface $authenticator The authenticator to use
* @return $this
*/
public function withAuthenticator(AuthenticatorInterface $authenticator): self
{
$this->authenticator = $authenticator;
return $this;
}
/**
* Set the logger to use
* @param LoggerInterface $logger The logger to use
* @return $this
*/
public function withLogger(LoggerInterface $logger): self
{
$this->logger = $logger;
return $this;
}
/**
* Build the Vaas client
* @return Vaas The Vaas client
* @throws VaasClientException If the authenticator is not set
*/
public function build(): Vaas
{
if (!isset($this->logger)) {
$this->logger = new NullLogger();
}
if (!isset($this->authenticator)) {
throw new VaasClientException('Authenticator is required');
}
if (!isset($this->httpClient)) {
$this->httpClient = HttpClientBuilder::buildDefault();
}
if (!isset($this->options)) {
$this->options = new VaasOptions();
}
$vaas = Vaas::createInstance();
$vaas->withHttpClient($this->httpClient);
$vaas->withAuthenticator($this->authenticator);
$vaas->withOptions($this->options);
$vaas->withLogger($this->logger);
return $vaas;
}
}