diff --git a/DependencyInjection/DoctrineMongoDBExtension.php b/DependencyInjection/DoctrineMongoDBExtension.php index df048cf7..7b2af849 100644 --- a/DependencyInjection/DoctrineMongoDBExtension.php +++ b/DependencyInjection/DoctrineMongoDBExtension.php @@ -16,6 +16,7 @@ use Doctrine\Common\EventSubscriber; use Doctrine\ODM\MongoDB\DocumentManager; use InvalidArgumentException; +use Jean85\PrettyVersions; use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension; use Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerWorkerSubscriber; use Symfony\Component\Cache\Adapter\ApcuAdapter; @@ -32,6 +33,7 @@ use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\Messenger\MessageBusInterface; +use Throwable; use function array_keys; use function array_merge; use function class_exists; @@ -48,6 +50,9 @@ */ class DoctrineMongoDBExtension extends AbstractDoctrineExtension { + /** @var string */ + private static $odmVersion; + /** @internal */ public const CONFIGURATION_TAG = 'doctrine.odm.configuration'; @@ -407,6 +412,11 @@ private function normalizeDriverOptions(array $connection) $driverOptions['context'] = new Reference($driverOptions['context']); } + $driverOptions['driver'] = [ + 'name' => 'symfony-mongodb', + 'version' => self::getODMVersion(), + ]; + return $driverOptions; } @@ -610,4 +620,17 @@ private function buildDeprecationArgs(string $version, string $message): array ? ['doctrine/mongodb-odm-bundle', $version, $message] : [$message]; } + + private static function getODMVersion(): string + { + if (self::$odmVersion === null) { + try { + self::$odmVersion = PrettyVersions::getVersion('doctrine/mongodb-odm')->getPrettyVersion(); + } catch (Throwable $t) { + return 'unknown'; + } + } + + return self::$odmVersion; + } } diff --git a/composer.json b/composer.json index 2d320fde..ff7752b6 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ "doctrine/annotations": "^1.13", "doctrine/mongodb-odm": "^2.3", "doctrine/persistence": "^2.2|^3.0", + "jean85/pretty-package-versions": "^1.3.0 || ^2.0.1", "psr/log": "^1.0|^2.0|^3.0", "symfony/config": "^4.4|^5.3|^6.0", "symfony/console": "^4.4.6|^5.3|^6.0",