launchdarkly/openfeature-server

OpenFeature 提供商,用于 LaunchDarkly PHP 服务器 SDK

1.0.0 2024-06-13 16:37 UTC

This package is auto-updated.

Last update: 2024-09-13 21:02:29 UTC


README

Run CI Packagist Documentation

此提供商允许使用 OpenFeature SDK 在 PHP 中使用 LaunchDarkly。

此提供商主要用于在多用户系统中使用,例如 Web 服务器和应用程序。它遵循多用户环境中的服务器端 LaunchDarkly 模型。它不适用于桌面和嵌入式系统应用程序。

LaunchDarkly 概览

LaunchDarkly 是一个功能管理平台,每天为超过 1000 亿次功能标志提供服务,帮助团队更快地构建更好的软件。今天就开始使用 LaunchDarkly 吧!开始使用

Twitter Follow

支持的 PHP 版本

此版本的 LaunchDarkly 提供商与 PHP 8.1 及以上版本兼容。

入门

必备条件

示例 composer 依赖关系

{
    "require": {
        "php": ">=8.1",
        "launchdarkly/openfeature-server": "^1.0"
    }
}

用法

use OpenFeature\OpenFeatureAPI;
use OpenFeature\implementation\flags\Attributes;
use OpenFeature\implementation\flags\EvaluationContext;

$provider = new LaunchDarkly\OpenFeature\Provider("my-sdk-key");

$api = OpenFeatureAPI::getInstance();
$api->setProvider($provider);

// Refer to OpenFeature documentation for getting a client and performing evaluations.

有关开始使用 SDK 的说明,请参阅SDK 参考指南

有关使用 OpenFeature 客户端的说明,请参阅OpenFeature 文档

OpenFeature 特殊考虑事项

LaunchDarkly 评估上下文,可以评估单个上下文或多个上下文。当使用 OpenFeature 时,单个和多个上下文都必须编码到单个 EvaluationContext 中。这是通过在 EvaluationContext 中查找名为 kind 的属性来完成的。

kind 相关的 4 种不同场景

  1. 没有 kind 属性。在这种情况下,提供程序将上下文视为包含“用户”类型的单个上下文。
  2. 有一个 kind 属性,并且该属性的值是“multi”。这将指示提供程序上下文是一个多上下文。
  3. 有一个 kind 属性,并且该属性的值是一个除“multi”以外的字符串。这将指示提供程序一个指定类型的单个上下文。
  4. 有一个 kind 属性,并且属性不是字符串。在这种情况下,将丢弃属性的值,上下文将被视为“用户”。将记录错误消息。

kind 属性应仅包含 ASCII 字母、数字、._- 的字符串。

OpenFeature 规范允许有可选的定位键,但 LaunchDarkly 要求对评估指定一个键。必须为每个要评估的上下文指定一个定位键。可以使用 targetingKey 指定,如 OpenFeature 规范中所做的那样,或者使用 key,这是 LaunchDarkly 对定位键的典型标识符。如果指定了 targetingKeykey,则 targetingKey 将具有优先级。

还有其他一些属性在单个或多个上下文中具有特殊功能。

示例

单个用户上下文

$context = new EvaluationContext("the-key");

单个类型为 "organization" 的上下文

$attributes = new Attributes(["kind" => "organization"]);
$context = new EvaluationContext("org-key", $attributes);

包含 "user" 和 "organization" 的多上下文

$attributes = [
    "kind" => "multi",
    "organization" => [
        "name" => "the-org-name",
        "targetingKey", "my-org-key",
        "myCustomAttribute", "myAttributeValue"
    ],
    "user" => [
        "key" => "my-user-key",
        "anonymous", true
    ]
];
$context = new EvaluationContext(null, new Attributes($attributes));

在单个上下文中设置私有属性

$attributes = [
    "kind" => "organization",
    "myCustomAttribute" => "myAttributeValue",
    "privateAttributes" => ["myCustomAttribute"]
];

$context = new EvaluationContext("org-key", new Attributes($attributes));

在多上下文中设置私有属性

$attributes = [
    "kind" => "organization",
    "organization" => [
        "name" => "the-org-name",
        "targetingKey" => "my-org-key",
        // This will ONLY apply to the "organization" attributes.
        "privateAttributes" => ["myCustomAttribute"],
        // This attribute will be private.
        "myCustomAttribute" => "myAttributeValue",
    ],
    "user" => [
        "key" => "my-user-key",
        "anonymous" = > true,
        // This attribute will not be private.
        "myCustomAttribute" => "myAttributeValue",
    ]
];

$context = new EvaluationContext(null, new Attributes($attributes));

了解更多

查看我们的文档,以获取有关配置和使用 LaunchDarkly 的详细说明。您也可以直接访问此 SDK 的完整参考指南

所有属性和方法的权威描述在php 文档中。

贡献

我们鼓励社区成员提交 pull request 和其他贡献。查看我们的贡献指南,了解如何为此 SDK 贡献。

关于 LaunchDarkly

  • LaunchDarkly 是一个持续交付平台,提供功能标志作为服务,允许开发者快速、安全地迭代。我们允许您轻松标记您的功能,并通过 LaunchDarkly 控制台进行管理。使用 LaunchDarkly,您可以
    • 将新功能推出给用户子集(例如选择加入测试者组的用户组),从真实世界的用例中收集反馈和错误报告。
    • 逐步将功能推出给越来越多的用户,并跟踪功能对关键指标的影响(例如,拥有功能 A 与功能 B 的用户完成购买的可能性如何?)。
    • 关闭在生产中导致性能问题的功能,而无需重新部署,甚至无需重启应用程序更改配置文件。
    • 基于用户属性授予某些功能的访问权限,例如付款计划(例如,'gold' 计划的用户比 'silver' 计划的用户获得更多功能)。在不关闭所有内容的情况下,关闭应用程序的部分以方便维护。
  • LaunchDarkly 为各种语言和技术提供功能标志 SDK。查看我们的文档以获取完整列表。
  • 探索 LaunchDarkly