You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 23, 2025. It is now read-only.
Add variant and mocking support. Refactor to use value objects.
[NEW] Mocking can now be achieved easily using `Unleash::fake()` similar to Laravel's `Event::fake()` or `Bus::fake()`. This is achieved using `UnleashFake`.
[NEW] Variant support. Get the correct variant based on the flag configuration using `Unleash::variant('flag-name', 'default-value');`
[CHANGE] To better support mocking and variants, the package has been updated to use value objects. This should be backwards compatible for the most part, with the implementation fo `ArrayAccess`, except for checks using `is_array()`.
[CHANGE] The Laravel-like `enabled()`, `disabled()`, `get()` and `all()` methods are now the primary, with the standard Unleash methods as aliases
[CHANGE] Tests have been updated to better handle Config mocking, simplifying some of them dramatically.
To enable or disable strategies, add or remove from `unleash.strategies` config in your `unleash.php` config file.
68
63
69
-
if (Feature::enabled('myAwesomeFeature')) {
70
-
// Congratulations, you can see this awesome feature!
71
-
}
64
+
### Custom Strategies
72
65
73
-
if (Feature::disabled('myAwesomeFeature')) {
74
-
// Check back later for more features!
75
-
}
66
+
Custom strategies must implement `\MikeFrancis\LaravelUnleash\Strategies\Contracts\Strategy` or if your strategy relies on dynamic data at runtime it should implement `\MikeFrancis\LaravelUnleash\Strategies\Contracts\DynamicStrategy`.
76
67
77
-
$feature = Feature::get('myAwesomeFeature');
68
+
```php
69
+
use \MikeFrancis\LaravelUnleash\Strategies\Contracts\Strategy;
70
+
use \Illuminate\Http\Request;
78
71
79
-
$allFeatures = Feature::all();
72
+
class CustomStrategy implements Strategy {
73
+
public function isEnabled(array $params, Request $request) : bool {
74
+
// logic here
75
+
return true || false;
76
+
}
77
+
}
80
78
```
81
79
82
-
### Dynamic Arguments
80
+
### Dynamic Strategies
83
81
84
-
If your strategy relies on dynamic data at runtime, you can pass additional arguments to the feature check functions:
82
+
When implementing `DynamicStrategy`you can pass additional arguments to the feature check functions which will be passed as extra arguments to the `isEnabled()` method:
85
83
86
84
```php
87
-
use \MikeFrancis\LaravelUnleash\Unleash;
88
-
use Config;
89
-
90
-
$unleash = app(Unleash::class);
91
-
92
85
$allowList = config('app.allow_list');
93
86
94
-
if ($unleash->isFeatureEnabled('myAwesomeFeature', $allowList)) {
87
+
if (Unleash::enabled('myAwesomeFeature', $allowList)) {
95
88
// Congratulations, you can see this awesome feature!
96
89
}
97
90
98
-
if ($unleash->isFeatureDisabled('myAwesomeFeature', $allowList)) {
91
+
if (Unleash::disabled('myAwesomeFeature', $allowList)) {
99
92
// Check back later for more features!
100
93
}
101
94
```
102
95
103
-
### Blade
96
+
## Variants
97
+
98
+
To use variant support, define your variants on the feature and use:
If you need to validate the arguments dynamically, you can instead use `withTestArgsUsing()` which takes a callback that returns a boolean on whether the arguments are accepted or not:
242
+
243
+
```php
244
+
use \MikeFrancis\LaravelUnleash\Values\FeatureFlag;
245
+
246
+
\Unleash::fake(
247
+
(new FeatureFlag('flag-name', true))->withTestArgsUsing(function(int $int) {
0 commit comments