@@ -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 ->formatEncryptionOptions ($ 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 ->formatEncryptionOptions ($ options );
223
213
224
214
return $ this ->manager ->createClientEncryption ($ options );
225
215
}
@@ -457,6 +447,28 @@ public function watch(array $pipeline = [], array $options = [])
457
447
return $ operation ->execute ($ server );
458
448
}
459
449
450
+ private function formatEncryptionOptions (array $ options ): array
451
+ {
452
+ if (isset ($ options ['keyVaultClient ' ])) {
453
+ if ($ options ['keyVaultClient ' ] instanceof self) {
454
+ $ options ['keyVaultClient ' ] = $ options ['keyVaultClient ' ]->manager ;
455
+ } elseif (! $ options ['keyVaultClient ' ] instanceof Manager) {
456
+ throw InvalidArgumentException::invalidType ('"keyVaultClient" option ' , $ options ['keyVaultClient ' ], [self ::class, Manager::class]);
457
+ }
458
+ }
459
+
460
+ // The server requires an empty document for automatic credentials.
461
+ if (isset ($ options ['kmsProviders ' ]) && is_array ($ options ['kmsProviders ' ])) {
462
+ foreach ($ options ['kmsProviders ' ] as $ name => $ provider ) {
463
+ if ($ provider === []) {
464
+ $ options ['kmsProviders ' ][$ name ] = Document::fromPHP ([]);
465
+ }
466
+ }
467
+ }
468
+
469
+ return $ options ;
470
+ }
471
+
460
472
private static function getVersion (): string
461
473
{
462
474
if (self ::$ version === null ) {
0 commit comments