-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add Support For Feature Flag Payloads #53
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,11 @@ class Client | |
*/ | ||
public $distinctIdsFeatureFlagsReported; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $decideVersion; | ||
|
||
/** | ||
* Create a new posthog object with your app's API key | ||
* key | ||
|
@@ -87,6 +92,7 @@ public function __construct( | |
$this->featureFlags = []; | ||
$this->groupTypeMapping = []; | ||
$this->distinctIdsFeatureFlagsReported = new SizeLimitedHash(SIZE_LIMIT); | ||
$this->decideVersion = $options["decide_version"] ?? '2'; | ||
|
||
// Populate featureflags and grouptypemapping if possible | ||
if (count($this->featureFlags) == 0 && !is_null($this->personalAPIKey)) { | ||
|
@@ -261,6 +267,41 @@ public function getFeatureFlag( | |
return null; | ||
} | ||
|
||
/** | ||
* @param string $key | ||
* @param string $distinctId | ||
* @param array $groups | ||
* @param array $personProperties | ||
* @param array $groupProperties | ||
* @return mixed | ||
*/ | ||
public function getFeatureFlagPayload( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only thing blocking a merge here is support for local evaluation -> since You can copy the exact code from python: https://github.com/PostHog/posthog-python/blob/master/posthog/client.py#L602 - and compare the You can also then copy all the tests below this line: https://github.com/PostHog/posthog-python/pull/81/files#diff-0e2fa9949bd8d80eecebfa2ff9b994a1bc528fbb003c7e80d104e6d5b3c5f07fR1379-R1384 to make sure it works fine. Let me know if any questions! :) If this is too much for your bandwidth, let me know too. |
||
string $key, | ||
string $distinctId, | ||
array $groups = array(), | ||
array $personProperties = array(), | ||
array $groupProperties = array(), | ||
): mixed { | ||
$results = json_decode( | ||
$this->decide($distinctId, $groups, $personProperties, $groupProperties), | ||
true | ||
); | ||
|
||
if (isset($results['featureFlags'][$key]) === false || $results['featureFlags'][$key] !== true) { | ||
return null; | ||
} | ||
|
||
$payload = $results['featureFlagPayloads'][$key] ?? null; | ||
|
||
$json = json_decode($payload, true); | ||
|
||
if (is_array($json)) { | ||
return $json; | ||
} | ||
|
||
return $payload; | ||
} | ||
|
||
/** | ||
* get the feature flag value for this distinct id. | ||
* | ||
|
@@ -425,7 +466,7 @@ public function decide( | |
} | ||
|
||
return $this->httpClient->sendRequest( | ||
'/decide/?v=2', | ||
'/decide/?v=' . $this->decideVersion, | ||
json_encode($payload), | ||
[ | ||
// Send user agent in the form of {library_name}/{library_version} as per RFC 7231. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Elliot, instead of making this an option, force update everything to version 3, I'll make a major version release for PHP with your PR, since we are meant to move off of v2 anyway.