Coder Social home page Coder Social logo

flagception-database-activator's Introduction

Database activator for flagception

Manage feature flags for Flagception with a sql database (mysql, postgres, sqlite, ...)!

Download the library

Open a command console, enter your project directory and execute the following command to download the latest stable version of this library:

$ composer require flagception/database-activator

Usage

Just create a new DatabaseActivator instance and commit it to your feature manager:

// YourClass.php

class YourClass
{
    public function run()
    {
        $activator = new DatabaseActivator(['url' => 'mysql://user:secret@localhost/mydb']);
        
        $manager = new FeatureManager($activator);
        if ($manager->isActive('your_feature_name')) {
            // do something
        }
    }
}

Connection

This activator use dbal under the hood. We redirect the first argument directly to dbal - so you can use all known connection options (see documentation):

User and password
// YourClass.php

class YourClass
{
    public function run()
    {
        $activator = new DatabaseActivator([
            'dbname' => 'mydb',
            'user' => 'user',
            'password' => 'secret',
            'host' => 'localhost',
            'driver' => 'pdo_mysql'
        ]);
        
        // ...
    }
}
Connection string
// YourClass.php

class YourClass
{
    public function run()
    {
        $activator = new DatabaseActivator([
            'url' => 'mysql://user:secret@localhost/mydb'
        ]);
        
        // ...
    }
}
PDO instance
// YourClass.php

class YourClass
{
    public function run()
    {
        $activator = new DatabaseActivator([
            'pdo' => $this->myPdoInstance
        ]);
        
        // ...
    }
}
DBAL instance
// YourClass.php

class YourClass
{
    public function run()
    {
        $activator = new DatabaseActivator($this->myDbalInstance);
        
        // ...
    }
}

Table

The activator will create the sql table if it does not already exist. The default table name is flagception_features which contains a feature and a state column. You can change the table and columns names by the second argument. It expects an array with values for db_table, db_column_feature and db_column_state. Setting one of the fields in optional.

Example:

// YourClass.php

class YourClass
{
    public function run()
    {
        $activator = new DatabaseActivator(['url' => 'mysql://user:secret@localhost/mydb'], [
            'db_table' => 'my_feature_table',
            'db_column_feature' => 'foo_feature_name',
            'db_column_state' => 'foo_is_active'
        ]);
        
        // The activator create a table 'my_feature_table' with the column 'foo_feature_name' and 'foo_is_active'.
        
        $manager = new FeatureManager($activator);
        if ($manager->isActive('your_feature_name')) {
            // do something
        }
    }
}

flagception-database-activator's People

Contributors

migo315 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.