承接 dose/feature 相关项目开发

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

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

dose/feature

Composer 安装命令:

composer require dose/feature

包简介

Simple Feature API enabling rampups and A/B testing.

README 文档

README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Feature is a rampup and AB testing library inspired by Etsy\Feature. It is NOT a direct replacement, but it can do everything Etsy's library can and more.

API

The main method is:

$feature->getVariant($name);

This will return a selected variant. It may also return NULL if the feature does not exist or if none of the variants were selected (features with incomplete coverage).

Before you can check for variants you need to define a few methods that will allow the Feature library to retrieve your configuration on-demand. This is done by injecting an implementation of the Connector interface into the Feature instance.

The Connector interface defines two methods:

getContext();

This is used to retrieve a context in which the variant will be selected. A variant will be selected for each context individually. Most of the time this will be set to a unique user id or session id. You can, for example, set this to reflect an article id. In this case, all users will see the same result but it will change between different articles.

getEntity($name);

This method allows the Feature instance to retrieve an instance of Entity class that will be used to select a variant.

Entity

To define a feature, your implementation of the getEntity($name) method needs to return an Entity instance. Once you create an Entity object, add variants to it using the following method:

$entity->addVariant($name, $odds)

This will add a specified variant to the feature. The odds can range between 0 and 100 and don't need to be whole numbers.

Migrating from Etsy\Feature

How do I check if a feature is enabled?

Etsy's library separates the concept of a feature and variant; which forces you to wrap each call to the variant() method in a conditional.

if (Feature::isEnabled('my_feature')) {
    switch (Feature::variant('my_feature')) {
        case 'foo':
            // do stuff appropriate for the foo variant
            break;
        case 'bar':
            // do stuff appropriate for the bar variant
            break;
    }
}

We eliminated the isEnabled($name) method completely and use the getVariant($name) method to determine if a feature is enabled:

switch $feature->getVariant($name) {
    case 'foo':
        // do stuff appropriate for the foo variant
        break;
    case 'bar':
        // do stuff appropriate for the bar variant
        break;
    case null:
        // feature is not enabled
        break;
}

Or:

if ($feature->getVariant($name)) {
    // Feature is enabled as long as variant evaluates to true
}

How do I define a feature that is on 50% of the time and has no variants?

This is done by defining a single variant with the odds set to 50:

$entity->addVariant(true, 50);

Now you can simply check if the selected variant is true:

if ($feature->getVariant($name)) {
    // Feature is on
}

How do I define a feature that applies to certain users or user groups?

This is done during the configuration of the feature:

if (isAdmin()) {
    $entity->addVariant(true, 100);
} else {
    $entity->addVariant(true, 20);
}

In the above example, the feature will be always on for admins and for 20% of visitors.

dose/feature 适用场景与选型建议

dose/feature 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.85k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2016 年 02 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-03