From ddaf6c22bb00285a8051d1a2eb50f9b5be7e7488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Tue, 19 Jan 2021 18:04:02 +0200 Subject: [PATCH] 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: - https://github.com/perftools/xhgui/pull/352 Users are encouraged to switch to file or upload savers --- src/Saver/MongoSaver.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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; + } }