承接 togul/php-sdk 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

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

  • apiKey must be an environment API key, not a user JWT.
  • Requests are sent to POST /api/v1/evaluate with the X-API-Key header.
  • The cache key includes the full evaluation context.
  • The client retries 429 and 5xx, but stops immediately on 401/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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固