Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Database Activator Laravel Package

flagception/database-activator

Doctrine DBAL-backed activator for Flagception feature flags. Stores flag state in a SQL database (MySQL/Postgres/SQLite), auto-creates the table, and supports connection arrays, DSNs, or an existing DBAL instance, with customizable table/column names.

View on GitHub
Deep Wiki
Context7

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('pdo-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('pdo-mysql://user:secret@localhost/mydb');
        
        // ...
    }
}
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('pdo-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
        }
    }
}
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
codifyo/ts-generator-bundle
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor