From 909ffbc5c6d768466c8afd302a5982584cd93cbb Mon Sep 17 00:00:00 2001 From: Alar Suut Date: Wed, 23 Aug 2017 12:16:51 +0300 Subject: [PATCH] New static method to generate a profiling ID and pass it to a profiler --- src/Xhgui/Profiles.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Xhgui/Profiles.php b/src/Xhgui/Profiles.php index 70aefdf..8ff07d9 100644 --- a/src/Xhgui/Profiles.php +++ b/src/Xhgui/Profiles.php @@ -8,6 +8,11 @@ class Xhgui_Profiles protected $_mapper; + /** + * @var MongoId lastProfilingId + */ + private static $lastProfilingId; + public function __construct(MongoDb $db) { $this->_collection = $db->results; @@ -22,6 +27,18 @@ public function __construct(MongoDb $db) */ public function insert($profile) { + $profile['_id'] = self::getLastProfilingId(); return $this->_collection->insert($profile, array('w' => 0)); } + + /** + * Return profiling ID + * @return MongoId lastProfilingId + */ + public static function getLastProfilingId() { + if (!self::$lastProfilingId) { + self::$lastProfilingId = new MongoId(); + } + return self::$lastProfilingId; + } }