gramzivi/flag-it-bundle

Lightweight and extensible feature flags bundle for Symfony

Maintainers

Package info

github.com/Gramzivi/flag-it-bundle

Type:symfony-bundle

pkg:composer/gramzivi/flag-it-bundle

Statistics

Installs: 8

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

v1.0.0-beta 2025-07-09 20:28 UTC

This package is auto-updated.

Last update: 2026-04-10 20:22:48 UTC


README

FlagItBundle is a lightweight and extensible feature flags bundle for Symfony.
It supports both simple (single-client) and advanced (multi-client) feature flag configuration. The bundle is designed to be unobtrusive and integrates cleanly with the Symfony service container.

Installation

composer require gramzivi/flag-it-bundle

Configuration

Create a configuration file at config/packages/flagit.yaml.

Simple configuration (single client)

flagit:
    flags:
        enable_chat: true
        new_dashboard: false

Advanced configuration (multiple clients)

flagit:
    current_client: '%env(default:client_a:FLAGIT_CURRENT_CLIENT)%'

    clients:
        client_a:
            enable_chat: true
            new_dashboard: false

        client_b:
            enable_chat: false
            new_dashboard: true

    defaults:
        enable_chat: false
        new_dashboard: false

The current_client can be defined via .env, or as a parameter in your configuration. If neither is defined, 'default' will be used.

Service Usage

Inject FeatureFlagManager into any service or controller:

use FlagIt\Service\FeatureFlagManager;

class SomeService
{
    public function __construct(private FeatureFlagManager $flags) {}

    public function run(): void
    {
        if ($this->flags->isEnabled('enable_chat')) {
            // Chat logic here
        }
    }
}

Twig Integration

If Twig is installed, the feature_flag() function will be available automatically.

{% if feature_flag('enable_chat') %}
    <div>Chat is enabled</div>
{% endif %}

There is no need for manual registration. The bundle checks if Twig is available and registers the extension automatically.

Console Usage

Use the console to inspect current flag states:

bin/console flagit:list

To list flags for a specific client:

bin/console flagit:list --client=client_b

Client Resolution Order

The bundle resolves the active client in the following order:

  1. From the FLAGIT_CURRENT_CLIENT environment variable
  2. From the flagit.current_client Symfony parameter
  3. Fallback to 'default'

Optional Service Configuration

If you want to explicitly wire the client context service, you can add the following to your services.yaml:

services:
    _defaults:
        autowire: true
        autoconfigure: true

    FlagIt\:
        resource: '../src/*'
        exclude: '../src/{DependencyInjection,Entity,Tests}'

    FlagIt\Context\DefaultClientContext:
        arguments:
            $configuredClient: '%flagit.current_client%'

Requirements

  • PHP >= 8.1
  • Symfony 6.4 or 7.x

License

MIT License