PHP code example of launchdarkly / openfeature-server
1. Go to this page and download the library: Download launchdarkly/openfeature-server library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
launchdarkly / openfeature-server example snippets
use OpenFeature\OpenFeatureAPI;
use OpenFeature\implementation\flags\Attributes;
use OpenFeature\implementation\flags\EvaluationContext;
$provider = new LaunchDarkly\OpenFeature\Provider("my-sdk-key");
$api = OpenFeatureAPI::getInstance();
$api->setProvider($provider);
// Refer to OpenFeature documentation for getting a client and performing evaluations.
$context = new EvaluationContext("the-key");
$attributes = new Attributes(["kind" => "organization"]);
$context = new EvaluationContext("org-key", $attributes);
$attributes = [
"kind" => "organization",
"myCustomAttribute" => "myAttributeValue",
"privateAttributes" => ["myCustomAttribute"]
];
$context = new EvaluationContext("org-key", new Attributes($attributes));
$attributes = [
"kind" => "organization",
"organization" => [
"name" => "the-org-name",
"targetingKey" => "my-org-key",
// This will ONLY apply to the "organization" attributes.
"privateAttributes" => ["myCustomAttribute"],
// This attribute will be private.
"myCustomAttribute" => "myAttributeValue",
],
"user" => [
"key" => "my-user-key",
"anonymous" = > true,
// This attribute will not be private.
"myCustomAttribute" => "myAttributeValue",
]
];
$context = new EvaluationContext(null, new Attributes($attributes));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.