jadb/feature_toggle 问题修复 & 功能扩展

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

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

jadb/feature_toggle

Composer 安装命令:

composer require jadb/feature_toggle

包简介

Feature Flip, Feature Flag, Feature Switch

README 文档

README

Build Status Total Downloads License

Feature Toggle

a.k.a. Feature Flip, Feature Flag, Feature Switch

From Wikipedia:

Feature Toggle is a technique in software development that attempts to provide an alternative to maintaining multiple source code branches, called feature branches.

Continuous release and continuous deployment enables you to have quick feedback about your coding. This requires you to integrate your changes as early as possible. Feature branches introduce a by-pass to this process. Feature toggles brings you back to the track, but the execution paths of your feature is still “dead” and “untested”, if a toggle is “off”. But the effort is low to enable the new execution paths just by setting a toggle to “on”.

Common use cases:

  • Limited testing (i.e. employees only based on email address, subset of users, etc.)
  • Gradual feature release (i.e. by location, by subscription, by browser, etc.)

Install

FeatureToggle can be installed using Composer (of course, you could always clone it from GitHub).

NOTE: For PHP5.x support, please check the 0.1.0 branch.

In composer.json:

{
    "require": {
        "jadb/feature_toggle": "^1.0"
    }
}

To install, you may then run:

$ php composer.phar install

Example

In your application's bootstrap:

use FeatureToggle\FeatureRegistry;
use Predis\Client as Redis;

FeatureRegistry::setStorage(new Redis());

FeatureRegistry::init('Cool Feature', [
	'description' => 'A cool new feature!',
	'strategies' => [
		'UserAgent' => [['/opera/', '/Mozilla\/5\.0/']],
		function ($Feature) {
			return !empty($_SESSION['isAdmin']);
		},
		function ($Feature) {
			return !empty($_SESSION[$Feature->getName()]);
		}
	]
]);

FeatureRegistry::init('Another Cool Feature', [
	'type' => 'threshold', // use the `ThresholdFeature`
	'description' => 'Another cool new feature!',
	'strategies' => [
		'UserAgent' => [['/opera/', '/Mozilla\/5\.0/']],
		function ($Feature) {
			return !empty($_SESSION['isAdmin']);
		},
		function ($Feature) {
			return !empty($_SESSION[$Feature->getName()]);
		}
	]
])->threshold(2); // Require at least 2 strategies to pass

and then, anywhere in your code, you can check this feature's status like so:

if (\FeatureToggle\FeatureManager::isEnabled('Cool Feature')) {
	// do something
}

What's included?

Features

  • BooleanFeature: Enabled if one ore more strategies pass.
  • StrictBooleanFeature: Enabled only if entire strategies' set passes.
  • ThresholdFeature: Enabled only if a minimum number of strategies pass.
  • EnabledFeature: Forces feature to always be enabled.
  • DisabledFeature: Forces feature to always be disabled.

Features MUST implement the FeatureInterface.

Strategies

  • DateTimeStrategy: Compares today's time to set date and time.
  • DateTimeRangeStrategy: Checks if today's time is in set date time range.
  • UserAgentStrategy: Checks if browser's user agent matches any allowed agent.

Strategies MUST implement the StrategyInterface.

Storage Adapters

  • HashStorage: Default. Basic associative array (a.k.a. in memory)
  • FileStorage: Filesystem used (only good if features stored in database).
  • MemcachedStorage: Memcached store, requires the Memcached extension.
  • RedisStorage: Redis store, requires the predis/predis package.

Storage adapaters MUST implement the StorageInterface.

Todo

  • PercentageStrategy enable feature to a percentage of users - requires RedisStorage
  • Option to automatically disable a feature if error threshold reached - requires RedisStorage

Contributing

  • Fork
  • Mod, fix, test
  • Optionally write some documentation (currently in README.md)
  • Send pull request

All contributed code must be licensed under the [BSD 3-Clause License][bsd3clause].

Bugs & Feedback

http://github.com/jadb/feature_toggle/issues

License

Copyright (c) 2014, Jad Bitar

Licensed under the MIT license.

Redistributions of files must retain the above copyright notice.

统计信息

  • 总下载量: 4k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2014-02-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固