@@ -118,12 +118,8 @@ public function __construct(?string $uri = null, array $uriOptions = [], array $
118118 throw InvalidArgumentException::invalidType ('"typeMap" driver option ' , $ driverOptions ['typeMap ' ], 'array ' );
119119 }
120120
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 ' ]);
127123 }
128124
129125 if (isset ($ driverOptions ['builderEncoder ' ]) && ! $ driverOptions ['builderEncoder ' ] instanceof Encoder) {
@@ -232,13 +228,7 @@ public function bulkWrite(BulkWriteCommand|ClientBulkWrite $bulk, array $options
232228 */
233229 public function createClientEncryption (array $ options ): ClientEncryption
234230 {
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 );
242232
243233 return $ this ->manager ->createClientEncryption ($ options );
244234 }
@@ -500,4 +490,26 @@ private function mergeDriverInfo(array $driver): array
500490
501491 return $ mergedDriver ;
502492 }
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+ }
503515}
0 commit comments