定制 gathern/growthbook-openfeature-provider 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱: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.14k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 未知

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固