Problem/Motivation

Database connection configuration is stored in arrays that are more or less taken as is from info in the $databases array in settings.php.

This makes the entire management of these connection options a bit sparsed around, and static analysis struggling.

Proposed resolution

Introduce a ConnectionParameters object where configuration is read from settings.php (or programmatically), then sealed off for the rest of the request. Adjust code so that as much of the logic as possible determines the object before instantation (i.e. end up with a value object).

  • Introduce ConnectionParametersInterface and an abstract base class implementation ConnectionParametersBase
  • Implement only SQLite in this issue (to demonstrate other drivers can work without), implement the rest drivers in follow ups
  • To support BC, db drivers that implement a ConnectionParameters class will start using the new logic, those that don't will get a closure wrapper implementation of ConnectionParametersBase that provides access to the options array
  • For the moment, allow read-only array access to the parameters in the new class - this can be deprecated once all drivers are converted
  • Deprecate Database::getConnectionInfoAsUrl() and Connection::createUrlFromConnectionOptions() as now the URL version of the parameters can be got from the object directly.
  • Ensure new classes are PHPStan level-10 compliant.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3533038

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mondrake created an issue. See original summary.

moshe weitzman’s picture

LGTM

mondrake’s picture

mondrake’s picture

Title: Introduce a ConnectionParameters object to store database connection parameters » Introduce a ConnectionParameters value object to store database connection parameters
mondrake’s picture

Issue summary: View changes
Status: Postponed » Needs review
smustgrave’s picture

Status: Needs review » Postponed

This is looking good from what I can tell. Postponing and jumping to the blocker.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

mondrake’s picture

Status: Postponed » Needs work

mondrake changed the visibility of the branch 3533038-introduce-a-connectionparameters to hidden.

mondrake’s picture

Status: Needs work » Needs review
needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

mondrake’s picture

Issue summary: View changes
mondrake’s picture

Assigned: Unassigned » mondrake
Issue summary: View changes

Working on tuning array access and cloning

mondrake’s picture

Assigned: mondrake » Unassigned
Issue summary: View changes
Status: Needs work » Needs review

Used PHP 8.5 clone with syntax, guarded the value objects from casual array access writes.