digital-gravy/feature-flag
Composer 安装命令:
composer require digital-gravy/feature-flag
包简介
Feature Flag for WordPress
README 文档
README
A flexible PHP library for managing feature flags with multiple storage backends.
Installation
You can install the library via Composer:
composer require digital-gravy/feature-flag
Features
- Simple on/off feature flag management
- Multiple storage backends:
- JSON file
- PHP Constants
- Array-based storage
- Type-safe implementation
- Extensible storage interface
- Exception handling for invalid flags
Usage
Basic Usage
use DigitalGravy\FeatureFlag\FeatureFlagStore; use DigitalGravy\FeatureFlag\Storage\KeyedArray; // Create a feature flag store with array storage $flags = new KeyedArray([ 'dark_mode' => 'on', 'beta_feature' => 'off' ]); $store = new FeatureFlagStore($flags->get_flags()); // Check if a feature is enabled if ($store->is_on('dark_mode')) { // Dark mode is enabled }
JSON File Storage
use DigitalGravy\FeatureFlag\Storage\JsonFile; $flags = new JsonFile('/path/to/flags.json'); $store = new FeatureFlagStore($flags->get_flags());
Example flags.json:
{
"dark_mode": "on",
"beta_feature": "off"
}
PHP Constants Storage
use DigitalGravy\FeatureFlag\Storage\PHPConstant; define('DARK_MODE', true); define('BETA_FEATURE', 'off'); $flags = new PHPConstant(['DARK_MODE', 'BETA_FEATURE']); $store = new FeatureFlagStore($flags->get_flags());
Multiple Sources
The FeatureFlagStore constructor accepts an array of flags from different storage backends.
When multiple sources are provided, the flags are merged together, and the last source overrides the previous ones.
$store = new FeatureFlagStore( $jsonFlags->get_flags(), $constantFlags->get_flags(), $arrayFlags->get_flags() );
Flag Rules
- Flag keys must contain only alphanumeric characters, underscores, and dashes
- Flag values must be either 'on' or 'off'
- Flag keys are case-insensitive and stored in lowercase
Custom Storage Backend
You can implement your own storage backend by implementing the FlagStorageInterface:
use DigitalGravy\FeatureFlag\Storage\FlagStorageInterface; class CustomStorage implements FlagStorageInterface { public function get_flags(): array { // Return array of FeatureFlag objects } }
Error Handling
The library includes several exception types:
Invalid_Flag_Key: Thrown when a flag key contains invalid charactersInvalid_Flag_Value: Thrown when a flag value is not 'on' or 'off'Flag_Key_Not_Found: Thrown when attempting to check a non-existent flagNot_A_Flag: Thrown when invalid flag types are providedFileNotFoundException: Thrown when the JSON file does not existFileNotReadableException: Thrown when the JSON file exists but is not readable
License
GPLv3 - see LICENSE file for details
digital-gravy/feature-flag 适用场景与选型建议
digital-gravy/feature-flag 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.45k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 12 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「wordpress」 「feature-toggle」 「feature-flag」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 digital-gravy/feature-flag 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 digital-gravy/feature-flag 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 digital-gravy/feature-flag 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Pheature flags Doctrine DBAL toggle implementation library.
Feature toggling for ZF2. This module akt like an wrapper for qandidate-labs/qandidate-toggle.
Pheature flags toggle CRUD library.
Pheature flags toggle CRUD API PSR-7 implementation.
Alfabank REST API integration
Pheature flags Laminas Mezzio toggle.
统计信息
- 总下载量: 5.45k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2024-12-16