Git Product home page Git Product logo

featureflag's Introduction

Feature flag

Library for easy work with feature flags in PHP.

The library allows to add multiple data sources (in case you want to have config with default values and another configs with overridden values).

Data sources

Just for example I've some sources:

  • SimpleArray
  • SimpleArrayWritable - an example for writable data sources
  • SimpleObject
  • RemoteJsonCurl

To add another data source you need to create a new class and implement \FeatureFlag\Contracts\DataSourceInterface with 3 methods:

  • exists - to know that selected flag exists
  • get - to get flag value
  • all - to return available flags from data source

In case you need to add/update/delete flags values you can implement \FeatureFlag\Contracts\WritableSourceInterface with 3 methods:

  • add
  • update
  • delete

Examples

Single source

// init array of flags with values
$config = ['first_flag' => true, 'second_flag' => false];
// init data source
$ds = new \FeatureFlag\DataSources\SimpleArray($config);
// create instance of service and add data source
$service = new \FeatureFlag\FeatureFlag();
$service->addSource($ds);
// single condition check
if($service->enabled('first_flag')) {
    // do something
}
// multiple flags check
if($service->enabledWithDependencies('first_flag', ['second_flag' => false])) {
    // do something
}

Multiple sources

// init first data source
$firstDsConfig = ['first_flag' => true, 'second_flag' => false];
$firstDs = new \FeatureFlag\DataSources\SimpleArray($firstDsConfig);
// init second data source
$secondDsConfig = new \stdClass;
$secondDsConfig->first_flag = false;
$secondDs = new \FeatureFlag\DataSources\SimpleObject($secondDsConfig);
// init service
$service = new \FeatureFlag\FeatureFlag([$firstDs, $secondDs]);
//
$service->enabled('second_flag'); // false
$service->enabled('first_flag'); // false

Installation

composer require antonkuku/featureflag

featureflag's People

Contributors

antonkuku avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.