Search by

rollercoders / flagforge-php

TheFe91

PHP client for FlagForge feature flagging

Package info

github.com/Rollercoders/flagforge-php

pkg:composer/rollercoders/flagforge-php

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.0 2026-07-06 15:59 UTC

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