rollercoders/flagforge-php
Composer 安装命令:
composer require rollercoders/flagforge-php
包简介
PHP client for FlagForge feature flagging
README 文档
README
PHP client for FlagForge feature flags. Zero external dependencies, uses cURL.
Installation
composer require rollercoders/flagforge-php
Usage
Initialization
use FlagForge\FlagForgeClient; $client = new FlagForgeClient([ 'host' => 'https://flagforge.myapp.com', 'api_key' => 'ff_xxxx', 'timeout' => 5, // optional, default 5 seconds ]);
isEnabled
Checks whether a feature flag is enabled for a user with optional attributes. Throws FlagForgeException on error.
$enabled = $client->isEnabled('new-dashboard', [ 'userId' => 'user-123', 'attributes' => ['plan' => 'premium'], ]); if ($enabled) { // show the new dashboard }
isEnabledSafe
Like isEnabled, but returns false instead of throwing an exception on error.
$enabled = $client->isEnabledSafe('new-dashboard', ['userId' => 'user-123']); if ($enabled) { // show the new dashboard }
evaluateMany
Evaluates multiple flags at once for a user. Returns an associative array flag => bool.
$results = $client->evaluateMany(['flag-a', 'flag-b'], ['userId' => 'user-123']); // Returns: ['flag-a' => true, 'flag-b' => false] foreach ($results as $flag => $enabled) { echo "$flag: " . ($enabled ? 'ON' : 'OFF') . PHP_EOL; }
evaluateAll
Evaluates all available flags for a user. Returns an associative array flag => bool.
$results = $client->evaluateAll(['userId' => 'user-123']); foreach ($results as $flag => $enabled) { echo "$flag: " . ($enabled ? 'ON' : 'OFF') . PHP_EOL; }
Error handling
FlagForge\FlagForgeException is thrown by isEnabled and evaluateMany/evaluateAll in the following cases:
- Connection error (cURL)
- Invalid HTTP response from the server
- Malformed JSON response
Use isEnabledSafe to avoid exceptions in critical parts of your application:
use FlagForge\FlagForgeException; try { $enabled = $client->isEnabled('new-dashboard', ['userId' => 'user-123']); } catch (FlagForgeException $e) { // handle the error error_log('FlagForge error: ' . $e->getMessage()); $enabled = false; }
Requirements
- PHP 8.1+
- ext-curl
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-07-06