定制 playox/feature-tox 二次开发

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

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

playox/feature-tox

最新稳定版本:0.0.1

Composer 安装命令:

composer require --dev playox/feature-tox

包简介

Feature toggle on steroids.

README 文档

README

FeatureTox is a simple and powerful feature toggle library. Only a few lines of configuration necessary - and still very flexible and expandable. This Library is based on https://github.com/bestit/flagception-sdk and further developed from us.

Latest Stable Version Testing FeatureTox codecov Total Downloads License

Download the library

Open a command console, enter your project directory and execute the following command to download the latest stable version of this library:

$ composer require playox/FeatureTox

Quick example

Just create a FeatureManager instance and pass your activator to start with feature toggling.

// MyClass.php
class MyClass
{
    public function doSomething()
    {
        // The activator decide if the feature is active or not
        // You can use your own activator if you implement the interface
        $activator = new ArrayActivator();

        $manager = new FeatureManager($activator);

        if ($manager->isActive('your_feature_name')) {
            // do something
        }
    }
}

The activator is the most important class and decide if the given feature is active or not. The ArrayActivator needs an array with active feature names as constructor argument. If the requested feature is in array, it will return true otherwise false. Example:

// MyClass.php
class MyClass
{
    public function doSomething()
    {
        $activator = new ArrayActivator([
            'feature_abc',
            'feature_def',
            'feature_ghi'
        ]);

        $manager = new FeatureManager($activator);

        // Will return true
        if ($manager->isActive('feature_def')) {
            // do something
        }

        // Will return false
        if ($manager->isActive('feature_wxy')) {
            // do something
        }
    }
}

This library ships an ArrayActivator, a ConstraintActivator, a EnvironmentActivator, CookieActivator and a ChainActivator.

In most cases you will create your own activator (eg. for doctrine). Just implement the FeatureActivatorInterface.

You can use a CacheActivator if you want to cache the result from some time intensive activators.

Advanced example

Sometimes your activator needs more context for deciding if a feature is active or not. You can optionally add a context object as second argument to the manager and check the context data in your activator.

Example:

// MyClass.php
class MyClass
{
    public function doSomething(User $user)
    {
        $activator = new YourCustomDoctrineActivator();

        $manager = new FeatureManager($activator);
        $context = new Context();
        $context->add('user_id', $user->getId());
        
        // Check the feature with context
        if ($manager->isActive('feature_def', $context)) {
            // do something
        }
        
         // Check the feature without context (result may differ from above)
         if ($manager->isActive('feature_def')) {
             // do something
         }
    }
}

// YourCustomDoctrineActivator.php
class YourCustomDoctrineActivator implements FeatureActivatorInterface
{
    public function isActive($name, Context $context)
    {
        return $context->get('user_id') === 12;
    }
}

You can also add the context data globally instead of adding the context to each feature request. Just pass a class which implement the ContextDecoratorInterface as second argument for the feature manager constructor:

// MyClass.php
class MyClass
{
    public function doSomething(User $user)
    {
        $activator = new YourCustomDoctrineActivator();
        $decorator = new ArrayDecorator([
            'user_id' => $user->getId()
        ]);

        $manager = new FeatureManager($activator, $decorator);

        // Check the feature with the global defined context         
        if ($manager->isActive('feature_def')) {
            // do something
        }
    }
}

//YourCustomDoctrineActivator.php
class YourCustomDoctrineActivator implements FeatureActivatorInterface
{
    public function isActive($name, Context $context)
    {
        return $context->get('user_id') === 12;
    }
}

You can also mix both variants:

// MyClass.php
class MyClass
{
    public function doSomething(User $user)
    {
        $activator = new YourCustomDoctrineActivator();
        $decorator = new ArrayDecorator([
            'user_id' => $user->getId()
        ]);

        $manager = new FeatureManager($activator, $decorator);

        $context = new Context();
        $context->add('user_name', $user->getUsername());

        // Check the feature with the global defined context         
        if ($manager->isActive('feature_def', $context)) {
            // do something
        }
    }
}

This library ships an ArrayDecorator and a ChainDecorator.

playox/feature-tox 适用场景与选型建议

playox/feature-tox 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.89k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2022 年 09 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「testing」 「flags」 「feature」 「toggle」 「rollout」 「feature-flags」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 playox/feature-tox 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 playox/feature-tox 我们能提供哪些服务?
定制开发 / 二次开发

基于 playox/feature-tox 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 0
  • Forks: 18
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-08