Package Data | |
---|---|
Maintainer Username: | exolnet |
Maintainer Contact: | adeschambeault@exolnet.com (Alexandre D'Eschambeault) |
Package Create Date: | 2017-07-26 |
Package Last Update: | 2024-03-28 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-23 03:06:09 |
Package Statistics | |
---|---|
Total Downloads: | 9,315 |
Monthly Downloads: | 596 |
Daily Downloads: | 24 |
Total Stars: | 7 |
Total Watchers: | 6 |
Total Forks: | 1 |
Total Open Issues: | 0 |
Bento helps you organize feature launches by custom user segments. Create and organize rules to make features available to certain users.
Define your features, define your segmentation strategies and let Bento launch each feature to the right people. Bento can also help you run A/B testing on your applications.
The core concepts of this library are inspired by Airbnb's Trebuchet project for Ruby.
Require this package with composer:
composer require eXolnet/laravel-bento
If you don't use package auto-discovery, add the service provider to the providers
array in config/app.php
:
Exolnet\Bento\BentoServiceProvider::class
And the facade to the facades
array in config/app.php
:
'Bento' => Exolnet\Bento\BentoFacade::class
Define features and their launch segmentation strategies. You can define one strategy with the aim
method:
Bento::aim('feature', 'visitor-percent', 10);
Or you can combine multiple strategies:
Bento::feature('feature')->aim('visitor-percent', 10)->aim('hostname', 'example.com');
Then, you can check if a feature is launched for a visitor with the launch
method:
if (Bento::launch('feature')) {
//
}
Or use the handy macro in your Blade templates:
@launch('feature')
Feature is launched!
@else
Coming soon!
@endlaunch
The following segmentation strategies are available to help quickly target your users:
Additional logic segmentation strategies are available to help target your users with more complex rules.
Bento::aim('feature', 'logic-not', 'everybody');
Bento::aim('feature', 'logic-and', function($feature) {
$feature
->aim('environment', 'production')
->aim('visitor-percent', 20);
});
Bento::aim('feature', 'logic-or', function($feature) {
$feature
->aim('environment', 'staging')
->aim('user', [1, 2]);
});
You can create your own custom strategies.
You can also inject dependencies the same way Laravel Controllers' method injection works. A common use-case for method injection is injecting the Illuminate\Contracts\Auth\Guard
instance into your strategy to target users by property:
use Illuminate\Contracts\Auth\Guard;
Bento::defineStrategy('role', function(Guard $guard, $role) {
return $guard->user() && $guard->user()->role === $role;
});
Then, you can use your custom strategy like the default one:
Bento::feature('feature')->aim('role', 'admin');
To run the phpUnit tests, please use:
$ composer test
Please see CONTRIBUTING and CODE OF CONDUCT for details.
If you discover any security related issues, please email security@exolnet.com instead of using the issue tracker.
This code is licensed under the MIT license. Please see the license file for more information.