getsidekicker / flagr-feature-laravel
让在 Laravel 中使用 Flagr 变得轻而易举
0.1.0
2023-01-29 23:48 UTC
Requires
- php: ^8.0
- getsidekicker/flagr-client: 1.1.14
- guzzlehttp/psr7: ^1.7 || ^2.0
- spatie/laravel-package-tools: ^1.12|^1.13|^1.14
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- orchestra/testbench: ^6.0|^7.0|^8.0
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.6
This package is auto-updated.
Last update: 2024-09-14 01:11:58 UTC
README
先决条件
要使用此包,您需要安装并可以访问 Flagr
安装
发布配置
php artisan vendor:publish --tag=flagr-feature-laravel-config
用法
阻止执行
//function feature_eval('flag', on: fn(object $attachment) => // do stuff when feature is on, otherwise: fn(object $attachment) => // do stuff when any other variant isn't matched ) //alias app('feature')->eval('flag', on: fn(object $attachment) => // do stuff when feature is on, otherwise: fn(object $attachment) => // do stuff when any other variant isn't matched );
条件
//function if (feature_match('flag')) { // do feature when feature variant is 'on' } else { // do otherwise } //alias //function if (app('feature')->match('flag')) { // do feature when feature variant is 'on' } else { // do otherwise }
上下文
默认情况下,上下文作为评估调用的一部分发送给 Flagr。这可以用来对片段添加约束。
{ "env": "<Laravel Environment>", "user": ["<Array representation of currently authed user>"], "host": "<Host as derived from request or APP_URL env>" }
此外,可以设置上下文。请注意,任何上下文都将覆盖默认上下文。
feature_add_context([]); app('feature')->addContext([]);
为确保在请求间应用一致的特征处理,您可以提供一个可选的 id
feature_set_id('user_123'); app('feature')->setId('user_123'); // evaluation calls
创建新的功能标志
标志可以以以下格式创建:php artisan feature:create-flag {--name} {--description} [{--tags=*}]
。这将在 Flagr 中使用简单的布尔标志类型。
例如:
php artisan feature:create-flag --name="temp-flag" --description="Create temp flag for feature"