vehikl/flip 问题修复 & 功能扩展

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

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

vehikl/flip

Composer 安装命令:

composer require vehikl/flip

包简介

A Feature Toggle implementation

README 文档

README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Flip is a simple Feature Toggle implementation. Features are implemented as independent classes and are "mixed" into the class you want the feature to be exposed from.

Install

Via Composer

$ composer require vehikl/flip

Usage

A Flip feature is just a regular PHP class with a few required methods.

enabled - This method returns a boolean value indicating if the feature is enabled or not

toggles - This method returns an array of available feature toggles. The array is keyed by the name of the method which is called to run the feature. The value of each key is an associative array with keys on and off, each key is mapped to the appropriate method to call depending on if the feature is "on" or "off".

class SomeFeature extends \Vehikl\Flip\Feature
{
    /**
     * Decides under which conditions this Feature is enabled
     */
    public function enabled()
    {
        return random_int(0, 1) == 1;
    }

    /**
     * Returns an array of available toggles for this feature
     */
    public function toggles()
    {
        return [
            'someToggle' => [
                'on' => 'whenOn',
                'off' => 'whenOff'
            ]
        ];
    }
    
    public function whenOn()
    {
        return "I'm on!";
    }

    public function whenOff()
    {
        return "I'm off!";
    }
}

class SomeClass
{
    use Vehikl\Flip\Featurable;
    
    protected $features = [SomeFeature::class];
    
    public function someBehaviour()
    {
        // no need for if/else blocks, just call the toggle using the
        // `flip` helper
        return $this->flip()->someToggle();
    }
}

Forcing Features to be On or Off

You can force a feature to be "on" or "off" by calling the alwaysOn or alwaysOff static methods respectively. This will force all features of that class to be either "on" or "off" regardless of how their enabled methods evaluate.

class SomeFeature extends \Vehikl\Flip\Feature
{
    // include the $forcedState static variable if you want to enable forcing state
    protected static $forcedState;
    
    /**
     * Decides under which conditions this Feature is enabled
     */
    public function enabled()
    {
        return random_int(0, 1) == 1;
    }

    /**
     * Returns an array of available toggles for this feature
     */
    public function toggles()
    {
        return [
            'someToggle' => [
                'on' => 'whenOn',
                'off' => 'whenOff'
            ]
        ];
    }
    
    public function whenOn()
    {
        return "I'm on!";
    }

    public function whenOff()
    {
        return "I'm off!";
    }
}

class SomeClass
{
    use Vehikl\Flip\Featurable;
    
    protected $features = [SomeFeature::class];
    
    public function someBehaviour()
    {
        // no need for if/else blocks, just call the toggle using the
        // `flip` helper
        return $this->flip()->someToggle();
    }
}

// force the SomeFeature feature to be always on
SomeFeature::alwaysOn()

// anytime `someToggle` is called on instances of SomeClass,
// the `on` version of `someToggle` will be run 
$someObject = new SomeClass;
$someObject->someBehaviour();  // always returns "I'm on!"

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email go@vehikl.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

  • Stars: 7
  • Watchers: 28
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-06-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固