ClientFactory.php in MongoDB 8.2
File
modules/mongodb/src/ClientFactory.php
View source
<?php
declare (strict_types=1);
namespace Drupal\mongodb;
use Drupal\Core\Site\Settings;
use MongoDB\Client;
class ClientFactory {
protected $settings;
protected $clients;
public function __construct(Settings $settings) {
$this->settings = $settings
->get(MongoDb::MODULE)['clients'];
}
public function get($alias) {
if (!isset($this->clients[$alias]) || !$this->clients[$alias] instanceof Client) {
$info = $this->settings[$alias] ?? [];
$info += [
'uri' => 'mongodb://localhost:27017',
'uriOptions' => [],
'driverOptions' => [],
];
$this->clients[$alias] = new Client($info['uri'], $info['uriOptions'], $info['driverOptions']);
}
return $this->clients[$alias];
}
}
Classes
Name |
Description |
ClientFactory |
Helper class to construct a MongoDB client with Drupal specific config. |