From 0573cdb75a367eab0cd96221d6e1b433c97613e3 Mon Sep 17 00:00:00 2001 From: ziming Date: Sat, 8 Jul 2023 17:30:17 +0800 Subject: [PATCH] rename statsigfeaturegate to statsigcheckgate, statsig_feature_gate to statsig_check_gate. Remove incomplete middleware for now --- README.md | 10 +++++----- src/LaravelStatsig.php | 4 ++++ src/LaravelStatsigServiceProvider.php | 2 +- .../EnsureStatsigFeaturesAreActive.php | 20 ------------------- src/helpers.php | 4 ++-- 5 files changed, 12 insertions(+), 28 deletions(-) delete mode 100644 src/Middleware/EnsureStatsigFeaturesAreActive.php diff --git a/README.md b/README.md index 7137770..40afed3 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Laravel Package for Statsig. A Feature Gate & A/B Testing Platform with a somewhat decent free tier. This package is still very early in development & likely not ready for production use yet. -I have only just started using it in production on a small site 1st. +I have only just started using it in production on 2 small sites currently. Use at your own risk if you want to try it now. But if you have used in production, it would be great to let me know :) @@ -18,7 +18,7 @@ It is basically a wrapper around the [Statsig PHP SDK](https://docs.statsig.com/ The following features are being considered for the future. If any of it interest you, feel free to submit a PR. -- New Adaptors +- New Adapters - New Middlewares - Convenience Traits & Methods - Octane/Vapor/Serverless Support (Probably far in the future) @@ -129,9 +129,9 @@ It is confusingly named in all lowercase to match the official laravel naming co Currently it can only be used if the user is logged in. Do not use it for your guest pages for now. ```blade -@statsigfeaturegate('gate_name') +@statsigcheckgate('gate_name')

This is shown if this statsig gate return true

-@endstatsigfeaturegate +@endstatsigcheckgate ``` Lastly, a helper function is also provided if you want to be even more concise in your blade templates. @@ -140,7 +140,7 @@ It is named in snake case, following laravel naming conventions for global helpe Like the blade directive, currently it can only be used if the user is logged in. ```blade -
+
``` ## Testing diff --git a/src/LaravelStatsig.php b/src/LaravelStatsig.php index 0b1adf9..9708b26 100755 --- a/src/LaravelStatsig.php +++ b/src/LaravelStatsig.php @@ -141,6 +141,10 @@ public function flush(): void */ public function __call(string $name, array $arguments): mixed { + if (isset($arguments[0]) && $arguments[0] instanceof Authenticatable) { + $arguments[0] = LaravelUserToStatsigUserConverter::convertLaravelUserToStatsigUser($arguments[0]); + } + return $this->statsigServer->$name(...$arguments); } } diff --git a/src/LaravelStatsigServiceProvider.php b/src/LaravelStatsigServiceProvider.php index 0c20b8c..9aa8006 100644 --- a/src/LaravelStatsigServiceProvider.php +++ b/src/LaravelStatsigServiceProvider.php @@ -32,7 +32,7 @@ public function configurePackage(Package $package): void public function packageBooted(): void { - Blade::if('statsigfeaturegate', function (string $gateName) { + Blade::if('statsigcheckgate', function (string $gateName) { return LaravelStatsig::checkGate(Auth::user(), $gateName); }); } diff --git a/src/Middleware/EnsureStatsigFeaturesAreActive.php b/src/Middleware/EnsureStatsigFeaturesAreActive.php deleted file mode 100644 index 832aa95..0000000 --- a/src/Middleware/EnsureStatsigFeaturesAreActive.php +++ /dev/null @@ -1,20 +0,0 @@ -user, $features) === false) { - // TODO: Allow the user to specify a custom response in the future - abort(400); - } - } -} diff --git a/src/helpers.php b/src/helpers.php index e45bf56..7bc3249 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -5,8 +5,8 @@ use Illuminate\Support\Facades\Auth; use Ziming\LaravelStatsig\Facades\LaravelStatsig; -if (! function_exists('statsig_feature_gate')) { - function statsig_feature_gate(string $name): bool +if (! function_exists('statsig_check_gate')) { + function statsig_check_gate(string $name): bool { return LaravelStatsig::checkGate(Auth::user(), $name); }