Add array-shape types for URI and driver options, including autoEncryption as a separate type

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • PHP Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Context

      The URI options and driver options of the PHP library are typed with loose @param array docblocks in Client::__construct(), DriverOptions::fromArray(), and AutoEncryptionOptions::fromArray(). The only partial array shape today is on Client::createClientEncryption()

      array{kmsProviders?: ..., keyVaultClient?: ...}

      There is no reusable @phpstan-type or @psalm-type for autoEncryption, schemaMap, encryptedFieldsMap, or extraOptions.

      Goal

      Introduce type aliases (PHPStan and psalm) so the library and downstream integrations can import and statically validate these options. The aliases are annotation-only, hence backwards compatible.

      Types to add* URI options: readPreference, readConcern, writeConcern, retryWrites, and the other supported connection string options.

      • Driver options: name, version, platform, typeMap, builderEncoder, autoEncryption, driver.
      • autoEncryption, as a separate type: keyVaultNamespace, kmsProviders (local, aws, azure, gcp, kmip), schemaMap, encryptedFieldsMap, extraOptions (cryptSharedLibPath, cryptSharedLibSearchPaths, ...), keyVaultClient.
      • encryptedFields, defined and required (not optional): fields with path, bsonType, keyId optional, and queries with queryType equality or range plus optional min, max, sparsity; escCollection; ecocCollection.

      Delivery

      • Add the @phpstan-type and @psalm-type aliases on the relevant classes (AutoEncryptionOptions, DriverOptions, Client) or in a shared location.
      • Wire them into the existing docblocks: AutoEncryptionOptions::fromArray(), Client::createClientEncryption(), DriverOptions::fromArray().
      • Keep the runtime behavior unchanged (annotations only).

      Motivation

      Required by the mongodb/laravel-mongodb Queryable Encryption work (PHPLARA-50, WRITING-32185) to statically type config('database.connections.mongodb.driver_options.autoEncryption'). PHPLIB currently exports no reusable type for these options.

      Definition of done

      • Psalm and PHPStan pass with the new aliases in place.
      • Downstream consumers can @phpstan-import-type and @psalm-import-type the autoEncryption and encryptedFields types.

            Assignee:
            Unassigned
            Reporter:
            Jérôme Tamarelle
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: