gramzivi/flag-it-bundle
最新稳定版本:v1.0.0-beta
Composer 安装命令:
composer require gramzivi/flag-it-bundle
包简介
Lightweight and extensible feature flags bundle for Symfony
README 文档
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:
- From the
FLAGIT_CURRENT_CLIENTenvironment variable - From the
flagit.current_clientSymfony parameter - 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
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-09