diff --git a/src/Saver/MongoSaver.php b/src/Saver/MongoSaver.php index add5fd9..220ad13 100644 --- a/src/Saver/MongoSaver.php +++ b/src/Saver/MongoSaver.php @@ -20,8 +20,33 @@ public function isSupported() public function save(array $data) { + $data['profile'] = $this->encodeProfile($data['profile']); + $result = parent::save($data); return !empty($result); } + + /** + * MongoDB can't save keys with values containing a dot: + * + * InvalidArgumentException: invalid document for insert: keys cannot contain ".": + * "Zend_Controller_Dispatcher_Standard::loadClass==>load::controllers/ArticleController.php" + * + * Replace the dots with underscrore in keys. + * + * @link https://github.com/perftools/xhgui/issues/209 + */ + private function encodeProfile(array $profile) + { + $results = array(); + foreach ($profile as $k => $v) { + if (strpos($k, '.') !== false) { + $k = str_replace('.', '_', $k); + } + $results[$k] = $v; + } + + return $results; + } }