oneduo / laravel-pennant-launchdarkly
A LaunchDarkly driver for Laravel Pennant
Installs: 1 092
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 2
Forks: 1
Open Issues: 2
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-11-04 20:36:29 UTC
README
A Laravel Pennant driver for LaunchDarkly.
- Installation
- Usage
- Troubleshooting
- Testing
- Changelog
- Contributing
- Security Vulnerabilities
- Credits
- License
Installation
You can install the package via composer:
composer require oneduo/laravel-pennant-launchdarkly
Usage
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(); } }
Related documentation
- https://docs.launchdarkly.com/sdk/features/test-data-sources#php
- https://launchdarkly.github.io/php-server-sdk/
Troubleshooting
[E1] Scope must be an instance of LDUser
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.
[E2] Not implemented, Launchdarkly driver does not support this method
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.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.