@@ -119,12 +119,8 @@ public function __construct(?string $uri = null, array $uriOptions = [], array $
119119 throw InvalidArgumentException::invalidType ('"typeMap" driver option ' , $ driverOptions ['typeMap ' ], 'array ' );
120120 }
121121
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 ' ]);
128124 }
129125
130126 if (isset ($ driverOptions ['builderEncoder ' ]) && ! $ driverOptions ['builderEncoder ' ] instanceof Encoder) {
@@ -233,13 +229,7 @@ public function bulkWrite(BulkWriteCommand|ClientBulkWrite $bulk, array $options
233229 */
234230 public function createClientEncryption (array $ options ): ClientEncryption
235231 {
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 );
243233
244234 return $ this ->manager ->createClientEncryption ($ options );
245235 }
@@ -501,4 +491,26 @@ private function mergeDriverInfo(array $driver): array
501491
502492 return $ mergedDriver ;
503493 }
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+ }
504516}
0 commit comments