|
2 | 2 | namespace LaunchDarkly; |
3 | 3 |
|
4 | 4 | use LaunchDarkly\Impl\EventFactory; |
| 5 | +use LaunchDarkly\Impl\NullEventPublisher; |
5 | 6 | use LaunchDarkly\Integrations\Guzzle; |
6 | 7 | use Monolog\Handler\ErrorLogHandler; |
7 | 8 | use Monolog\Logger; |
@@ -107,7 +108,17 @@ public function __construct($sdkKey, $options = array()) |
107 | 108 | $this->_eventFactoryDefault = new EventFactory(false); |
108 | 109 | $this->_eventFactoryWithReasons = new EventFactory(true); |
109 | 110 |
|
110 | | - $this->_eventProcessor = new EventProcessor($sdkKey, $options); |
| 111 | + if (isset($options['event_processor'])) { |
| 112 | + $ep = $options['event_processor']; |
| 113 | + if (is_callable($ep)) { |
| 114 | + $ep = $ep($sdkKey, $options); |
| 115 | + } |
| 116 | + $this->_eventProcessor = $ep; |
| 117 | + } elseif ($this->_offline || !$this->_send_events) { |
| 118 | + $this->_eventProcessor = new EventProcessor($sdkKey, $options); |
| 119 | + } else { |
| 120 | + $this->_eventProcessor = new EventProcessor($sdkKey, $options); |
| 121 | + } |
111 | 122 |
|
112 | 123 | $this->_featureRequester = $this->getFeatureRequester($sdkKey, $options); |
113 | 124 | } |
@@ -184,9 +195,6 @@ private function variationDetailInternal($key, $user, $default, $eventFactory) |
184 | 195 | return new EvaluationDetail($default, null, EvaluationReason::error($errorKind)); |
185 | 196 | }; |
186 | 197 | $sendEvent = function ($detail, $flag) use ($key, $user, $default, $eventFactory) { |
187 | | - if ($this->isOffline() || !$this->_send_events) { |
188 | | - return; |
189 | | - } |
190 | 198 | if ($flag) { |
191 | 199 | $event = $eventFactory->newEvalEvent($flag, $user, $detail, $default); |
192 | 200 | } else { |
@@ -222,10 +230,8 @@ private function variationDetailInternal($key, $user, $default, $eventFactory) |
222 | 230 | return $result; |
223 | 231 | } |
224 | 232 | $evalResult = $flag->evaluate($user, $this->_featureRequester, $eventFactory); |
225 | | - if (!$this->isOffline() && $this->_send_events) { |
226 | | - foreach ($evalResult->getPrerequisiteEvents() as $e) { |
227 | | - $this->_eventProcessor->enqueue($e); |
228 | | - } |
| 233 | + foreach ($evalResult->getPrerequisiteEvents() as $e) { |
| 234 | + $this->_eventProcessor->enqueue($e); |
229 | 235 | } |
230 | 236 | $detail = $evalResult->getDetail(); |
231 | 237 | if ($detail->isDefaultValue()) { |
@@ -271,28 +277,25 @@ public function isOffline() |
271 | 277 | * |
272 | 278 | * @param $eventName string The name of the event |
273 | 279 | * @param $user LDUser The user that performed the event |
274 | | - * @param $data mixed |
| 280 | + * @param $data mixed Optional additional information to associate with the event |
| 281 | + * @param $metricValue number A numeric value used by the LaunchDarkly experimentation feature in |
| 282 | + * numeric custom metrics. Can be omitted if this event is used by only non-numeric metrics. This |
| 283 | + * field will also be returned as part of the custom event for Data Export. |
275 | 284 | */ |
276 | | - public function track($eventName, $user, $data) |
| 285 | + public function track($eventName, $user, $data = null, $metricValue = null) |
277 | 286 | { |
278 | | - if ($this->isOffline()) { |
279 | | - return; |
280 | | - } |
281 | 287 | if (is_null($user) || $user->isKeyBlank()) { |
282 | 288 | $this->_logger->warning("Track called with null user or null/empty user key!"); |
283 | 289 | return; |
284 | 290 | } |
285 | | - $this->_eventProcessor->enqueue($this->_eventFactoryDefault->newCustomEvent($eventName, $user, $data)); |
| 291 | + $this->_eventProcessor->enqueue($this->_eventFactoryDefault->newCustomEvent($eventName, $user, $data, $metricValue)); |
286 | 292 | } |
287 | 293 |
|
288 | 294 | /** |
289 | 295 | * @param $user LDUser |
290 | 296 | */ |
291 | 297 | public function identify($user) |
292 | 298 | { |
293 | | - if ($this->isOffline()) { |
294 | | - return; |
295 | | - } |
296 | 299 | if (is_null($user) || $user->isKeyBlank()) { |
297 | 300 | $this->_logger->warning("Track called with null user or null/empty user key!"); |
298 | 301 | return; |
|
0 commit comments