Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. MongoDbStore.php

function MongoDbStore::skimUri

Extract default database and collection from given connection URI and remove collection querystring.

Non-standard parameters are removed from the URI to improve libmongoc's re-use of connections.

See also

https://www.php.net/manual/en/mongodb.connection-handling.php

1 call to MongoDbStore::skimUri()
MongoDbStore::__construct in vendor/symfony/lock/Store/MongoDbStore.php

File

vendor/symfony/lock/Store/MongoDbStore.php, line 147

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\Store

Code

private function skimUri(string $uri) : string {
    if (!str_starts_with($uri, 'mongodb://') && !str_starts_with($uri, 'mongodb+srv://')) {
        throw new InvalidArgumentException(\sprintf('The given MongoDB Connection URI "%s" is invalid. Expecting "mongodb://" or "mongodb+srv://".', $uri));
    }
    if (false === ($params = parse_url($uri))) {
        throw new InvalidArgumentException(\sprintf('The given MongoDB Connection URI "%s" is invalid.', $uri));
    }
    $pathDb = ltrim($params['path'] ?? '', '/') ?: null;
    if (null !== $pathDb) {
        $this->options['database'] = $pathDb;
    }
    $matches = [];
    if (preg_match('/^(.*[\\?&])collection=([^&#]*)&?(([^#]*).*)$/', $uri, $matches)) {
        $prefix = $matches[1];
        $this->options['collection'] = $matches[2];
        if (empty($matches[4])) {
            $prefix = substr($prefix, 0, -1);
        }
        $uri = $prefix . $matches[3];
    }
    return $uri;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal