Skip to content

Commit f751629

Browse files
Deprecate mixing the url option with host, dbname and a few others
1 parent 759018e commit f751629

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

DependencyInjection/Configuration.php

+12-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use function array_intersect_key;
1616
use function array_keys;
17+
use function array_pop;
1718
use function assert;
1819
use function class_exists;
1920
use function constant;
@@ -245,12 +246,17 @@ private function configureDbalDriverNode(ArrayNodeDefinition $node): void
245246
$node
246247
->validate()
247248
->always(static function (array $values) {
248-
$deprecatedOptions = ['override_url' => true];
249-
$deprecatedValues = array_intersect_key($values, $deprecatedOptions);
249+
if (! isset($values['url'])) {
250+
return $values;
251+
}
252+
253+
$urlConflictingOptions = ['host' => true, 'port' => true, 'user' => true, 'password' => true, 'path' => true, 'dbname' => true, 'unix_socket' => true, 'memory' => true];
254+
$urlConflictingValues = array_keys(array_intersect_key($values, $urlConflictingOptions));
255+
256+
if ($urlConflictingValues) {
257+
$tail = count($urlConflictingValues) > 1 ? sprintf('or "%s" options', array_pop($urlConflictingValues)) : 'option';
250258

251-
if ($deprecatedValues) {
252-
$message = count($deprecatedValues) > 1 ? 'options are' : 'option is';
253-
@trigger_error(sprintf('The "doctrine.dbal.%s" %s deprecated since DoctrineBundle 2.4, use the "doctrine.dbal.url" option instead.', implode('", "doctrine.dbal.', array_keys($deprecatedValues)), $message), E_USER_DEPRECATED);
259+
@trigger_error(sprintf('Setting the "doctrine.dbal.%s" %s while the "url" one is defined is deprecated since DoctrineBundle 2.4.', implode('", "', $urlConflictingValues), $tail), E_USER_DEPRECATED);
254260
}
255261

256262
return $values;
@@ -263,7 +269,7 @@ private function configureDbalDriverNode(ArrayNodeDefinition $node): void
263269
->scalarNode('port')->info('Defaults to null at runtime.')->end()
264270
->scalarNode('user')->info('Defaults to "root" at runtime.')->end()
265271
->scalarNode('password')->info('Defaults to null at runtime.')->end()
266-
->booleanNode('override_url')->info('Allows overriding parts of the "url" parameter with dbname, host, port, user, and/or password parameters.')->end()
272+
->booleanNode('override_url')->setDeprecated(...$this->getDeprecationMsg('The "doctrine.dbal.override_url" configuration key is deprecated.', '2.4'))->end()
267273
->scalarNode('dbname_suffix')->end()
268274
->scalarNode('application_name')->end()
269275
->scalarNode('charset')->end()

UPGRADE-2.4.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ UPGRADE FROM 2.3 to 2.4
44
Configuration
55
--------
66

7+
* Setting the `host`, `port`, `user`, `password`, `path`, `dbname`, `unix_socket`
8+
or `memory` configuration options while the `url` one is set has been deprecated.
79
* The `override_url` configuration option has been deprecated.
810
* Combined use of simplified connection configuration in DBAL (without `connections` key)
911
and multiple connection configuration is disallowed now. If you experience this issue, instead of

0 commit comments

Comments
 (0)