77use Facile \MongoDbBundle \Capsule \Client as BundleClient ;
88use Facile \MongoDbBundle \Event \ConnectionEvent ;
99use Facile \MongoDbBundle \Models \ClientConfiguration ;
10+ use Facile \MongoDbBundle \Services \UriOptions \UriOptionsInterface ;
1011use Facile \MongoDbBundle \Services \DriverOptions \DriverOptionsInterface ;
1112use MongoDB \Client ;
1213use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
@@ -31,19 +32,23 @@ final class ClientRegistry
3132 /** @var EventDispatcherInterface */
3233 private $ eventDispatcher ;
3334
35+ /** @var UriOptionsInterface */
36+ private $ uriOptionsService ;
3437 /** @var DriverOptionsInterface */
3538 private $ driverOptionsService ;
3639
3740 public function __construct (
3841 EventDispatcherInterface $ eventDispatcher ,
39- bool $ debug ,
40- ?DriverOptionsInterface $ driverOptionsService
42+ bool $ debug ,
43+ ?UriOptionsInterface $ uriOptionsService ,
44+ ?DriverOptionsInterface $ driverOptionsService
4145 ) {
4246 $ this ->clients = [];
4347 $ this ->configurations = [];
4448 $ this ->debug = $ debug ;
4549 $ this ->eventDispatcher = $ eventDispatcher ;
4650 $ this ->driverOptionsService = $ driverOptionsService ;
51+ $ this ->uriOptionsService = $ uriOptionsService ;
4752 }
4853
4954 public function addClientsConfigurations (array $ configurations ): void
@@ -64,6 +69,16 @@ private function buildClientConfiguration(array $conf): ClientConfiguration
6469 $ conf ['uri ' ] = self ::buildConnectionUri ($ conf ['hosts ' ]);
6570 }
6671
72+ $ conf ['uriOptions ' ] = [
73+ 'replicaSet ' => $ conf ['replicaSet ' ],
74+ 'ssl ' => $ conf ['ssl ' ],
75+ 'connectTimeoutMS ' => $ conf ['connectTimeoutMS ' ],
76+ 'readPreference ' => $ conf ['readPreference ' ],
77+ ];
78+ if ($ this ->uriOptionsService instanceof UriOptionsInterface) {
79+ $ conf ['options ' ] = $ this ->uriOptionsService ->buildUriOptions ($ conf ['uriOptions ' ]);
80+ }
81+
6782 $ conf ['driverOptions ' ] = [];
6883 if ($ this ->driverOptionsService instanceof DriverOptionsInterface) {
6984 $ conf ['driverOptions ' ] = $ this ->driverOptionsService ->buildDriverOptions ($ conf );
@@ -74,12 +89,7 @@ private function buildClientConfiguration(array $conf): ClientConfiguration
7489 $ conf ['username ' ],
7590 $ conf ['password ' ],
7691 $ conf ['authSource ' ],
77- [
78- 'replicaSet ' => $ conf ['replicaSet ' ],
79- 'ssl ' => $ conf ['ssl ' ],
80- 'connectTimeoutMS ' => $ conf ['connectTimeoutMS ' ],
81- 'readPreference ' => $ conf ['readPreference ' ],
82- ],
92+ $ conf ['uriOptions ' ],
8393 $ conf ['driverOptions ' ]
8494 );
8595 }
0 commit comments