-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.php
67 lines (53 loc) · 1.91 KB
/
main.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
<?php
require 'vendor/autoload.php';
function showEvaluationResult(string $key, bool $value) {
echo PHP_EOL;
echo sprintf("*** The %s feature flag evaluates to %s", $key, $value ? 'true' : 'false');
echo PHP_EOL;
if ($value) {
showBanner();
}
}
function showBanner() {
echo PHP_EOL;
echo " ██ " . PHP_EOL;
echo " ██ " . PHP_EOL;
echo " ████████ " . PHP_EOL;
echo " ███████ " . PHP_EOL;
echo "██ LAUNCHDARKLY █" . PHP_EOL;
echo " ███████ " . PHP_EOL;
echo " ████████ " . PHP_EOL;
echo " ██ " . PHP_EOL;
echo " ██ " . PHP_EOL;
echo PHP_EOL;
}
// Set $sdkKey to your LaunchDarkly SDK key.
$sdkKey = getenv("LAUNCHDARKLY_SDK_KEY") ?? "";
// Set $featureFlagKey to the feature flag key you want to evaluate.
$featureFlagKey = getenv("LAUNCHDARKLY_FLAG_KEY");
if (!$featureFlagKey) {
$featureFlagKey = 'sample-feature';
}
$ci = getenv("CI") ?? false;
if (!$sdkKey) {
echo "*** Please set the environment variable LAUNCHDARKLY_SDK_KEY to your LaunchDarkly SDK key first" . PHP_EOL . PHP_EOL;
exit(1);
} else if (!$featureFlagKey) {
echo "*** Please set the environment variable LAUNCHDARKLY_FLAG_KEY to a boolean flag first" . PHP_EOL . PHP_EOL;
exit(1);
}
$client = new LaunchDarkly\LDClient($sdkKey);
// Set up the evaluation context. This context should appear on your LaunchDarkly contexts dashboard soon after you run the demo.
$context = LaunchDarkly\LDContext::builder("example-user-key")
->kind("user")
->name("Sandy")
->build();
$lastValue = null;
do {
$flagValue = $client->variation($featureFlagKey, $context, false);
if ($flagValue !== $lastValue) {
showEvaluationResult($featureFlagKey, $flagValue);
$lastValue = $flagValue;
}
sleep(1);
} while(!$ci);