@@ -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) {
@@ -213,13 +209,7 @@ final public function addSubscriber(Subscriber $subscriber): void
213
209
*/
214
210
public function createClientEncryption (array $ options )
215
211
{
216
- if (isset ($ options ['keyVaultClient ' ])) {
217
- if ($ options ['keyVaultClient ' ] instanceof self) {
218
- $ options ['keyVaultClient ' ] = $ options ['keyVaultClient ' ]->manager ;
219
- } elseif (! $ options ['keyVaultClient ' ] instanceof Manager) {
220
- throw InvalidArgumentException::invalidType ('"keyVaultClient" option ' , $ options ['keyVaultClient ' ], [self ::class, Manager::class]);
221
- }
222
- }
212
+ $ options = $ this ->prepareEncryptionOptions ($ options );
223
213
224
214
return $ this ->manager ->createClientEncryption ($ options );
225
215
}
@@ -499,4 +489,26 @@ private function mergeDriverInfo(array $driver): array
499
489
500
490
return $ mergedDriver ;
501
491
}
492
+
493
+ private function prepareEncryptionOptions (array $ options ): array
494
+ {
495
+ if (isset ($ options ['keyVaultClient ' ])) {
496
+ if ($ options ['keyVaultClient ' ] instanceof self) {
497
+ $ options ['keyVaultClient ' ] = $ options ['keyVaultClient ' ]->manager ;
498
+ } elseif (! $ options ['keyVaultClient ' ] instanceof Manager) {
499
+ throw InvalidArgumentException::invalidType ('"keyVaultClient" option ' , $ options ['keyVaultClient ' ], [self ::class, Manager::class]);
500
+ }
501
+ }
502
+
503
+ // The server requires an empty document for automatic credentials.
504
+ if (isset ($ options ['kmsProviders ' ]) && is_array ($ options ['kmsProviders ' ])) {
505
+ foreach ($ options ['kmsProviders ' ] as $ name => $ provider ) {
506
+ if ($ provider === []) {
507
+ $ options ['kmsProviders ' ][$ name ] = new stdClass ();
508
+ }
509
+ }
510
+ }
511
+
512
+ return $ options ;
513
+ }
502
514
}
0 commit comments