A Laravel Pennant driver for LaunchDarkly.
- Installation
- Usage
- Troubleshooting
- Testing
- Changelog
- Contributing
- Security Vulnerabilities
- Credits
- License
You can install the package via composer:
composer require oneduo/laravel-pennant-launchdarkly
You may use the driver in your existing Laravel Pennant configuration file, by setting your store's driver
to LaunchDarklyDriver::class
.
You should provide your SDK key in your store's configuration.
You may add any LaucnhDarkly cleint specific configuration options to the store's configuration.
A typical configuration might look like this:
// 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' => [],
],
],
];
Then, in your scopeable Model, for instance your User model, you should implement the FeatureScopeable
interface, and provide a toFeatureIdentifier
method.
<?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/
This is most likely due to either the scope you are using, or the fact that your currently authenticated user not having
implemented FeatureScopeable
correctly.
Please check the usage instructions.
The LaunchDarkly driver for Laravel Pennant only supports read operations, and does not support write operations. If you need to write to LaunchDarkly, you should use the LaunchDarkly platform or the REST API.
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.