Fix(Database): Ensure read/write settings correctly inherit shared config #18744
+38
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Changes
Currently, in the
Database\Connection::createDrivers()
method, if a configuration array is provided for theread
orwrite
roles, it does not correctly inherit the values from the shared (default) configuration.For instance, if a user only specifies the
port
for theread
connection, other essential parameters likehost
,username
, anddatabase
are not carried over from the shared config. This leads to a connection failure, contrary to the behavior described in the documentation.This issue stems from PHP's operator precedence, where the array union operator (
+
) is evaluated before the null coalescing operator (??
).Proposed Changes
This PR corrects this behavior by adding parentheses to the configuration merging logic.
The line is changed from:
$readConfig = $config['read'] ?? [] + $sharedConfig;
To:
$readConfig = ($config['read'] ?? []) + $sharedConfig;
This small but critical change ensures that the
read
orwrite
specific configuration is resolved first, and then the shared configuration is correctly applied as a fallback for any keys that were not specified.With this fix, users can define only the parameters they wish to override in the
read
andwrite
configurations, making the feature work as intended and documented.