function MongoDbStore::__construct
Parameters
Collection|Client|Manager|string $mongo An instance of a Collection or Client or URI @see https://docs.mongodb.com/manual/reference/connection-string/:
array $options See below:
float $initialTtl The expiration delay of locks in seconds:
Throws
InvalidArgumentException If required options are not provided
InvalidTtlException When the initial ttl is not valid
Options: gcProbability: Should a TTL Index be created expressed as a probability from 0.0 to 1.0 [default: 0.001] database: The name of the database [required when $mongo is a Client] collection: The name of the collection [required when $mongo is a Client] uriOptions: Array of uri options. [used when $mongo is a URI] driverOptions: Array of driver options. [used when $mongo is a URI]
When using a URI string: The database is determined from the uri's path, otherwise the "database" option is used. To specify an alternate authentication database; "authSource" uriOption or querystring parameter must be used. The collection is determined from the uri's "collection" querystring parameter, otherwise the "collection" option is used.
For example: mongodb://myuser:mypass@myhost/mydatabase?collection=mycollection
If gcProbability is set to a value greater than 0.0 there is a chance this store will attempt to create a TTL index on self::save(). If you prefer to create your TTL Index manually you can set gcProbability to 0.0 and optionally leverage self::createTtlIndex(int $expireAfterSeconds = 0).
writeConcern and readConcern are not specified by MongoDbStore meaning the connection's settings will take effect. readPreference is primary for all queries.
See also
https://docs.mongodb.com/php-library/current/reference/method/MongoDBCl…
https://docs.mongodb.com/manual/applications/replication/
File
-
vendor/
symfony/ lock/ Store/ MongoDbStore.php, line 95
Class
- MongoDbStore
- MongoDbStore is a StoreInterface implementation using MongoDB as a storage engine. Support for MongoDB server >=2.2 due to use of TTL indexes.
Namespace
Symfony\Component\Lock\StoreCode
public function __construct(Collection|Database|Client|Manager|string $mongo, array $options = [], float $initialTtl = 300.0) {
$this->options = array_merge([
'gcProbability' => 0.001,
'database' => null,
'collection' => null,
'uriOptions' => [],
'driverOptions' => [],
], $options);
if ($mongo instanceof Collection) {
$this->options['database'] ??= $mongo->getDatabaseName();
$this->options['collection'] ??= $mongo->getCollectionName();
$this->manager = $mongo->getManager();
}
elseif ($mongo instanceof Database) {
$this->options['database'] ??= $mongo->getDatabaseName();
$this->manager = $mongo->getManager();
}
elseif ($mongo instanceof Client) {
$this->manager = $mongo->getManager();
}
elseif ($mongo instanceof Manager) {
$this->manager = $mongo;
}
else {
$this->uri = $this->skimUri($mongo);
}
if (null === $this->options['database']) {
throw new InvalidArgumentException(\sprintf('"%s()" requires the "database" in the URI path or option.', __METHOD__));
}
if (null === $this->options['collection']) {
throw new InvalidArgumentException(\sprintf('"%s()" requires the "collection" in the URI querystring or option.', __METHOD__));
}
$this->namespace = $this->options['database'] . '.' . $this->options['collection'];
if ($this->options['gcProbability'] < 0.0 || $this->options['gcProbability'] > 1.0) {
throw new InvalidArgumentException(\sprintf('"%s()" gcProbability must be a float from 0.0 to 1.0, "%f" given.', __METHOD__, $this->options['gcProbability']));
}
if ($this->initialTtl <= 0) {
throw new InvalidTtlException(\sprintf('"%s()" expects a strictly positive TTL, got "%d".', __METHOD__, $this->initialTtl));
}
}