You are here

public static function MongoDb::libraryApiVersion in MongoDB 8.2

Guess an approximation of the library version, to handle API changes.

  • 1.2.0 is the minimum version required from composer.json.
  • 1.3.0 adds Collection::watch().
  • 1.4.0 deprecates Collection::count() and adds countDocuments().

@internal

Thanks to jmikola for simplifications to this method.

Return value

string A semantic versioning version string.

See also

https://github.com/mongodb/mongo-php-library/issues/558

1 call to MongoDb::libraryApiVersion()
MongoDbTest::testLibraryVersion in modules/mongodb/tests/src/Kernel/MongoDbTest.php
@covers ::libraryApiVersion

File

modules/mongodb/src/MongoDb.php, line 52

Class

MongoDb
Class MongoDb contains constants usable by all modules using the driver.

Namespace

Drupal\mongodb

Code

public static function libraryApiVersion() : string {
  if (!empty(static::$libraryVersion)) {
    return static::$libraryVersion;
  }
  if (method_exists(Collection::class, 'countDocuments')) {
    return static::$libraryVersion = '1.4.0';
  }
  if (method_exists(Collection::class, 'watch')) {
    return static::$libraryVersion = '1.3.0';
  }
  return static::$libraryVersion = '1.2.0';
}