承接 featurit/featurit-sdk-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

featurit/featurit-sdk-php

最新稳定版本:v1.0.1

Composer 安装命令:

composer require featurit/featurit-sdk-php

包简介

PHP SDK for FeaturIT

README 文档

README

Build Status Total Downloads Latest Stable Version License

PHP client for the FeaturIT Feature Flag management platform.

Description

This package aims to simplify the integration of the FeaturIT API in a PHP project.

Getting started

Dependencies

  • PHP >= 8.0
  • psr/http-client-implementation
  • psr/simple-cache-implementation

Installing

composer require featurit/featurit-sdk-php

If there's no package providing psr/http-client-implementation, visit https://packagist.org/providers/psr/http-client-implementation and choose the package that better suits your project.

If there's no package providing psr/simple-cache-implementation, visit https://packagist.org/providers/psr/simple-cache-implementation and choose the package that better suits your project.

Basic Usage

$featurit = new \Featurit\Client\Featurit(
    'my-tenant-subdomain', 
    'my-environment-key'
);

$isFeatureFlagActive = $featurit->isActive('MY_FEATURE_NAME');

if ($isFeatureFlagActive) {
    my_feature_code();
}

Segmentation Usage

This is useful when you want to show different versions of your features to your users depending on certain attributes.

$featurit = new \Featurit\Client\Featurit(
    'my-tenant-subdomain', 
    'my-environment-key'
);

$userContext = new \Featurit\Client\Modules\Segmentation\DefaultFeaturitUserContext(
    '1234',
    '123af503',
    '192.168.1.1',
    [
        'role' => 'ADMIN',
        'email' => 'featurit.tech@gmail.com',
    ] 
);

$featurit->setUserContext($userContext);

$isFeatureFlagActive = $featurit->isActive('MY_FEATURE_NAME');

if ($isFeatureFlagActive) {
    $featureVersion = $featurit->version('MY_FEATURE_NAME');
    
    if ($featureVersion == 'v1') {
        my_feature_v1_code();
    } else if ($featureVersion == 'v2') {
        my_feature_v2_code();
    }
}

Creating a UserContextProvider

In some cases you want to fill the UserContext data once and forget about it when checking for feature flags.

If that is your case you can implement your own UserContextProvider and pass it to the Featurit client constructor (we recommend using our builder in order to create a new Featurit client).

class MyFeaturitUserContextProvider implements FeaturitUserContextProvider

    public function getContext(): FeaturitUserContext
    {
        $contextData = get_my_context_data();
        
        return new DefaultFeaturitUserContext(
            $contextData['userId'],
            $contextData['sessionId'],
            $contextData['ipAddress'],
            [
                'role' => $contextData['role'],
                ...
            ]
        );
    }
}

Event Tracking

In order to track some event in your application, you can add this once the event has happened:

$featurit = new \Featurit\Client\Featurit(
    'my-tenant-subdomain', 
    'my-environment-key'
);

$userContext = new \Featurit\Client\Modules\Segmentation\DefaultFeaturitUserContext(
    '1234',
    '123af503',
    '192.168.1.1',
    [
        'role' => 'ADMIN',
        'email' => 'featurit.tech@gmail.com',
    ] 
);

$featurit->setUserContext($userContext);

$featurit->trackPerson();

// trackPerson will track a new Person with the data set in the FeaturitUserContext.

$featurit->track('MY_EVENT_NAME', [
    'a_property_name' => 'a_property_value',
    'another_property_name' => 'another_property_value',
]);

All the events and people you track in the same request will be accumulated and associated to the current FeaturitUserContext, if for some reason you want to send the data immediately, you can do as follows:

$featurit->flush();

Authors

FeaturIT

https://www.featurit.com

featurit.tech@gmail.com

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-11-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固