-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy path06-prefixing.php
executable file
·45 lines (35 loc) · 1.32 KB
/
06-prefixing.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
<?php
/**
* Let's assume you want features to be prefixed per environment, here's a sample implementation
*/
use Unleash\Client\Configuration\UnleashContext;
use Unleash\Client\DTO\Variant;
use Unleash\Client\Unleash;
use Unleash\Client\UnleashBuilder;
require_once __DIR__ . '/_common.php';
class PrefixedUnleash implements Unleash
{
public function __construct(private string $prefix, private Unleash $original)
{
}
public function isEnabled(string $featureName, UnleashContext $context = null, bool $default = false): bool
{
return $this->original->isEnabled("{$this->prefix}.{$featureName}", $context, $default);
}
public function getVariant(string $featureName, ?UnleashContext $context = null, ?Variant $fallbackVariant = null): Variant
{
return $this->original->getVariant("{$this->prefix}.{$featureName}", $context, $fallbackVariant);
}
public function register(): bool
{
return $this->original->register();
}
}
$unleash = UnleashBuilder::create()
->withAppName($appName)
->withAppUrl($appUrl)
->withInstanceId($instanceId)
->withHeader('Authorization', $apiKey)
->build();
$unleash = new PrefixedUnleash('myPrefix', $unleash);
var_dump($unleash->isEnabled('test')); // will ask for myPrefix.test