-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathConfig.php
89 lines (75 loc) · 2.58 KB
/
Config.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
<?php
declare(strict_types=1);
namespace OpenFeature\Providers\GoFeatureFlag\config;
use Psr\Http\Client\ClientInterface;
class Config
{
private string $endpoint;
/**
* @var array<string, string>
*/
private array $customHeaders = [];
/**
* @var ClientInterface|null - The HTTP Client to use (if you want to use a custom one)
*/
private ?ClientInterface $httpclient;
/**
* @var array<string, mixed> exporterMetadata - is the metadata we send to the GO Feature Flag relay proxy when we report
* the evaluation data usage.
*
* ‼️Important: If you are using a GO Feature Flag relay proxy before version v1.41.0, the information of this
* field will not be added to your feature events.
*/
private array $exporterMetadata = [];
/**
* @param string $endpoint - The endpoint to your GO Feature Flag Instance
* @param string|null $apiKey - API Key to use to connect to GO Feature Flag
* @param array<string, string>|null $customHeaders - Custom headers you want to send
* @param array<string, mixed>|null $exporterMetadata - Metadata to send to the relay proxy during evaluation data collection
* @param ClientInterface|null $httpclient - The HTTP Client to use (if you want to use a custom one)
*/
public function __construct(
string $endpoint,
?string $apiKey = '',
?array $customHeaders = [],
?array $exporterMetadata = [],
?ClientInterface $httpclient = null,
) {
$this->httpclient = $httpclient;
$this->endpoint = $endpoint;
$this->customHeaders = $customHeaders ?? [];
// set default exporter metadata fields
$this->exporterMetadata = $exporterMetadata ?? [];
$this->exporterMetadata['openfeature'] = true;
$this->exporterMetadata['provider'] = 'php';
if ($apiKey !== null && $apiKey !== '') {
$this->customHeaders['Authorization'] = 'Bearer ' . $apiKey;
}
}
public function getEndpoint(): string
{
return $this->endpoint;
}
/**
* @return array<string, string>
*/
public function getCustomHeaders(): array
{
return $this->customHeaders;
}
public function addCustomHeader(string $key, string $value): void
{
$this->customHeaders[$key] = $value;
}
public function getHttpClient(): ?ClientInterface
{
return $this->httpclient;
}
/**
* @return array<string, mixed>
*/
public function getExporterMetadata(): array
{
return $this->exporterMetadata;
}
}