From 5db82ea8694f4300fe9a8ce277b1f716cc8fa760 Mon Sep 17 00:00:00 2001 From: Srinath Reddy Dudi Date: Wed, 15 Apr 2026 00:01:38 -0400 Subject: [PATCH] improved feature flag tracking --- src/Laritor.php | 6 +++++- src/Recorders/FeatureFlagRecorder.php | 28 ++++++--------------------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/src/Laritor.php b/src/Laritor.php index 2c179f5..80c9b6f 100644 --- a/src/Laritor.php +++ b/src/Laritor.php @@ -13,7 +13,7 @@ class Laritor { - public const VERSION = '3.0.4'; + public const VERSION = '3.0.5'; /** * @var array @@ -83,6 +83,10 @@ public function booted() public function controllerStarted() { + if (!$this->started) { + $this->started = microtime(true); + } + $this->middleware = $this->getDurationFrom($this->started) - $this->booted; $this->setContext('CONTROLLER'); } diff --git a/src/Recorders/FeatureFlagRecorder.php b/src/Recorders/FeatureFlagRecorder.php index 415f3b6..83785e1 100644 --- a/src/Recorders/FeatureFlagRecorder.php +++ b/src/Recorders/FeatureFlagRecorder.php @@ -37,27 +37,11 @@ public static function recordFeatureCheck(string $feature, bool $active = true) { $laritor = app(Laritor::class); - $flags = $laritor->getEvents(self::$eventType); - $addedFlags = []; - - $flagAdded = false; - foreach ($flags as $flag) { - if ($flag['feature'] === $feature) { - $flagAdded = true; - $flag['active'] = $active; - } - - $addedFlags[] = $flag; - } - - if (!$flagAdded) { - $addedFlags[] = [ - 'feature' => $feature, - 'active' => $active, - 'checked_at' => now()->toDateTimeString(), - ]; - } - - $laritor->addevents(self::$eventType, $addedFlags); + $laritor->pushEvent(self::$eventType, [ + 'feature' => $feature, + 'active' => $active, + 'context' => $laritor->getContext(), + 'checked_at' => now()->toDateTimeString(), + ]); } }