定制 systream/feature-switch 二次开发

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

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

systream/feature-switch

Composer 安装命令:

composer require systream/feature-switch

包简介

This package provides feature switch functionality. A/B test support and time based switcher.

README 文档

README

Installation

You can install this package via packagist.org with composer.

composer require systream/feature-switch

composer.json:

"require": {
    "systream/feature-switch": "1.*"
}

This library requires php 5.6 or higher.

Usage examples

By default the feature is not enabled.

$feature = new Feature('foo_bar_feature_key');
$feature->isEnabled(); // will return: false

If you want to change the feature state, you have to set up one or more switcher.

Switchers (/ toggles / flippers)

Simple

You can easily switch on a feature:

$feature = new Feature('foo_bar_feature_key');
$feature->addSwitcher(Simple::on());
$feature->isEnabled(); // will return: true

A/B testing

This will enable the feature approximately 50% of the visitors. The feature status is tracking by cookie, so if the visitor returns, the same state of the feature will be shown.

$feature = new Feature('foo_bar_feature_key');
$feature->addSwitcher(new AB());
$feature->isEnabled();

Time based switching

With this library you can set up a time based feature toggle too. For example you cool new feature will be available for every visitor after a point in time.

$feature = new Feature('foo_bar_feature_key');
$feature->addSwitcher(new Until(\DateTime::createFromFormat('Y-m-d H:i:s', '2017-08-12 10:00:00')));
$feature->isEnabled(); // brefore 2017-08-12 10:00:00 it's return false, after will return true

If you want to disable a feature after a date:

$feature = new Feature('foo_bar_feature_key');
$feature->addSwitcher(new Until(\DateTime::createFromFormat('Y-m-d H:i:s', '2017-08-12 10:00:00'), false));
$feature->isEnabled(); // brefore 2017-08-12 10:00:00 it's return true, after will return false

Callback

For custom cases:

$feature = new Feature('foo_bar_feature_key');
$feature->addSwitcher(
	new Callback(function() {
		/* do custom logic */
		return true;
	})
);
$feature->isEnabled();

Writing custom switcher

The only thing you should do that your class need to implement FeatureSwitcherInterface interface.

Add multiple switcher/toggle

$feature = new Feature('foo_bar_feature_key');
$feature->addSwitcher(new AB());
$feature->addSwitcher(new Until(\DateTime::createFromFormat('Y-m-d H:i:s', '2017-08-12 10:00:00')));
$feature->isEnabled();

The feature will passed to all of the switcher until one of them return true; In this case the feature will tested first with AB switcher and if it returns false then it passes to the next time based switcher.

FeatureSwitch

Simple feature builder

$feature1 = FeatureSwitch::buildFeature('foo_feature', true); // enabled
$feature2 = FeatureSwitch::buildFeature('another_bar_feature', false); // disabled

Container

$featureSwitch = new FeatureSwitch();
$featureSwitch->addFeature(FeatureSwitch::buildFeature('foo', true));
 
$feature = new Feature('bar2');
$feature->addSwitcher(new AB());

$featureSwitch->addFeature($feature);
$featureSwitch->isEnabled('foo'); // true
$featureSwitch->isEnabled('bar2');

FeatureSwitchArray

This class decorates the FeatureSwitch with array access support.

You can user FeatureSwitchArray class as Array:

$featureSwitch = new FeatureSwitchArray();

$featureSwitch[] = FeatureSwitch::buildFeature('foo', true);
$featureSwitch->isEnabled('foo'); // returns true
$featureSwitch['foo']->isEnabled();

Test

Build Status

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-05-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固