ssola/enabler 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

ssola/enabler

Composer 安装命令:

composer require ssola/enabler

包简介

Enable a functionality to specific IP, specific group / users or by percentage of visitors.

README 文档

README

Enabler is a simple feature flag package. With this package you can display/hide your awesome new features to customers in order to deploy your new stuff smoothly and to have everything under control.

I would like to know what do you think about this package and if you have an idea about how to improve this package plase create a new issue.

Requirements

To use this package you only need to have:

  • PHP >= 5.4
  • Redis (it's our default persistence tool)
  • Composer

If you need a different persistence tool like Memcache or MySQL you can simply write your own Storable adapter.

Installation

composer require ssola/enabler

composer update

How it works?

With Enabler is really simple to show/hide features to your users. Let me show how it works with this little example:

Requirement: We need to deploy our new killer feature gradually. We expect a lot of new people using it and we need to be completely sure that it works properly. At this stage we only want to enable this feature to a really small set of customers: exactly 1% of them.

First of all we have to create our new Feature and include which filters should be used.

$feature = new Enabler\Feature(
  'secret-feature',
  true,
  [
    'Enabler\Filter\Distributed' => [1]
  ]
);

$enabler = new Enabler\Enabler($storage);
$enabler->storage()->create($feature);

// At this point feature has been created and will use the Distributed filter to display it only to 1% of our visitors
// after this we can create the condition:

if ($enabler->enabled('secret-feature')) {
  // Here your feature for only 1% of your visitors.
}

Finally you determined to test your new Feature in a new scenario. In this respect we only want to reveal it to logged in customers.For that logic we have implemented the Identifier filter. You only have to instantiate an Identity object passing the required user data. In this case we must to pass the user id and group to which it belongs.

$identity = new Enabler\Identity(MyUserClass::getUserId(), MyUserClass::getGroup());

$feature = new Enabler\Feature(
  'secret-feature',
  true,
  [
    'Enabler\Filter\Identifier' => ['groups' => ['early-adopters', 'test-users']]
  ]
);

$enabler = new Enabler\Enabler($storage, $identity);
$enabler->storage()->create($feature);

if ($enabler->enabled('secret-feature')) {
  // Here your feature for users that belongs to early-adopters or test-users group
}

But now imagine that we need to display only to a bigger amount (10%) of our test-users group in a particular date range. We can do it easily adding more than one filter to the feature filter chain, like this:

$identity = new Enabler\Identity(MyUserClass::getUserId(), MyUserClass::getGroup());

$feature = new Enabler\Feature(
  'secret-feature',
  true,
  [
    'Enabler\Filter\Distributed' => [10],
    'Enabler\Filter\Identifier' => ['groups' => ['test-users']],
    'Enabler\Filter\Date' => ['from' => new DateTime('2014-10-30'), 'to' => new DateTime('2015-10-30')]
  ]
);

$enabler = new Enabler\Enabler($storage, $identity);
$enabler->storage()->create($feature);

if ($enabler->enabled('secret-feature')) {
  // Here your feature for users that belongs to early-adopters or test-users group
}

Extend me

Storage

We need a storage adapter to be able to store your Feature configuration in some place. Our default storage tool is Redis, but if feel free to write your own adapters.

It's as simples as this:

class MyAwesomeStorageAdapter implements Enabler\Storage\Storable
{
  public function create (Feature $feature) {
    // do your magic here!
  }
  
  public function delete ($name) {
    // delete a specific Feature
  }
  
  public function get ($name) {
    return $myFeature;
  }
}

#### Filters

At the moment we support four different filters Random Weighted Distribution, IP, Date / Date Range and Identity. But we thought people will have great ideas and it's really simple to create your own filters.

class FilterByWeather implements Enabler\Filter\Filterable
{
  public function filter ($value, Feature $feature, Identity $identity) {
    // our value is Sunny
    $currentWeather = Weather::getFromIp(IP::getIp());
    
    if($currentWeather == $value) {
      return true;
    }
    
    return false;
  }
}

Features

You can choose among different filters or create your owns in order to displar/hide your features:

  • By IP: Display your feature only to certain IP or IP range (TBD)
  • By Random weight distribution: You can display your feature for example only to 10% or your visitors
  • By Identity: Use our Identity class or create your own in order to have access to User Id and/or Group.
  • By date or date range: Display your feature depending on specific date or set a range to display it only for a precise range of dates.

Bitdeli Badge

ssola/enabler 适用场景与选型建议

ssola/enabler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15 次下载、GitHub Stars 达 22, 最近一次更新时间为 2014 年 11 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 22
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-11-27