2017 © Pedro Peláez
 

library flip

A Feature Toggle implementation

image

vehikl/flip

A Feature Toggle implementation

  • Friday, July 13, 2018
  • by bbrothers
  • Repository
  • 11 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Flip

Latest Version on Packagist ![Software License][ico-license] Build Status ![Coverage Status][ico-scrutinizer] Quality Score ![Total Downloads][ico-downloads], (*1)

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., (*2)

Install

Via Composer, (*3)

``` bash $ composer require vehikl/flip, (*4)


## 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". ``` php 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., (*5)

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., (*6)

Testing

bash $ composer test, (*7)

Contributing

Please see CONTRIBUTING for details., (*8)

Security

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

Credits

License

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

The Versions

13/07 2018

dev-always-on

dev-always-on https://github.com/vehikl/flip

A Feature Toggle implementation

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

feature feature toggle vehikl

23/06 2018

dev-master

9999999-dev https://github.com/vehikl/flip

A Feature Toggle implementation

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

feature feature toggle vehikl

23/06 2018

dev-fix-stickler

dev-fix-stickler https://github.com/vehikl/flip

A Feature Toggle implementation

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

feature feature toggle vehikl

22/06 2018

v0.1.2

0.1.2.0 https://github.com/vehikl/flip

A Feature Toggle implementation

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

feature feature toggle vehikl

22/06 2018

dev-container-for-all

dev-container-for-all https://github.com/vehikl/flip

A Feature Toggle implementation

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

feature feature toggle vehikl

17/06 2018

v0.1.1

0.1.1.0 https://github.com/vehikl/flip

A Feature Toggle implementation

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

feature feature toggle vehikl

16/06 2018

v0.1

0.1.0.0 https://github.com/vehikl/flip

A Feature Toggle implementation

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

feature feature toggle vehikl