Skip to content

Commit ddaf6c2

Browse files
committed
Encode mongodb keys (strip out dot)
As the perftools/xhgui-collector package will no longer be updated, do the change in perftools/php-profiler package This duplicates same fix in xhgui itself: - perftools/xhgui#352 Users are encouraged to switch to file or upload savers
1 parent 39d6207 commit ddaf6c2

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

src/Saver/MongoSaver.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,33 @@ public function isSupported()
2020

2121
public function save(array $data)
2222
{
23+
$data['profile'] = $this->encodeProfile($data['profile']);
24+
2325
$result = parent::save($data);
2426

2527
return !empty($result);
2628
}
29+
30+
/**
31+
* MongoDB can't save keys with values containing a dot:
32+
*
33+
* InvalidArgumentException: invalid document for insert: keys cannot contain ".":
34+
* "Zend_Controller_Dispatcher_Standard::loadClass==>load::controllers/ArticleController.php"
35+
*
36+
* Replace the dots with underscrore in keys.
37+
*
38+
* @link https://github.com/perftools/xhgui/issues/209
39+
*/
40+
private function encodeProfile(array $profile)
41+
{
42+
$results = array();
43+
foreach ($profile as $k => $v) {
44+
if (strpos($k, '.') !== false) {
45+
$k = str_replace('.', '_', $k);
46+
}
47+
$results[$k] = $v;
48+
}
49+
50+
return $results;
51+
}
2752
}

0 commit comments

Comments
 (0)