togul/php-sdk
最新稳定版本:2.4.0
Composer 安装命令:
composer require togul/php-sdk
包简介
PHP SDK for Togul Feature Flag Service
README 文档
README
PHP client for evaluating Togul feature flags with local TTL caching and fallback behavior.
Install
composer require togul/php-sdk
Usage
Boolean flag (on/off)
<?php use Togul\Config; use Togul\FallbackMode; use Togul\TogulClient; $client = new TogulClient(new Config( environment: 'production', apiKey: 'your-environment-api-key', timeout: 5.0, cacheTtl: 30, fallbackMode: FallbackMode::FailClosed, retryCount: 2, )); $enabled = $client->isEnabled('new-dashboard', [ 'user_id' => 'user-123', 'country' => 'TR', ]);
Multi-variant flags
Use typed convenience methods to read flag values beyond boolean:
// String variant $theme = $client->evaluateString('ui-theme', ['user_id' => 'user-123'], fallback: 'default'); // Number variant $limit = $client->evaluateNumber('rate-limit', ['plan' => 'pro'], fallback: 100.0); // Boolean variant $flag = $client->evaluateBool('beta-feature', ['user_id' => 'user-123'], fallback: false); // JSON variant (returns decoded value) $config = $client->evaluateJson('feature-config', ['user_id' => 'user-123'], fallback: null);
Full evaluation result
evaluateResult() returns an EvaluateResult object with all flag metadata and typed accessors:
$result = $client->evaluateResult('checkout-flow', ['user_id' => 'user-123']); $result->enabled; // bool $result->flagKey; // string $result->valueType; // 'boolean' | 'string' | 'number' | 'json' $result->reason; // string $result->boolValue(false); // bool $result->stringValue(''); // string $result->numberValue(0.0); // float $result->jsonValue(null); // mixed
Notes
apiKeymust be an environment API key, not a user JWT.- Requests are sent to
POST /api/v1/evaluatewith theX-API-Keyheader. - The cache key includes the full evaluation context.
- The client retries
429and5xx, but stops immediately on401/403/404. - Typed accessors (
boolValue,stringValue, etc.) return the fallback if the flag is disabled or the value type does not match.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-14