open-feature/flagd-provider

open-feature 的 Flagd 提供器包


README

a Latest Stable Version Total Downloads PHP 8.0+ License

概览

Flagd 是一个简单的命令行工具,用于检索和展示功能标志给服务。它旨在符合 OpenFeature 标志定义的方案。这个仓库和包提供了与 OpenFeature PHP SDK 交互的客户端代码。

此包还基于各种 PSR(PHP 标准建议)如日志接口(PSR-3)和基本及扩展编码标准(PSR-1 和 PSR-12)。

安装

composer require open-feature/flagd-provider

使用方法

FlagdProvider 客户端构造函数接受一个单选参数,包含 3 个字段,它们的默认值对应于 flagd 服务器提供的默认参数

/** @var \Psr\Http\Client\ClientInterface $client */
$client;

/** @var Psr\Http\Message\RequestFactoryInterface $requestFactory */
$requestFactory;

/** @var Psr\Http\Message\StreamFactoryInterface $streamFactory */
$streamFactory;

OpenFeatureAPI::setProvider(new FlagdProvider([
    'protocol' => 'http',
    'host' => 'localhost',
    'port' => 8013,
    'secure' => true,
    'http' => [
      'client' => $client,
      'requestFactory' => $requestFactory,
      'streamFactory' => $streamFactory,
    ],
]));
  • 协议: "http" (默认为 http)
  • 主机: 字符串 (默认为 "localhost")
  • 端口: 数字 (默认为 8013)
  • 安全: true | false (默认为 false)
  • http: 数组或 HttpConfig 对象,提供 PSR 接口的实现
    • 客户端: ClientInterface 的实现
    • requestFactory: RequestFactoryInterface 的实现
    • streamFactory: StreamFactoryInterface 的实现

gRPC 与 HTTP

Flagd 服务器使用 gRPC,但提供了可通过 HTTP 访问的 gRPC Web 端点。后者被当前 Flagd 提供器的实现所使用,未来计划实现 gRPC 原生提供器选项。PHP 在 HTTP 方面具有某些灵活性,而 gRPC 是一种有意见的代码生成策略,但它们都有用,且 gRPC 原生可能在某些同步/异步场景中提供更好的性能。另一个目标将是为各种场景提供 Flagd 提供器的协议基准测试,以便更容易地由提供器的消费者做出此决定。

开发

PHP 版本

此库针对 PHP 版本和更高版本。只要你的系统上有任何兼容的 PHP 版本,你应该能够使用 OpenFeature SDK。

此包还有一个 .tool-versions 文件,用于与 asdf 等PHP版本管理器一起使用。

安装和依赖

使用 composer install 安装依赖项。 composer install 将使用最新兼容版本更新 composer.lock

我们重视尽可能少运行时依赖项。添加任何依赖项都需要仔细考虑和审查。

测试

使用 composer run test 运行测试。