1
1
[ ![ GitHub license] ( https://img.shields.io/github/license/PabloJoan/feature.svg )] ( https://github.com/PabloJoan/feature/blob/master/LICENSE )
2
2
3
- Requires PHP 8.2 and above.
3
+ Requires PHP 8.3 and above.
4
4
5
5
# Installation
6
6
@@ -33,7 +33,7 @@ $featureConfigs = [
33
33
34
34
$features = new Features($featureConfigs);
35
35
36
- $features->isEnabled(featureName: 'foo'); // true
36
+ $features->isEnabled(featureName: 'foo'); // true
37
37
$features->getEnabledVariant(featureName: 'foo'); // 'variant1'
38
38
```
39
39
@@ -50,27 +50,34 @@ A feature can be completely enabled, completely disabled, or something in
50
50
between and can comprise a number of related variants.
51
51
52
52
The two main API entry points are:
53
+
53
54
``` php
54
55
$features->isEnabled(featureName: 'my_feature')
55
56
```
57
+
56
58
which returns true when ` my_feature ` is enabled and, for multi-variant features:
59
+
57
60
``` php
58
61
$features->getEnabledVariant(featureName: 'my_feature')
59
62
```
63
+
60
64
which returns the name of the particular variant which should be used.
61
65
62
66
The single argument to each of these methods is the name of the
63
67
feature to test.
64
68
65
69
A typical use of ` $features->isEnabled ` for a single-variant feature
66
70
would look something like this:
71
+
67
72
``` php
68
73
if ($features->isEnabled(featureName: 'my_feature')) {
69
74
// do stuff
70
75
}
71
76
```
77
+
72
78
For a multi-variant feature, we can determine the appropriate code to run for
73
79
each variant with something like this:
80
+
74
81
``` php
75
82
switch ($features->getEnabledVariant(featureName: 'my_feature')) {
76
83
case 'foo':
@@ -81,8 +88,10 @@ each variant with something like this:
81
88
break;
82
89
}
83
90
```
91
+
84
92
If a feature is bucketed by id, then we pass the id string to
85
93
` $features->isEnabled ` and ` $features->getEnabledVariant ` as a second parameter
94
+
86
95
``` php
87
96
$isMyFeatureEnabled = $features->isEnabled(
88
97
featureName: 'my_feature',
@@ -95,30 +104,38 @@ If a feature is bucketed by id, then we pass the id string to
95
104
);
96
105
```
97
106
98
-
99
107
## Configuration cookbook
100
108
101
109
There are a number of common configurations so before I explain the complete
102
110
syntax of the feature configuration stanzas, here are some of the more common
103
111
cases along with the most concise way to write the configuration.
104
112
105
113
### A totally enabled feature:
114
+
106
115
``` php
107
116
$server_config['foo'] = ['variants' => ['enabled' => 100]];
108
117
```
118
+
109
119
### A totally disabled feature:
120
+
110
121
``` php
111
122
$server_config['foo'] = ['variants' => ['enabled' => 0]];
112
123
```
124
+
113
125
### Feature with winning variant turned on for everyone
126
+
114
127
``` php
115
128
$server_config['foo'] = ['variants' => ['blue_background' => 100]];
116
129
```
130
+
117
131
### Single-variant feature ramped up to 1% of users.
132
+
118
133
``` php
119
134
$server_config['foo'] = ['variants' => ['enabled' => 1]];
120
135
```
136
+
121
137
### Multi-variant feature ramped up to 1% of users for each variant.
138
+
122
139
``` php
123
140
$server_config['foo'] = [
124
141
'variants' => [
@@ -128,31 +145,41 @@ cases along with the most concise way to write the configuration.
128
145
],
129
146
];
130
147
```
148
+
131
149
### Enabled for 10% of regular users.
150
+
132
151
``` php
133
152
$server_config['foo'] = [
134
153
'variants' => ['enabled' => 10]
135
154
];
136
155
```
156
+
137
157
### Feature ramped up to 1% of requests, bucketing at random rather than by id
158
+
138
159
``` php
139
160
$server_config['foo'] = [
140
161
'variants' => ['enabled' => 1],
141
162
'bucketing' => 'random'
142
163
];
143
164
```
165
+
144
166
### Feature ramped up to 40% of requests, bucketing by id rather than at random
167
+
145
168
``` php
146
169
$server_config['foo'] = [
147
170
'variants' => ['enabled' => 40],
148
171
'bucketing' => 'id'
149
172
];
150
173
```
174
+
151
175
### Single-variant feature in 50/50 A/B test
176
+
152
177
``` php
153
178
$server_config['foo'] = ['variants' => ['enabled' => 50]];
154
179
```
180
+
155
181
### Multi-variant feature in A/B test with 20% of users seeing each variant (and 40% left in control group).
182
+
156
183
``` php
157
184
$server_config['foo'] = [
158
185
'variants' => [
@@ -162,6 +189,7 @@ cases along with the most concise way to write the configuration.
162
189
],
163
190
];
164
191
```
192
+
165
193
## Configuration details
166
194
167
195
Each feature’s config stanza controls when the feature is enabled and what
@@ -173,7 +201,7 @@ keys, the most important of which is `'variants'`.
173
201
The value of the ` 'variants' ` property an array whose keys are names of variants
174
202
and whose values are the percentage of requests that should see each variant.
175
203
176
- The remaining feature config property is ` 'bucketing' ` . Bucketing specifies
204
+ The remaining feature config property is ` 'bucketing' ` . Bucketing specifies
177
205
how users are bucketed when a feature is enabled for only a percentage of users.
178
206
The default value, ` 'random' ` , causes each request to be bucketed independently,
179
207
meaning that the same user will be in different buckets on different requests.
@@ -189,12 +217,12 @@ There are a few ways to misuse the Feature API or misconfigure a feature that
189
217
may be detected. (Some of these are not currently detected but may be in the
190
218
future.)
191
219
192
- 1 . Setting the percentage value of a variant in ` 'variants' ` to a value less
193
- than 0 or greater than 100.
220
+ 1 . Setting the percentage value of a variant in ` 'variants' ` to a value less
221
+ than 0 or greater than 100.
194
222
195
- 2 . Setting ` 'variants' ` such that the sum of the variant percentages is
196
- greater than 100.
223
+ 2 . Setting ` 'variants' ` such that the sum of the variant percentages is
224
+ greater than 100.
197
225
198
- 3 . Setting ` 'variants' ` to a non-array value.
226
+ 3 . Setting ` 'variants' ` to a non-array value.
199
227
200
- 4 . Setting ` 'bucketing' ` to any value that is not ` 'id' ` or ` 'random' ` .
228
+ 4 . Setting ` 'bucketing' ` to any value that is not ` 'id' ` or ` 'random' ` .
0 commit comments