Skip to content

Commit 794c435

Browse files
authored
Merge pull request #61 from perftools/mongo-encode-keys
2 parents be7b751 + c281e23 commit 794c435

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

src/Saver/MongoSaver.php

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

2121
public function save(array $data)
2222
{
23+
if (isset($data['profile'])) {
24+
$data['profile'] = $this->encodeProfile($data['profile']);
25+
}
26+
2327
$result = parent::save($data);
2428

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

0 commit comments

Comments
 (0)