-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathFlagdProvider.php
61 lines (47 loc) · 2.26 KB
/
FlagdProvider.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
<?php
declare(strict_types=1);
namespace OpenFeature\Providers\Flagd;
use OpenFeature\Providers\Flagd\config\IConfig;
use OpenFeature\Providers\Flagd\config\Validator;
use OpenFeature\Providers\Flagd\service\ServiceFactory;
use OpenFeature\Providers\Flagd\service\ServiceInterface;
use OpenFeature\implementation\provider\AbstractProvider;
use OpenFeature\interfaces\flags\EvaluationContext;
use OpenFeature\interfaces\flags\FlagValueType;
use OpenFeature\interfaces\provider\Provider;
use OpenFeature\interfaces\provider\ResolutionDetails;
class FlagdProvider extends AbstractProvider implements Provider
{
protected static string $NAME = 'FlagdProvider';
private IConfig $config;
private ServiceInterface $service;
public function __construct(mixed $config = null)
{
$this->config = Validator::validate($config);
$this->service = ServiceFactory::fromConfig($this->config);
}
public function resolveBooleanValue(string $flagKey, bool $defaultValue, ?EvaluationContext $context = null): ResolutionDetails
{
return $this->service->resolveValue($flagKey, FlagValueType::BOOLEAN, $defaultValue, $context);
}
public function resolveStringValue(string $flagKey, string $defaultValue, ?EvaluationContext $context = null): ResolutionDetails
{
return $this->service->resolveValue($flagKey, FlagValueType::STRING, $defaultValue, $context);
}
public function resolveIntegerValue(string $flagKey, int $defaultValue, ?EvaluationContext $context = null): ResolutionDetails
{
return $this->service->resolveValue($flagKey, FlagValueType::INTEGER, $defaultValue, $context);
}
public function resolveFloatValue(string $flagKey, float $defaultValue, ?EvaluationContext $context = null): ResolutionDetails
{
return $this->service->resolveValue($flagKey, FlagValueType::FLOAT, $defaultValue, $context);
}
public function resolveObjectValue(string $flagKey, mixed $defaultValue, ?EvaluationContext $context = null): ResolutionDetails
{
return $this->service->resolveValue($flagKey, FlagValueType::OBJECT, $defaultValue, $context);
}
public function resolveAllValues(?EvaluationContext $context = null): array
{
return $this->service->resolveValues($context);
}
}