File tree 2 files changed +39
-6
lines changed
2 files changed +39
-6
lines changed Original file line number Diff line number Diff line change @@ -44,16 +44,11 @@ public function register()
44
44
*
45
45
* @return void
46
46
*/
47
- public function boot (? FeatureToggleClient $ client = null , ? Request $ request = null )
47
+ public function boot ()
48
48
{
49
49
$ this ->publishes ([
50
50
__DIR__ .'/../config/feature-toggle.php ' => config_path ('feature-toggle.php ' ),
51
51
]);
52
-
53
- if ($ client ) {
54
- // The SplitIO SDK doesn't allow empty keys.
55
- $ client ->setKey (optional ($ request ->user ())->email ?? "__dummy_key__ " );
56
- }
57
52
}
58
53
59
54
private static $ splitIOFactory ;
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace PartechGSS \Laravel \FeatureToggle \Middleware ;
4
+
5
+ use Closure ;
6
+ use PartechGSS \Laravel \FeatureToggle \Contracts \FeatureToggleClient ;
7
+
8
+ class SetFeatureToggleKeyFromUserEmail
9
+ {
10
+ private $ featureToggleClient ;
11
+
12
+ /**
13
+ * Create a new middleware instance.
14
+ *
15
+ * @param ApiManager $auth
16
+ * @return void
17
+ */
18
+ public function __construct (FeatureToggleClient $ featureToggleClient )
19
+ {
20
+ $ this ->featureToggleClient = $ featureToggleClient ;
21
+ }
22
+
23
+ /**
24
+ * Handle an incoming request. Sets the feature toggle client key to $request->user()->email
25
+ * when found, and to "__no_user__" otherwise.
26
+ *
27
+ * @param \Illuminate\Http\Request $request
28
+ * @param \Closure $next
29
+ * @return mixed
30
+ */
31
+ public function handle ($ request , Closure $ next )
32
+ {
33
+ // After authentication, set the feature toggle key to the user's email.
34
+ $ this ->featureToggleClient ->setKey (optional ($ request ->user ())->email ?? "__no_user__ " );
35
+
36
+ return $ next ($ request );
37
+ }
38
+ }
You can’t perform that action at this time.
0 commit comments