@@ -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) {
@@ -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 ->prepareEncryptionOptions ($ options );
223213
224214 return $ this ->manager ->createClientEncryption ($ options );
225215 }
@@ -499,4 +489,26 @@ private function mergeDriverInfo(array $driver): array
499489
500490 return $ mergedDriver ;
501491 }
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+ }
502514}
0 commit comments