Skip to content

Commit 33b174b

Browse files
committed
Deprecate "service" connection parameter
1 parent 3cf87f0 commit 33b174b

File tree

4 files changed

+70
-4
lines changed

4 files changed

+70
-4
lines changed

UPGRADE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ awareness about deprecated code.
66
- Use of our low-overhead runtime deprecation API, details:
77
https://github.com/doctrine/deprecations/
88

9+
# Upgrade to 4.4
10+
11+
## Deprecated `service` connection parameter for `oci8` and `pdo_oci` connections.
12+
13+
Using the `service` connection parameter to indicate that the value of the `dbname` parameter is the service name has
14+
been deprecated. Use the `servicename` parameter instead.
15+
916
# Upgrade to 4.3
1017

1118
## Deprecated support for MariaDB 10.5

docs/en/reference/configuration.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,11 @@ pdo_oci / oci8
303303
- ``dbname`` (string): Name of the database/schema to connect to.
304304
- ``servicename`` (string): Optional name by which clients can
305305
connect to the database instance. Will be used as Oracle's
306-
``SID`` connection parameter if given and defaults to Doctrine's
307-
``dbname`` connection parameter value.
306+
``SERVICE_NAME`` connection parameter if given.
308307
- ``service`` (boolean): Whether to use Oracle's ``SERVICE_NAME``
309308
connection parameter in favour of ``SID`` when connecting. The
310309
value for this will be read from Doctrine's ``servicename`` if
311-
given, ``dbname`` otherwise.
310+
given, ``dbname`` otherwise. Using this parameter is deprecated.
312311
- ``pooled`` (boolean): Whether to enable database resident
313312
connection pooling.
314313
- ``charset`` (string): The charset used when connecting to the

src/Driver/AbstractOracleDriver/EasyConnectString.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Doctrine\DBAL\Driver\AbstractOracleDriver;
66

7+
use Doctrine\Deprecations\Deprecation;
8+
79
use function implode;
810
use function is_array;
911
use function sprintf;
@@ -51,10 +53,19 @@ public static function fromConnectionParameters(array $params): self
5153

5254
$connectData = [];
5355

56+
if (isset($params['service'])) {
57+
Deprecation::trigger(
58+
'doctrine/dbal',
59+
'https://github.com/doctrine/dbal/pull/7042',
60+
'Using the "service" parameter to indicate that the value of the "dbname" parameter is the'
61+
. ' service name is deprecated. Use the "servicename" parameter instead.',
62+
);
63+
}
64+
5465
if (isset($params['servicename']) || isset($params['dbname'])) {
5566
$serviceKey = 'SID';
5667

57-
if (isset($params['service'])) {
68+
if (isset($params['service']) || isset($params['servicename'])) {
5869
$serviceKey = 'SERVICE_NAME';
5970
}
6071

tests/Driver/AbstractOracleDriver/EasyConnectStringTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
namespace Doctrine\DBAL\Tests\Driver\AbstractOracleDriver;
66

77
use Doctrine\DBAL\Driver\AbstractOracleDriver\EasyConnectString;
8+
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
89
use PHPUnit\Framework\Attributes\DataProvider;
910
use PHPUnit\Framework\TestCase;
1011

1112
class EasyConnectStringTest extends TestCase
1213
{
14+
use VerifyDeprecations;
15+
1316
/** @param mixed[] $params */
1417
#[DataProvider('connectionParametersProvider')]
1518
public function testFromConnectionParameters(array $params, string $expected): void
@@ -71,4 +74,50 @@ public static function connectionParametersProvider(): iterable
7174
],
7275
];
7376
}
77+
78+
/** @param array<string, mixed> $parameters */
79+
#[DataProvider('getConnectionParameters')]
80+
public function testParameterDeprecation(
81+
array $parameters,
82+
string $expectedConnectString,
83+
bool $expectDeprecation,
84+
): void {
85+
if ($expectDeprecation) {
86+
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/7042');
87+
} else {
88+
$this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/7042');
89+
}
90+
91+
$string = EasyConnectString::fromConnectionParameters($parameters);
92+
93+
self::assertSame($expectedConnectString, (string) $string);
94+
}
95+
96+
/** @return iterable<string, array{array<string, mixed>, string, bool}> */
97+
public static function getConnectionParameters(): iterable
98+
{
99+
$serviceNameString = '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))'
100+
. '(CONNECT_DATA=(SERVICE_NAME=BILLING)))';
101+
102+
yield 'dbname-and-service' => [
103+
[
104+
'host' => 'localhost',
105+
'port' => 1521,
106+
'dbname' => 'BILLING',
107+
'service' => true,
108+
],
109+
$serviceNameString,
110+
true,
111+
];
112+
113+
yield 'servicename' => [
114+
[
115+
'host' => 'localhost',
116+
'port' => 1521,
117+
'servicename' => 'BILLING',
118+
],
119+
$serviceNameString,
120+
false,
121+
];
122+
}
74123
}

0 commit comments

Comments
 (0)