<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
gathern / growthbook-openfeature-provider example snippets
use Cache\Adapter\Apcu\ApcuCachePool;
use Growthbook\Growthbook;
use OpenFeature\OpenFeatureAPI;
$growthbook Growthbook::create();
//By default, there is no caching enabled.
// You can enable it by passing any PSR16-compatible
// instance into the withCache method.
// Any psr-16 library will work
$cache = new ApcuCachePool();
$growthbook ->withCache($cache);
$api = OpenFeatureAPI::getInstance();
$api->setProvider(new GrowthbookOpenfeatureProvider(
growthbook: Growthbook,
clientKey: '<Growthbook_CLIENT_KEY>',
apiHost: '<Growthbook_API_HOST>',
));
$client = $api->getClient(
GrowthbookOpenfeatureProvider::class,
'v1.17',
);
$client->getStringValue
(
flagKey: 'enable-success-button',
defaultValue: 'wrong',
);
use OpenFeature\implementation\flags\Attributes;
use OpenFeature\implementation\flags\MutableEvaluationContext;
$user_data = [
'name' => 'john Doe',
'age' => '20',
'gender' => 'male',
'nationality' => 'martian'
];
echo $client->getBooleanValue(
flagKey: 'test-boolean',
defaultValue: false,
context: new MutableEvaluationContext(
targetingKey: "targeting-key-value",
attributes: new Attributes(attributesMap: $user_data)
)
);