rollercoders/flagforge-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-07-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固