dose/feature
Composer 安装命令:
composer require dose/feature
包简介
Simple Feature API enabling rampups and A/B testing.
关键字:
README 文档
README
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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dose/feature 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A block that displays featured content - large image, title, description and link.
Testing Suite For Lumen like Laravel does.
MaxAl Subscriptions is a flexible plans and subscription management system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
The PHP SDK for Checkmango
Rinvex Subscriptions is a flexible plans and subscription management system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
Rinvex Subscriptions is a flexible plans and subscription management system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
统计信息
- 总下载量: 8.85k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 9
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-02-03