gathern/growthbook-openfeature-provider 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gathern/growthbook-openfeature-provider

最新稳定版本:v1.0.0

Composer 安装命令:

composer require gathern/growthbook-openfeature-provider

包简介

this package provide growthbook (a feature flag serice) provider to openfeature

README 文档

README

Latest Version on Packagist Tests Total Downloads

This is where your description should go. Try and limit it to a paragraph or two. Consider adding a small example.

Installation

You can install the package via composer:

composer require gathern/growthbook-openfeature-provider

Usage

<?php
    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',
    );

if you need to get the flag value of specific user attributes you can openfeature evaluation-context and set the user data as attributes .

<?php
    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)
                )
            );

you can follow the usage of openfeature-php-package and docs of growthbook-php-sdk for instance of growthbook

if you need to use all growthbook sdk features or any feature service throw the openfeature api to reach feature using spatie/invade package just install it and follow this example

<?php

$openfeatureAPI= invade($client)->api;
$provider=invade($openfeatureAPI)->getProvider();
$growthbook=invade($provider)->growthbook;
print_r($growthbook->getFeatures());
print_r($growthbook->getAttributes());
print_r( $growthbook->getViewedExperiments());

Testing

composer test:unit

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 3.19k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-10