oneduo / laravel-pennant-launchdarkly
为 Laravel Pennant 提供的 LaunchDarkly 驱动程序
v0.1.0
2023-03-03 19:56 UTC
Requires
- php: ^8.1
- illuminate/contracts: ^10.0
- kevinrob/guzzle-cache-middleware: ^4.0
- laravel/pennant: ^1.2
- launchdarkly/server-sdk: ^5.1
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.9
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2024-09-09 22:21:08 UTC
README
这是一个为 LaunchDarkly 提供的 Laravel Pennant 驱动程序。
安装
您可以通过 composer 安装此软件包
composer require oneduo/laravel-pennant-launchdarkly
使用
您可以在现有的 Laravel Pennant 配置文件中使用驱动程序,通过设置您的存储驱动程序为 LaunchDarklyDriver::class
。
您应该在存储配置中提供您的 SDK 密钥。
您可以将任何 LaunchDarkly 客户端特定的配置选项添加到存储配置中。
一个典型的配置可能如下所示
// config/pennant.php <?php use Oneduo\LaravelPennantLaunchdarkly\LaunchDarklyDriver; return [ /* |-------------------------------------------------------------------------- | Default Pennant Store |-------------------------------------------------------------------------- | | Here you will specify the default store that Pennant should use when | storing and resolving feature flag values. Pennant ships with the | ability to store flag values in an in-memory array or database. | | Supported: "array", "database" | */ 'default' => env('PENNANT_STORE', 'laucnhdarkly'), /* |-------------------------------------------------------------------------- | Pennant Stores |-------------------------------------------------------------------------- | | Here you may configure each of the stores that should be available to | Pennant. These stores shall be used to store resolved feature flag | values - you may configure as many as your application requires. | */ 'stores' => [ // ... 'laucnhdarkly' => [ 'driver' => LaunchDarklyDriver::class, 'sdk_key' => env('LAUNCHDARKLY_SDK_KEY'), 'options' => [], ], ], ];
然后,在您的可作用域模型中,例如您的用户模型,您应该实现 FeatureScopeable
接口,并提供一个 toFeatureIdentifier
方法。
<?php namespace App\Models; use Illuminate\Foundation\Auth\User as Authenticable; use Laravel\Pennant\Contracts\FeatureScopeable; use LaunchDarkly\LDUser; use LaunchDarkly\LDUserBuilder; class User extends Authenticable implements FeatureScopeable { // ... public function toFeatureIdentifier(string $driver): LDUser { return (new LDUserBuilder($this->getKey())) // you may add more attributes to your LDUser // ->email($this->email) // ->firstName($this->firstname) // ->lastName($this->lastname) //->custom([...]) ->build(); } }
相关文档
- https://docs.launchdarkly.com/sdk/features/test-data-sources#php
- https://launchdarkly.github.io/php-server-sdk/
故障排除
[E1] 范围必须是 LDUser 的实例
这很可能是由于您正在使用的范围,或者是因为您当前认证的用户没有正确实现 FeatureScopeable
。
请检查使用说明。
[E2] 未实现,Launchdarkly 驱动程序不支持此方法
LaunchDarkly 驱动程序仅支持读取操作,不支持写入操作。如果您需要向 LaunchDarkly 写入,请使用 LaunchDarkly 平台或 REST API。
测试
composer test
变更日志
请参阅 CHANGELOG 了解最近有哪些更改。
贡献
请参阅 CONTRIBUTING 了解详细信息。
安全漏洞
请参阅 我们的安全策略 了解如何报告安全漏洞。
致谢
许可
MIT 许可证 (MIT)。请参阅 许可文件 了解更多信息。