Skip to content
This repository has been archived by the owner on Sep 26, 2020. It is now read-only.

Commit

Permalink
New static method to generate a profiling ID and pass it to a profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
AlarSuu committed Aug 23, 2017
1 parent c68ee22 commit 8e46f10
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/Xhgui/Profiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ class Xhgui_Profiles

protected $_mapper;

/**
* @var MongoId lastProfilingId
*/
private static $lastProfilingId;

public function __construct(MongoDb $db)
{
$this->_collection = $db->results;
Expand All @@ -22,20 +27,18 @@ public function __construct(MongoDb $db)
*/
public function insert($profile)
{
$profile = $this->setProfilingId($profile);
$profile['_id'] = self::getLastProfilingId();
return $this->_collection->insert($profile, array('w' => 0));
}

/**
* Set profiling ID, if it is already initiated
*
* @param array $profile The profile data
* @return array
*/
public function setProfilingId($profile) {
if (!empty(Xhgui_Saver::getLastProfilingId())) {
$profile['_id'] = Xhgui_Saver::getLastProfilingId();
}
return $profile;
}
/**
* Return profiling ID
* @return MongoId lastProfilingId
*/
public static function getLastProfilingId() {
if (!self::$lastProfilingId) {
self::$lastProfilingId = new MongoId();
}
return self::$lastProfilingId;
}
}

0 comments on commit 8e46f10

Please sign in to comment.