8000 [HttpKernel] Support MongoClient and Mongo connection classes · symfony/symfony@de19a81 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit de19a81

Browse files
committed
[HttpKernel] Support MongoClient and Mongo connection classes
MongoClient defaults its write concern to w=1 (i.e. "safe" writes), which means update() may return an array instead of boolean true. Check for this before returning from write().
1 parent b28af77 commit de19a81

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/Symfony/Component/HttpKernel/Profiler/MongoDbProfilerStorage.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ public function write(Profile $profile)
102102
'time' => $profile->getTime()
103103
);
104104

105-
return $this->getMongo()->update(array('_id' => $profile->getToken()), array_filter($record, function ($v) { return !empty($v); }), array('upsert' => true));
105+
$result = $this->getMongo()->update(array('_id' => $profile->getToken()), array_filter($record, function ($v) { return !empty($v); }), array('upsert' => true));
106+
107+
return isset($result['ok']) ? (boolean) $result['ok'] : true;
106108
}
107109

108110
/**
@@ -114,12 +116,15 @@ protected function getMongo()
114116
{
115117
if ($this->mongo === null) {
116118
if (preg_match('#^(mongodb://.*)/(.*)/(.*)$#', $this->dsn, $matches)) {
117-
$mongo = new \Mongo($matches[1] . (!empty($matches[2]) ? '/' . $matches[2] : ''));
119+
$server = $matches[1] . (!empty($matches[2]) ? '/' . $matches[2] : '');
118120
$database = $matches[2];
119121
$collection = $matches[3];
122+
123+
$mongoClass = (version_compare(phpversion('mongo'), '1.3.0', '<')) ? '\Mongo' : '\MongoClient';
124+
$mongo = new $mongoClass($server);
120125
$this->mongo = $mongo->selectCollection($database, $collection);
121126
} else {
122-
throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use MongoDB with an invalid dsn "%s". The expected format is "mongodb://user:pass@location/database/collection"', $this->dsn));
127+
throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use MongoDB with an invalid dsn "%s". The expected format is "mongodb://[user:pass@]host/database/collection"', $this->dsn));
123128
}
124129
}
125130

0 commit comments

Comments
 (0)
0