@@ -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 ->formatEncryptionOptions ($ driverOptions ['autoEncryption ' ]);
128124 }
129125
130126 if (isset ($ driverOptions ['builderEncoder ' ]) && ! $ driverOptions ['builderEncoder ' ] instanceof Encoder) {
@@ -213,13 +209,7 @@ final public function addSubscriber(Subscriber $subscriber): void
213209 */
214210 public function createClientEncryption (array $ options )
215211 {
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 );
223213
224214 return $ this ->manager ->createClientEncryption ($ options );
225215 }
@@ -457,6 +447,28 @@ public function watch(array $pipeline = [], array $options = [])
457447 return $ operation ->execute ($ server );
458448 }
459449
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+
460472 private static function getVersion (): string
461473 {
462474 if (self ::$ version === null ) {
0 commit comments