rollercoders / flagforge-php
PHP client for FlagForge feature flagging
Requires
- php: >=8.1
- ext-curl: *
Requires (Dev)
- phpunit/phpunit: ^11
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-06 16:44:31 UTC
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