From bbeae6a1880c8c5f6dc3ff6fad7807254e36e54e Mon Sep 17 00:00:00 2001 From: Anand Capur Date: Wed, 22 Feb 2023 11:44:08 -0800 Subject: [PATCH] fix config add feature flag functions --- config/posthog.php | 4 +-- src/PostHog.php | 56 ++++++++++++++++++++++++++++++++++ src/PostHogServiceProvider.php | 4 +-- 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/config/posthog.php b/config/posthog.php index 5aba3b8..e3fdda1 100644 --- a/config/posthog.php +++ b/config/posthog.php @@ -10,7 +10,7 @@ |-------------------------------------------------------------------------- */ - 'key' => '', + 'key' => env('POSTHOG_KEY', null), /* |-------------------------------------------------------------------------- @@ -18,5 +18,5 @@ |-------------------------------------------------------------------------- */ - 'host' => 'https://app.posthog.com', + 'host' => env('POSTHOG_HOST', null), ]; diff --git a/src/PostHog.php b/src/PostHog.php index f863c62..50dc47d 100644 --- a/src/PostHog.php +++ b/src/PostHog.php @@ -50,4 +50,60 @@ public static function alias(string $id, string $alias): bool 'alias' => $alias, ]); } + + /** + * @param array $groups + * @param array $personProperties + * @param array $groupProperties + * + * @throws \Exception + */ + public static function isFeatureEnabled( + string $key, + string $distinctId, + array $groups = [], + array $personProperties = [], + array $groupProperties = [], + bool $onlyEvaluateLocally = false, + bool $sendFeatureFlagEvents = true + ): null|bool { + return PostHogClient::isFeatureEnabled($key, $distinctId, $groups, $personProperties, $groupProperties, $onlyEvaluateLocally, $sendFeatureFlagEvents); + } + + /** + * @param array $groups + * @param array $personProperties + * @param array $groupProperties + * + * @throws \Exception + */ + public static function getFeatureFlag( + string $key, + string $distinctId, + array $groups = [], + array $personProperties = [], + array $groupProperties = [], + bool $onlyEvaluateLocally = false, + bool $sendFeatureFlagEvents = true + ): null|bool|string { + return PostHogClient::getFeatureFlag($key, $distinctId, $groups, $personProperties, $groupProperties, $onlyEvaluateLocally, $sendFeatureFlagEvents); + } + + /** + * @param array $groups + * @param array $personProperties + * @param array $groupProperties + * @return array + * + * @throws \Exception + */ + public static function getAllFlags( + string $distinctId, + array $groups = [], + array $personProperties = [], + array $groupProperties = [], + bool $onlyEvaluateLocally = false + ): array { + return PostHogClient::getAllFlags($distinctId, $groups, $personProperties, $groupProperties, $onlyEvaluateLocally); + } } diff --git a/src/PostHogServiceProvider.php b/src/PostHogServiceProvider.php index 3027519..27fae5b 100644 --- a/src/PostHogServiceProvider.php +++ b/src/PostHogServiceProvider.php @@ -17,8 +17,8 @@ public function configurePackage(Package $package): void public function packageBooted(): void { - if ($key = config('posthog.key')) { - PostHog::init($key, ['host' => config('posthog.host', 'https://app.posthog.com')]); + if (! empty(config('posthog.key'))) { + PostHog::init(config('posthog.key'), ['host' => empty(config('posthog.host')) ? 'https://app.posthog.com' : config('posthog.host')]); } } }