Skip to content

Commit ef19927

Browse files
committed
Merge branch '4.2.x' into 5.0.x
* 4.2.x: Implement an EnumType for MySQL/MariaDB (#6536) Leverage the new PDO subclasses (#6532) PHPStan 1.12.6 (#6535)
2 parents f041d52 + 9744af4 commit ef19927

File tree

23 files changed

+410
-19
lines changed

23 files changed

+410
-19
lines changed

UPGRADE.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ all drivers and middleware.
2121

2222
# Upgrade to 4.2
2323

24+
## Support for new PDO subclasses on PHP 8.4
25+
26+
On PHP 8.4, if you call `getNativeConnection()` on a connection established through one of the PDO drivers,
27+
you will get an instance of the new PDO subclasses, e.g. `Pdo\Mysql` or `Pdo\Ppgsql` instead of just `PDO`.
28+
29+
However, this currently does not apply to persistent connections.
30+
See https://github.com/php/php-src/issues/16314 for details.
31+
2432
## Minor BC break: incompatible query cache format
2533

2634
The query cache format has been changed to address the issue where a cached result with no rows would miss the metadata.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"doctrine/coding-standard": "12.0.0",
4141
"fig/log-test": "^1",
4242
"jetbrains/phpstorm-stubs": "2023.2",
43-
"phpstan/phpstan": "1.12.0",
43+
"phpstan/phpstan": "1.12.6",
4444
"phpstan/phpstan-phpunit": "1.4.0",
4545
"phpstan/phpstan-strict-rules": "^1.6",
4646
"phpunit/phpunit": "10.5.30",

docs/en/reference/types.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ type natively, this type is mapped to the ``string`` type internally.
196196
Values retrieved from the database are always converted to PHP's ``string`` type
197197
or ``null`` if no data is present.
198198

199+
enum
200+
++++
201+
202+
Maps and converts a string which is one of a set of predefined values. This
203+
type is specifically designed for MySQL and MariaDB, where it is mapped to
204+
the native ``ENUM`` type. For other database vendors, this type is mapped to
205+
a string field (``VARCHAR``) with the maximum length being the length of the
206+
longest value in the set. Values retrieved from the database are always
207+
converted to PHP's ``string`` type or ``null`` if no data is present.
208+
199209
Binary string types
200210
^^^^^^^^^^^^^^^^^^^
201211

phpstan.neon.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ parameters:
111111
-
112112
message: '#^Parameter \#2 \$callback of function array_reduce expects callable\(\(callable&TIn\)\|Closure\(mixed \$value\)\: mixed\|null, callable\(T\)\: T\)\: \(\(callable&TIn\)\|Closure\(mixed \$value\)\: mixed\|null\), Closure\(callable\|null, callable\)\: \(callable\(T\)\: T\) given\.$#'
113113
path: src/Portability/Converter.php
114+
115+
# PHPStan does not know the new PDO classes yet.
116+
- '~^Class Pdo\\\w+ not found\.$~'
117+
- '~^Call to an undefined static method PDO\:\:connect\(\)\.$~'
114118
includes:
115119
- vendor/phpstan/phpstan-phpunit/extension.neon
116120
- vendor/phpstan/phpstan-phpunit/rules.neon

psalm.xml.dist

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,14 @@
281281
<file name="src/Driver/PgSQL/Statement.php"/>
282282
</errorLevel>
283283
</TypeDoesNotContainType>
284+
<UndefinedClass>
285+
<errorLevel type="suppress">
286+
<!-- New PDO classes introduced in PHP 8.4 -->
287+
<referencedClass name="Pdo\Mysql"/>
288+
<referencedClass name="Pdo\Pgsql"/>
289+
<referencedClass name="Pdo\Sqlite"/>
290+
</errorLevel>
291+
</UndefinedClass>
284292
<UndefinedDocblockClass>
285293
<errorLevel type="suppress">
286294
<!-- See https://github.com/vimeo/psalm/issues/5472 -->
@@ -292,6 +300,12 @@
292300
<referencedClass name="OCILob"/>
293301
</errorLevel>
294302
</UndefinedDocblockClass>
303+
<UndefinedMethod>
304+
<errorLevel type="suppress">
305+
<!-- New PDO static constructor introduced in PHP 8.4 -->
306+
<referencedMethod name="PDO::connect"/>
307+
</errorLevel>
308+
</UndefinedMethod>
295309
<UnsupportedPropertyReferenceUsage>
296310
<errorLevel type="suppress">
297311
<!-- This code is valid -->

src/Driver/PDO/MySQL/Driver.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\DBAL\Driver\PDO\Connection;
99
use Doctrine\DBAL\Driver\PDO\Exception;
1010
use Doctrine\DBAL\Driver\PDO\Exception\InvalidConfiguration;
11+
use Doctrine\DBAL\Driver\PDO\PDOConnect;
1112
use PDO;
1213
use PDOException;
1314
use SensitiveParameter;
@@ -16,6 +17,8 @@
1617

1718
final class Driver extends AbstractMySQLDriver
1819
{
20+
use PDOConnect;
21+
1922
/**
2023
* {@inheritDoc}
2124
*/
@@ -39,7 +42,7 @@ public function connect(
3942
unset($safeParams['password']);
4043

4144
try {
42-
$pdo = new PDO(
45+
$pdo = $this->doConnect(
4346
$this->constructPdoDsn($safeParams),
4447
$params['user'] ?? '',
4548
$params['password'] ?? '',

src/Driver/PDO/OCI/Driver.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\DBAL\Driver\PDO\Connection;
99
use Doctrine\DBAL\Driver\PDO\Exception;
1010
use Doctrine\DBAL\Driver\PDO\Exception\InvalidConfiguration;
11+
use Doctrine\DBAL\Driver\PDO\PDOConnect;
1112
use PDO;
1213
use PDOException;
1314
use SensitiveParameter;
@@ -16,6 +17,8 @@
1617

1718
final class Driver extends AbstractOracleDriver
1819
{
20+
use PDOConnect;
21+
1922
/**
2023
* {@inheritDoc}
2124
*/
@@ -39,7 +42,7 @@ public function connect(
3942
unset($safeParams['password']);
4043

4144
try {
42-
$pdo = new PDO(
45+
$pdo = $this->doConnect(
4346
$this->constructPdoDsn($params),
4447
$params['user'] ?? '',
4548
$params['password'] ?? '',

src/Driver/PDO/PDOConnect.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\DBAL\Driver\PDO;
6+
7+
use PDO;
8+
9+
use const PHP_VERSION_ID;
10+
11+
/** @internal */
12+
trait PDOConnect
13+
{
14+
/** @param array<int, mixed> $options */
15+
private function doConnect(
16+
string $dsn,
17+
string $username,
18+
string $password,
19+
array $options,
20+
): PDO {
21+
// see https://github.com/php/php-src/issues/16314
22+
if (PHP_VERSION_ID < 80400 || ($options[PDO::ATTR_PERSISTENT] ?? false) === true) {
23+
return new PDO($dsn, $username, $password, $options);
24+
}
25+
26+
return PDO::connect($dsn, $username, $password, $options);
27+
}
28+
}

src/Driver/PDO/PgSQL/Driver.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\DBAL\Driver\PDO\Connection;
99
use Doctrine\DBAL\Driver\PDO\Exception;
1010
use Doctrine\DBAL\Driver\PDO\Exception\InvalidConfiguration;
11+
use Doctrine\DBAL\Driver\PDO\PDOConnect;
1112
use PDO;
1213
use PDOException;
1314
use SensitiveParameter;
@@ -16,6 +17,8 @@
1617

1718
final class Driver extends AbstractPostgreSQLDriver
1819
{
20+
use PDOConnect;
21+
1922
/**
2023
* {@inheritDoc}
2124
*/
@@ -39,7 +42,7 @@ public function connect(
3942
unset($safeParams['password']);
4043

4144
try {
42-
$pdo = new PDO(
45+
$pdo = $this->doConnect(
4346
$this->constructPdoDsn($safeParams),
4447
$params['user'] ?? '',
4548
$params['password'] ?? '',

src/Driver/PDO/SQLSrv/Driver.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Doctrine\DBAL\Driver\PDO\Connection as PDOConnection;
1111
use Doctrine\DBAL\Driver\PDO\Exception as PDOException;
1212
use Doctrine\DBAL\Driver\PDO\Exception\InvalidConfiguration;
13+
use Doctrine\DBAL\Driver\PDO\PDOConnect;
1314
use PDO;
1415
use SensitiveParameter;
1516

@@ -19,6 +20,8 @@
1920

2021
final class Driver extends AbstractSQLServerDriver
2122
{
23+
use PDOConnect;
24+
2225
/**
2326
* {@inheritDoc}
2427
*/
@@ -52,7 +55,7 @@ public function connect(
5255
unset($safeParams['password']);
5356

5457
try {
55-
$pdo = new PDO(
58+
$pdo = $this->doConnect(
5659
$this->constructDsn($safeParams, $dsnOptions),
5760
$params['user'] ?? '',
5861
$params['password'] ?? '',

0 commit comments

Comments
 (0)