kameleoon/openfeature-php
Composer 安装命令:
composer require kameleoon/openfeature-php
包简介
Kameleoon OpenFeature PHP
关键字:
README 文档
README
The Kameleoon OpenFeature provider for PHP allows you to connect your OpenFeature PHP implementation to Kameleoon without installing the PHP Kameleoon SDK.
Warning
This is a beta version. Breaking changes may be introduced before general release.
Supported PHP versions
This version of the SDK is built for the following targets:
- PHP 8.0 and above.
Get started
This section explains how to install, configure, and customize the Kameleoon OpenFeature provider.
Install dependencies
First, install the required dependencies in your application.
add in composer.json
{
"require": {
"kameleoon/openfeature-php": ">=0.0.1"
}
}
composer install
Usage
The following example shows how to use the Kameleoon provider with the OpenFeature SDK.
use OpenFeature\implementation\flags\Attributes; use OpenFeature\implementation\flags\EvaluationContext; use OpenFeature\OpenFeatureAPI; use Kameleoon\KameleoonProvider; use Kameleoon\KameleoonClientConfig; $clientConfig = new KameleoonClientConfig( "clientId", "clientSecret", ); $provider = new KameleoonProvider('siteCode', $clientConfig); $api = OpenFeatureAPI::getInstance(); $api->setProvider($provider); $client = $api->getClient(); $dataDictionary = [ 'variableKey' => 'stringKey' ]; $evalContext = new EvaluationContext("visitorCode", new Attributes($dataDictionary)); $evaluationDetails = $client->getStringDetails("featureKey", 5, $evalContext); $numberOfRecommendedProducts = $evaluationDetails->getValue(); print_r("Number of recommended products: " . $numberOfRecommendedProducts);
Customize the Kameleoon provider
You can customize the Kameleoon provider by changing the KameleoonClientConfig object that you passed to the constructor above. For example:
$clientConfig = new KameleoonClientConfig( clientId: "clientId", clientSecret: "clientSecret", kameleoonWorkDir: "/tmp/kameleoon/php-client/", // kameleoonWorkDir: optional / ("/tmp/kameleoon/php-client/" by default) refreshIntervalMinute: 60, // refreshIntervalMinute: in minutes, optional (60 minutes by default) defaultTimeoutMillisecond: 10_000, // defaultTimeoutMillisecond: in milliseconds, optional (10_000 ms by default) debugMode: false, // debugMode: optional (false by default) cookieOptions: $cookieOptions, // cookieOptions: optional environment: "development" // environment: optional ("production" by default) ); $provider = new KameleoonProvider('siteCode', $clientConfig);
Note
For additional configuration options, see the Kameleoon documentation.
EvaluationContext and Kameleoon Data
Kameleoon uses the concept of associating Data to users, while the OpenFeature SDK uses the concept of an EvaluationContext, which is a dictionary of string keys and values. The Kameleoon provider maps the EvaluationContext to the Kameleoon Data.
Note
To get the evaluation for a specific visitor, set the targeting_key value for the EvaluationContext to the visitor code (user ID). If the value is not provided, then the defaultValue parameter will be returned.
$values = [ 'variableKey' => 'stringKey' ]; $evalContext = new EvaluationContext("userId", new Attributes($values));
The Kameleoon provider provides a few predefined parameters that you can use to target a visitor from a specific audience and track each conversion. These are:
| Parameter | Description |
|---|---|
DataType::CUSTOM_DATA |
The parameter is used to set CustomData for a visitor. |
DataType::CONVERSION |
The parameter is used to track a Conversion for a visitor. |
DataType::CUSTOM_DATA
Use DataType::CUSTOM_DATA to set CustomData for a visitor. The DataType::CUSTOM_DATA field has the following parameters:
| Parameter | Type | Description |
|---|---|---|
CustomDataType::INDEX |
int | Index or ID of the custom data to store. This field is mandatory. |
CustomDataType::VALUES |
string or array | Value of the custom data to store. This field is mandatory. |
Example
$customeDataDictionary = [ DataType::CUSTOM_DATA => [ CustomDataType::INDEX => 1, CustomDataType::VALUES => '10' ] ]; $evalContext = new EvaluationContext("userId", new Attributes($customeDataDictionary));
DataType::CONVERSION
Use DataType::CONVERSION to track a Conversion for a visitor. The DataType::CONVERSION field has the following parameters:
| Parameter | Type | Description |
|---|---|---|
ConversionType::GOAL_ID |
int | Identifier of the goal. This field is mandatory. |
ConversionType::REVENUE |
float | Revenue associated with the conversion. This field is optional. |
Example
$conversionDictionary = [ DataType::CONVERSION => [ ConversionType::GOAL_ID => 1, ConversionType::REVENUE => 200 ] ]; $evalContext = new EvaluationContext("userId", new Attributes($conversionDictionary));
Use multiple Kameleoon Data types
You can provide many different kinds of Kameleoon data within a single EvaluationContext instance.
For example, the following code provides one DataType::CONVERSION instance and two DataType::CUSTOM_DATA instances.
$dataDictionary = [ DataType::CONVERSION => [ ConversionType::GOAL_ID => 1, ConversionType::REVENUE => 200 ], DataType::CUSTOM_DATA => [ [ CustomDataType::INDEX => 1, CustomDataType::VALUES => ['10', '30'] ], [ CustomDataType::INDEX => 2, CustomDataType::VALUES => '20' ] ] ]; $evalContext = new EvaluationContext("userId", $dataDictionary);
kameleoon/openfeature-php 适用场景与选型建议
kameleoon/openfeature-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 10 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sdk」 「kameleoon」 「openfeeature」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kameleoon/openfeature-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kameleoon/openfeature-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kameleoon/openfeature-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kameleoon SDK PHP
PHP SDK for the Enconvert file conversion API
支付宝开放平台v3协议文档,支持最新版PHP8+
Merchant-side PHP SDK for YoPay Pay Open API.
SDK oficial da API AurePay para PHP (tipado via OpenAPI)
SDK oficial da API AureEX para PHP (tipado via OpenAPI)
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: AGPL-3.0-or-later
- 更新时间: 2024-10-14