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