-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathUnleashHttpClient.php
51 lines (41 loc) · 1.2 KB
/
UnleashHttpClient.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
<?php
namespace Stogon\UnleashBundle\HttpClient;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\NullLogger;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class UnleashHttpClient implements LoggerAwareInterface
{
use LoggerAwareTrait;
private HttpClientInterface $httpClient;
protected string $apiUrl;
protected string $instanceId;
protected string $environment;
public function __construct(HttpClientInterface $unleashClient, string $apiUrl, string $instanceId, string $environment)
{
$this->httpClient = $unleashClient;
$this->apiUrl = $apiUrl;
$this->instanceId = $instanceId;
$this->environment = $environment;
$this->logger = new NullLogger();
}
public function fetchFeatures(): array
{
try {
$response = $this->httpClient->request('GET', 'client/features');
$features = $response->toArray();
} catch (\Throwable $th) {
$this->logger->critical('Could not fetch features flags', [
'exception' => $th,
]);
return [];
}
if (array_key_exists('features', $features)) {
$this->logger->debug('Fetched feature flags from remote', [
'feature_flags' => $features['features'],
]);
return $features['features'];
}
return [];
}
}