protected function MongoDbProfilerStorage::getMongo

Internal convenience method that returns the instance of the MongoDB Collection

Return value

\MongoCollection

Throws

\RuntimeException

1 call to MongoDbProfilerStorage::getMongo()
DummyMongoDbProfilerStorage::getMongo in drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/Profiler/MongoDbProfilerStorageTest.php
Internal convenience method that returns the instance of the MongoDB Collection
1 method overrides MongoDbProfilerStorage::getMongo()
DummyMongoDbProfilerStorage::getMongo in drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/Profiler/MongoDbProfilerStorageTest.php
Internal convenience method that returns the instance of the MongoDB Collection

File

drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Profiler/MongoDbProfilerStorage.php, line 100

Class

MongoDbProfilerStorage

Namespace

Symfony\Component\HttpKernel\Profiler

Code

protected function getMongo() {
  if ($this->mongo === null) {
    if (preg_match('#^(mongodb://.*)/(.*)/(.*)$#', $this->dsn, $matches)) {
      $server = $matches[1] . (!empty($matches[2]) ? '/' . $matches[2] : '');
      $database = $matches[2];
      $collection = $matches[3];
      $mongoClass = version_compare(phpversion('mongo'), '1.3.0', '<') ? '\\Mongo' : '\\MongoClient';
      $mongo = new $mongoClass($server);
      $this->mongo = $mongo
        ->selectCollection($database, $collection);
    }
    else {
      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));
    }
  }
  return $this->mongo;
}