定制 dose/laravelfeature 二次开发

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

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

dose/laravelfeature

Composer 安装命令:

composer require dose/laravelfeature

包简介

Rampup and AB testing library inspired for Laravel.

README 文档

README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Rampup and AB testing library inspired by Etsy\Feature for Laravel.

How to use

After you have added this package to your composer file you will need to register it's Service Provider.

'Dose\LaravelFeature\LaravelFeatureServiceProvider'

You also want to publish configuration so you can define your features.

php artisan config:publish dose/laravelfeature // Laravel 4
php artisan vendor:publish --provider="Dose\LaravelFeature\LaravelFeatureServiceProvider" // Laravel 5

To gain access to the API you need to resolve an instance out of the Service Container.

$feature = app()->make('Dose\LaravelFeature\LaravelFeatureInterface');

Of course, dependency injection can also be used.

Get Variant

$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).

Set Context

$feature->setContext($context);

This is not something commonly used but it lets you change the context in which a variant is selected. By default, user's session id is used. This means that the variant will be the same for the span of the session.

Sometimes you might want to rotate variants based on different criteria. For example, if you want all posts by a certain author to have a set of features consistent for all users. You can do that by setting the context.

$feature->setContext('post_author:' . $postAuthor);

AB Testing

It is a common use case to run multiple AB tests with multiple variants at the same time. In order to get valuable test results, only one test can be active at once. In order to achieve this, you need to define a wrapper feature. The variants will represent each test.

'tests' => [
    'test_a',
    'test_b',
    'test_c',
],
'test_a' => [
   'variant_a',
   'variant_b',
],
'test_b' => [
   'variant_a',
   'variant_b',
],
'test_c' => [
   'variant_a',
   'variant_b',
],

This allows us to check if a particular test is active and then retrieve it's variant.

if ($feature->getVariant('tests') == 'test_a') {
    $variant = $feature->getVariant('test_a');
}

Config

There are two configuration files that you can use to control the behavior.

config.php

In this file, you can specify if you want users to be able to override the variant selection with a specific URL parameter.

'allow_override' => false,

This is disabled by default. You may control who can use the URL override by defining your own logic.

'allow_override' => Gate::allows('feature_url_override'),

features.php

All your features are defined here.

There is a ton of flexibility in defining features. We will start with the most verbose and then work down.

Each feature can have any number of variants with each variant defining it's own odds.

'feature' => [
    'variant_a' => 25,
    'variant_b' => 25,
    'variant_c' => 50,
],

In the above example, each variant has the specified chance of being selected. Variants with odds below 0 are normalized to 0. The variants are processed top to bottom. If the sum of odds exceeds 100 the feature is saturated and any variants above that threshold have no chance of being selected.

'feature' => [
    'variant_a' => 100,
    'variant_b' => 25,
    'variant_c' => 50,
],

The above feature will always return variant_a.

You can omit the odds and just specify the variants. In this case, the variants are evenly spread out.

'feature' => [
    'variant_a',
    'variant_b',
],

In this case, both variants have 50% chance of being selected.

These approaches can be mixed. It is important to note that variants with specified odds will be processed first and then any remaining odds are distributed among the auto-scaled variants.

'feature' => [
    'variant_a' => 50,
    'variant_b',
    'variant_c',
],

The first variant has 50% chance of coming up while the other two have 25% chance each.

To specify a simple ON/OFF feature we just include a single variant.

'feature' => [
    'enabled' => 100,
],

This feature is always on. We can adjust the odds to turn it off completely or achieve a ramp-up functionality.

It is also possible to shorten the above example by just defining the odds for the feature itself.

'feature' => 50,

This feature will be on for 50% of the users.

URL override

If the URL override is enabled you can force a particular variant by specifying it in the URL

?features=example_feature:variant_1

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

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 964
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

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