Skip to content

Commit

Permalink
fix config add feature flag functions
Browse files Browse the repository at this point in the history
  • Loading branch information
arcdigital committed Feb 22, 2023
1 parent 2cfebbf commit bbeae6a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
4 changes: 2 additions & 2 deletions config/posthog.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
|--------------------------------------------------------------------------
*/

'key' => '',
'key' => env('POSTHOG_KEY', null),

/*
|--------------------------------------------------------------------------
| PostHog Key
|--------------------------------------------------------------------------
*/

'host' => 'https://app.posthog.com',
'host' => env('POSTHOG_HOST', null),
];
56 changes: 56 additions & 0 deletions src/PostHog.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,60 @@ public static function alias(string $id, string $alias): bool
'alias' => $alias,
]);
}

/**
* @param array<mixed> $groups
* @param array<mixed> $personProperties
* @param array<mixed> $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<mixed> $groups
* @param array<mixed> $personProperties
* @param array<mixed> $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<mixed> $groups
* @param array<mixed> $personProperties
* @param array<mixed> $groupProperties
* @return array<mixed>
*
* @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);
}
}
4 changes: 2 additions & 2 deletions src/PostHogServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')]);
}
}
}

0 comments on commit bbeae6a

Please sign in to comment.