Skip to content

Commit 1cb6b99

Browse files
committed
Merge pull request #3 from launchdarkly/jko/identify
Add identify support
2 parents a109333 + 495850b commit 1cb6b99

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/LaunchDarkly/LDClient.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,19 @@ public function getFlag($key, $user, $default = false) {
7878
}
7979
} catch (Exception $e) {
8080
error_log("LaunchDarkly caught $e");
81-
$this->_sendFlagRequestEvent($key, $user, $default);
81+
try {
82+
$this->_sendFlagRequestEvent($key, $user, $default);
83+
}
84+
catch (Exception $e) {
85+
error_log("LaunchDarkly caught $e");
86+
}
8287
return $default;
8388
}
8489
}
8590

8691
/**
8792
* Puts the LaunchDarkly client in offline mode.
88-
* In offline mode, all calls to `getFlag` will return the default value, and `sendEvent` will be a no-op.
93+
* In offline mode, all calls to `getFlag` will return the default value, and `track` will be a no-op.
8994
*
9095
*/
9196
public function setOffline() {
@@ -115,7 +120,7 @@ public function isOffline() {
115120
* @param LDUser $user The user that performed the event
116121
*
117122
*/
118-
public function sendEvent($eventName, $user, $data) {
123+
public function track($eventName, $user, $data) {
119124
if ($this->isOffline()) {
120125
return;
121126
}
@@ -131,6 +136,19 @@ public function sendEvent($eventName, $user, $data) {
131136
$this->_eventProcessor->enqueue($event);
132137
}
133138

139+
public function identify($user) {
140+
if ($this->isOffline()) {
141+
return;
142+
}
143+
144+
$event = array();
145+
$event['user'] = $user->toJSON();
146+
$event['kind'] = "identify";
147+
$event['creationDate'] = round(microtime(1) * 1000);
148+
$event['key'] = $user->getKey();
149+
$this->_eventProcessor->enqueue($event);
150+
}
151+
134152
protected function _sendFlagRequestEvent($key, $user, $value) {
135153
if ($this->isOffline()) {
136154
return;

0 commit comments

Comments
 (0)