getsidekicker / flagr-feature-laravel
Makes working with Flagr in Laravel a snap
Installs: 11 760
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 1
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-04-14 00:17:52 UTC
README
Prerequisites
To use this package, you will need to have Flagr installed and accessible
Installation
Publish config
php artisan vendor:publish --tag=flagr-feature-laravel-config
Usage
Block execution
//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 );
Conditional
//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 }
Context
By default, context is sent to Flagr as part of the evaluation call. This can be used to add constraints against segments.
{ "env": "<Laravel Environment>", "user": ["<Array representation of currently authed user>"], "host": "<Host as derived from request or APP_URL env>" }
Additionally, context can be set. Note that any context will be merged over the default context
feature_add_context([]); app('feature')->addContext([]);
To ensure that consistent feature treatment is applied across requests, you can supply an optional id
feature_set_id('user_123'); app('feature')->setId('user_123'); // evaluation calls
Creating new feature flag
Flags can be created in the format php artisan feature:create-flag {--name} {--description} [{--tags=*}]
. This will use the simple boolean flag type within Flagr
e.g.
php artisan feature:create-flag --name="temp-flag" --description="Create temp flag for feature"