Skip to content

Commit

Permalink
Encode mongodb keys (strip out dot)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
glensc committed Jan 19, 2021
1 parent 39d6207 commit ddaf6c2
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Saver/MongoSaver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit ddaf6c2

Please sign in to comment.