@@ -118,12 +118,8 @@ public function __construct(?string $uri = null, array $uriOptions = [], array $
118
118
throw InvalidArgumentException::invalidType ('"typeMap" driver option ' , $ driverOptions ['typeMap ' ], 'array ' );
119
119
}
120
120
121
- if (isset ($ driverOptions ['autoEncryption ' ]['keyVaultClient ' ])) {
122
- if ($ driverOptions ['autoEncryption ' ]['keyVaultClient ' ] instanceof self) {
123
- $ driverOptions ['autoEncryption ' ]['keyVaultClient ' ] = $ driverOptions ['autoEncryption ' ]['keyVaultClient ' ]->manager ;
124
- } elseif (! $ driverOptions ['autoEncryption ' ]['keyVaultClient ' ] instanceof Manager) {
125
- throw InvalidArgumentException::invalidType ('"keyVaultClient" autoEncryption option ' , $ driverOptions ['autoEncryption ' ]['keyVaultClient ' ], [self ::class, Manager::class]);
126
- }
121
+ if (isset ($ driverOptions ['autoEncryption ' ]) && is_array ($ driverOptions ['autoEncryption ' ])) {
122
+ $ driverOptions ['autoEncryption ' ] = $ this ->prepareEncryptionOptions ($ driverOptions ['autoEncryption ' ]);
127
123
}
128
124
129
125
if (isset ($ driverOptions ['builderEncoder ' ]) && ! $ driverOptions ['builderEncoder ' ] instanceof Encoder) {
@@ -232,13 +228,7 @@ public function bulkWrite(BulkWriteCommand|ClientBulkWrite $bulk, array $options
232
228
*/
233
229
public function createClientEncryption (array $ options ): ClientEncryption
234
230
{
235
- if (isset ($ options ['keyVaultClient ' ])) {
236
- if ($ options ['keyVaultClient ' ] instanceof self) {
237
- $ options ['keyVaultClient ' ] = $ options ['keyVaultClient ' ]->manager ;
238
- } elseif (! $ options ['keyVaultClient ' ] instanceof Manager) {
239
- throw InvalidArgumentException::invalidType ('"keyVaultClient" option ' , $ options ['keyVaultClient ' ], [self ::class, Manager::class]);
240
- }
241
- }
231
+ $ options = $ this ->prepareEncryptionOptions ($ options );
242
232
243
233
return $ this ->manager ->createClientEncryption ($ options );
244
234
}
@@ -500,4 +490,26 @@ private function mergeDriverInfo(array $driver): array
500
490
501
491
return $ mergedDriver ;
502
492
}
493
+
494
+ private function prepareEncryptionOptions (array $ options ): array
495
+ {
496
+ if (isset ($ options ['keyVaultClient ' ])) {
497
+ if ($ options ['keyVaultClient ' ] instanceof self) {
498
+ $ options ['keyVaultClient ' ] = $ options ['keyVaultClient ' ]->manager ;
499
+ } elseif (! $ options ['keyVaultClient ' ] instanceof Manager) {
500
+ throw InvalidArgumentException::invalidType ('"keyVaultClient" option ' , $ options ['keyVaultClient ' ], [self ::class, Manager::class]);
501
+ }
502
+ }
503
+
504
+ // The server requires an empty document for automatic credentials.
505
+ if (isset ($ options ['kmsProviders ' ]) && is_array ($ options ['kmsProviders ' ])) {
506
+ foreach ($ options ['kmsProviders ' ] as $ name => $ provider ) {
507
+ if ($ provider === []) {
508
+ $ options ['kmsProviders ' ][$ name ] = new stdClass ();
509
+ }
510
+ }
511
+ }
512
+
513
+ return $ options ;
514
+ }
503
515
}
0 commit comments