partechgss/laravel-feature-toggle
Composer 安装命令:
composer require partechgss/laravel-feature-toggle
包简介
Laravel Wrapper for feature toggles.
README 文档
README
This package allows you to implement feature flags in Laravel. Right now the only supported implementation is split.io.
Basic Usage
Change Behavior Based on a Flag
use PartechGSS\Laravel\FeatureToggle\Contracts\FeatureToggleClient;
$client = resolve(FeatureToggleClient::class);
switch ($client->getTreatment('my_flag')) {
case "on":
do_a_thing();
break;
default:
do_another_thing();
break;
}
Retrieve Configuration Attached to a Treatment
$treatmentWithConfig = $client->getTreatmentWithConfig('my_flag');
$treatment = $treatmentWithConfig['treatment'];
$config = $treatmentWithConfig['config'];
set_some_css_options($config);
Retrieve Multiple Flags in a Batch
$treatments = $client->getTreatments(['my_flag', 'another_flag']);
switch($treatments['my_flag']) {
...
}
Retrieve Configurations in a Batch
$treatmentsWithConfig = $client->getTreatmentsWithConfig('my_flag');
$treatment = $treatmentsWithConfig['my_flag']['treatment'];
$config = $treatmentsWithConfig['my_flgag']['config'];
set_some_css_options($config);
Installation
You can install the package via Composer:
composer require partechgss/laravel-feature-toggles
Configuration
Config File
Looks for config/feature-toggle.php. To install the default one:
php artisan vendor:publish
Middleware
You need to set the toggle "key" somewhere. This is usually something like a user's email address, used to decide which treatment the user gets for a particular flag. This package provides middleware that automatically sets the key based on the user's email addesss. This must be run after your authentication middleware, so, first make it available as route middleware and set the priority in your app/Http/Kernel.php.
use PartechGSS\Laravel\FeatureToggle\Middleware\SetFeatureToggleKeyFromUserEmail;
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'feature-toggle' => SetFeatureToggleKeyFromUserEmail::class,
];
protected $middlewarePriority = [
\App\Http\Middleware\Authenticate::class,
SetFeatureToggleKeyFromUserEmail::class,
];
Execute as Route Middleware
# routes/api.php
Route::middleware(['auth:api', 'feature-toggle'])->group(function() {
...,
});
Execute via Route Middleware Groups
# app/Http/Kernel.php
protected $middlewareGroups = [
'web' => [
...,
'feature-toggle',
],
'api' => [
\Barryvdh\Cors\HandleCors::class,
'throttle:60,1',
'bindings',
'feature-toggle',
],
];
Testing
This Project
composer test
Your Project
The SplitIO SDK throws errors when it can't find a configuration file in localhost mode. To work around that, create a dummy local split.yaml file and ask the factory to load it. For example, you can set SPLITIO_SPLIT_FILE in your testing environment to point to your file:
# .env.testing
SPLITIO_SPLIT_FILE=tests/__data__/split.yaml
This assumes a file like this one at tests/__data__/split.yaml:
- hello_world:
treatment: off
- hello_world:
treatment: on
keys: "user@example.org"
partechgss/laravel-feature-toggle 适用场景与选型建议
partechgss/laravel-feature-toggle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.15k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 07 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 partechgss/laravel-feature-toggle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 partechgss/laravel-feature-toggle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 6.15k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause-Clear
- 更新时间: 2020-07-20