Skip to content

Commit

Permalink
Merge branch '3.4.x' into 4.0.x
Browse files Browse the repository at this point in the history
* 3.4.x:
  Add native property types
  Use the null-coalescing assignment operator
  Deprecate Driver::getSchemaManager() in favor of AbstractPlatform::createSchemaManager()
  Drop support for PHP 7.3
  • Loading branch information
derrabus committed Jun 21, 2022
2 parents 78412fe + b5b9caf commit eeb5018
Show file tree
Hide file tree
Showing 70 changed files with 218 additions and 157 deletions.
10 changes: 0 additions & 10 deletions .github/workflows/continuous-integration.yml
Expand Up @@ -326,16 +326,6 @@ jobs:
config-file-suffix:
- ""
include:
- php-version: "8.0"
mysql-version: "8.0"
extension: "mysqli"
custom-entrypoint: >-
--entrypoint sh mysql:8 -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password"
- php-version: "8.0"
mysql-version: "8.0"
extension: "pdo_mysql"
custom-entrypoint: >-
--entrypoint sh mysql:8 -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password"
- mysql-version: "5.7"
- mysql-version: "8.0"
# https://stackoverflow.com/questions/60902904/how-to-pass-mysql-native-password-to-mysql-service-in-github-actions
Expand Down
4 changes: 4 additions & 0 deletions UPGRADE.md
Expand Up @@ -743,6 +743,10 @@ The following methods have been removed.

# Upgrade to 3.4

## Deprecated `Driver::getSchemaManager()`.

The `Driver::getSchemaManager()` method has been deprecated. Use `AbstractPlatform::createSchemaManager()` instead.

## Deprecated `ConsolerRunner`.

The `ConsoleRunner` class has been deprecated. Use Symfony Console documentation
Expand Down
12 changes: 11 additions & 1 deletion psalm.xml.dist
Expand Up @@ -39,6 +39,10 @@
See https://github.com/doctrine/dbal/pull/4317
-->
<file name="tests/Functional/LegacyAPITest.php"/>
<!--
TODO: remove in 4.0.0
-->
<referencedMethod name="Doctrine\DBAL\Driver::getSchemaManager"/>
</errorLevel>
</DeprecatedMethod>
<DocblockTypeContradiction>
Expand Down Expand Up @@ -170,6 +174,12 @@
<file name="tests/Functional/Driver/AbstractDriverTest.php"/>
</errorLevel>
</RedundantConditionGivenDocblockType>
<RedundantPropertyInitializationCheck>
<errorLevel type="suppress">
<!-- Running isset() checks on properties that should be initialized by setUp() is fine. -->
<directory name="tests"/>
</errorLevel>
</RedundantPropertyInitializationCheck>
<TypeDoesNotContainNull>
<errorLevel type="suppress">
<!-- See https://github.com/psalm/psalm-plugin-phpunit/issues/107 -->
Expand All @@ -181,7 +191,7 @@
<!-- See https://github.com/vimeo/psalm/issues/5472 -->
<referencedClass name="Doctrine\DBAL\Portability\T"/>
<!--
The OCI-Lob class was renamed to OCILob in PHP 8 while Psalm infers PHP 7.3 from composer.json
The OCI-Lob class was renamed to OCILob in PHP 8 while Psalm infers PHP 7 from composer.json
and may not properly interpret the LanguageLevelTypeAware annotation from the stubs.
-->
<referencedClass name="OCILob"/>
Expand Down
3 changes: 1 addition & 2 deletions src/Cache/ArrayResult.php
Expand Up @@ -20,8 +20,7 @@ final class ArrayResult implements Result
private array $data;

private int $columnCount = 0;

private int $num = 0;
private int $num = 0;

/**
* @param list<array<string, mixed>> $data
Expand Down
32 changes: 8 additions & 24 deletions src/Connection.php
Expand Up @@ -112,8 +112,7 @@ class Connection implements ServerVersionProvider
private ?AbstractPlatform $platform = null;

private ?ExceptionConverter $exceptionConverter = null;

private ?Parser $parser = null;
private ?Parser $parser = null;

/**
* The used DBAL driver.
Expand Down Expand Up @@ -149,13 +148,8 @@ public function __construct(
$this->params = $params;

// Create default config and event manager if none given
if ($config === null) {
$config = new Configuration();
}

if ($eventManager === null) {
$eventManager = new EventManager();
}
$config ??= new Configuration();
$eventManager ??= new EventManager();

$this->_config = $config;
$this->_eventManager = $eventManager;
Expand Down Expand Up @@ -535,11 +529,7 @@ public function setTransactionIsolation(int $level): void
*/
public function getTransactionIsolation(): int
{
if ($this->transactionIsolationLevel === null) {
$this->transactionIsolationLevel = $this->getDatabasePlatform()->getDefaultTransactionIsolationLevel();
}

return $this->transactionIsolationLevel;
return $this->transactionIsolationLevel ??= $this->getDatabasePlatform()->getDefaultTransactionIsolationLevel();
}

/**
Expand Down Expand Up @@ -1447,11 +1437,8 @@ final public function convertException(Driver\Exception $e): DriverException
*/
private function expandArrayParameters(string $sql, array $params, array $types): array
{
if ($this->parser === null) {
$this->parser = $this->getDatabasePlatform()->createSQLParser();
}

$visitor = new ExpandArrayParameters($params, $types);
$this->parser ??= $this->getDatabasePlatform()->createSQLParser();
$visitor = new ExpandArrayParameters($params, $types);

$this->parser->parse($sql, $visitor);

Expand Down Expand Up @@ -1489,11 +1476,8 @@ private function handleDriverException(
Driver\Exception $driverException,
?Query $query
): DriverException {
if ($this->exceptionConverter === null) {
$this->exceptionConverter = $this->_driver->getExceptionConverter();
}

$exception = $this->exceptionConverter->convert($driverException, $query);
$this->exceptionConverter ??= $this->_driver->getExceptionConverter();
$exception = $this->exceptionConverter->convert($driverException, $query);

if ($exception instanceof ConnectionLost) {
$this->close();
Expand Down
2 changes: 2 additions & 0 deletions src/Driver.php
Expand Up @@ -38,6 +38,8 @@ public function getDatabasePlatform(ServerVersionProvider $versionProvider): Abs
/**
* Gets the SchemaManager that can be used to inspect and change the underlying
* database schema of the platform this driver connects to.
*
* @deprecated Use {@link AbstractPlatform::createSchemaManager()} instead.
*/
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager;

Expand Down
2 changes: 1 addition & 1 deletion src/Driver/API/PostgreSQL/ExceptionConverter.php
Expand Up @@ -81,7 +81,7 @@ public function convert(Exception $exception, ?Query $query): DriverException
return new ConnectionException($exception, $query);
}

// Prior to fixing https://bugs.php.net/bug.php?id=64705 (PHP 7.3.22 and PHP 7.4.10),
// Prior to fixing https://bugs.php.net/bug.php?id=64705 (PHP 7.4.10),
// in some cases (mainly connection errors) the PDO exception wouldn't provide a SQLSTATE via its code.
// We have to match against the SQLSTATE in the error message in these cases.
if ($exception->getCode() === 7 && str_contains($exception->getMessage(), 'SQLSTATE[08006]')) {
Expand Down
11 changes: 11 additions & 0 deletions src/Driver/AbstractDB2Driver.php
Expand Up @@ -11,6 +11,7 @@
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Schema\DB2SchemaManager;
use Doctrine\DBAL\ServerVersionProvider;
use Doctrine\Deprecations\Deprecation;

use function assert;

Expand All @@ -24,8 +25,18 @@ public function getDatabasePlatform(ServerVersionProvider $versionProvider): DB2
return new DB2Platform();
}

/**
* @deprecated Use {@link DB2Platform::createSchemaManager()} instead.
*/
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): DB2SchemaManager
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5458',
'AbstractDB2Driver::getSchemaManager() is deprecated.'
. ' Use DB2Platform::createSchemaManager() instead.'
);

assert($platform instanceof DB2Platform);

return new DB2SchemaManager($conn, $platform);
Expand Down
15 changes: 13 additions & 2 deletions src/Driver/AbstractMySQLDriver.php
Expand Up @@ -16,6 +16,7 @@
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\MySQLSchemaManager;
use Doctrine\DBAL\ServerVersionProvider;
use Doctrine\Deprecations\Deprecation;

use function assert;
use function preg_match;
Expand Down Expand Up @@ -73,15 +74,25 @@ private function getOracleMysqlVersionNumber(string $versionString): string
$minorVersion = $versionParts['minor'] ?? 0;
$patchVersion = $versionParts['patch'] ?? null;

if ($majorVersion === '5' && $minorVersion === '7' && $patchVersion === null) {
$patchVersion = '9';
if ($majorVersion === '5' && $minorVersion === '7') {
$patchVersion ??= '9';
}

return $majorVersion . '.' . $minorVersion . '.' . $patchVersion;
}

/**
* @deprecated Use {@link AbstractMySQLPlatform::createSchemaManager()} instead.
*/
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): MySQLSchemaManager
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5458',
'AbstractMySQLDriver::getSchemaManager() is deprecated.'
. ' Use MySQLPlatform::createSchemaManager() instead.'
);

assert($platform instanceof AbstractMySQLPlatform);

return new MySQLSchemaManager($conn, $platform);
Expand Down
11 changes: 11 additions & 0 deletions src/Driver/AbstractOracleDriver.php
Expand Up @@ -12,6 +12,7 @@
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Schema\OracleSchemaManager;
use Doctrine\DBAL\ServerVersionProvider;
use Doctrine\Deprecations\Deprecation;

use function assert;

Expand All @@ -25,8 +26,18 @@ public function getDatabasePlatform(ServerVersionProvider $versionProvider): Ora
return new OraclePlatform();
}

/**
* @deprecated Use {@link OraclePlatform::createSchemaManager()} instead.
*/
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): OracleSchemaManager
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5458',
'AbstractOracleDriver::getSchemaManager() is deprecated.'
. ' Use OraclePlatform::createSchemaManager() instead.'
);

assert($platform instanceof OraclePlatform);

return new OracleSchemaManager($conn, $platform);
Expand Down
11 changes: 11 additions & 0 deletions src/Driver/AbstractPostgreSQLDriver.php
Expand Up @@ -11,6 +11,7 @@
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\PostgreSQLSchemaManager;
use Doctrine\DBAL\ServerVersionProvider;
use Doctrine\Deprecations\Deprecation;

use function assert;

Expand All @@ -24,8 +25,18 @@ public function getDatabasePlatform(ServerVersionProvider $versionProvider): Pos
return new PostgreSQLPlatform();
}

/**
* @deprecated Use {@link PostgreSQLPlatform::createSchemaManager()} instead.
*/
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): PostgreSQLSchemaManager
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5458',
'AbstractPostgreSQLDriver::getSchemaManager() is deprecated.'
. ' Use PostgreSQLPlatform::createSchemaManager() instead.'
);

assert($platform instanceof PostgreSQLPlatform);

return new PostgreSQLSchemaManager($conn, $platform);
Expand Down
11 changes: 11 additions & 0 deletions src/Driver/AbstractSQLServerDriver.php
Expand Up @@ -11,6 +11,7 @@
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Schema\SQLServerSchemaManager;
use Doctrine\DBAL\ServerVersionProvider;
use Doctrine\Deprecations\Deprecation;

use function assert;

Expand All @@ -24,8 +25,18 @@ public function getDatabasePlatform(ServerVersionProvider $versionProvider): SQL
return new SQLServerPlatform();
}

/**
* @deprecated Use {@link SQLServerPlatform::createSchemaManager()} instead.
*/
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): SQLServerSchemaManager
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5458',
'AbstractSQLServerDriver::getSchemaManager() is deprecated.'
. ' Use SQLServerPlatform::createSchemaManager() instead.'
);

assert($platform instanceof SQLServerPlatform);

return new SQLServerSchemaManager($conn, $platform);
Expand Down
11 changes: 11 additions & 0 deletions src/Driver/AbstractSQLiteDriver.php
Expand Up @@ -11,6 +11,7 @@
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Schema\SqliteSchemaManager;
use Doctrine\DBAL\ServerVersionProvider;
use Doctrine\Deprecations\Deprecation;

use function assert;

Expand All @@ -24,8 +25,18 @@ public function getDatabasePlatform(ServerVersionProvider $versionProvider): Sql
return new SqlitePlatform();
}

/**
* @deprecated Use {@link SqlitePlatform::createSchemaManager()} instead.
*/
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): SqliteSchemaManager
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5458',
'AbstractSQLiteDriver::getSchemaManager() is deprecated.'
. ' Use SqlitePlatform::createSchemaManager() instead.'
);

assert($platform instanceof SqlitePlatform);

return new SqliteSchemaManager($conn, $platform);
Expand Down
11 changes: 11 additions & 0 deletions src/Driver/Middleware/AbstractDriverMiddleware.php
Expand Up @@ -11,6 +11,7 @@
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\ServerVersionProvider;
use Doctrine\Deprecations\Deprecation;

abstract class AbstractDriverMiddleware implements Driver
{
Expand All @@ -34,8 +35,18 @@ public function getDatabasePlatform(ServerVersionProvider $versionProvider): Abs
return $this->wrappedDriver->getDatabasePlatform($versionProvider);
}

/**
* @deprecated Use {@link AbstractPlatform::createSchemaManager()} instead.
*/
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5458',
'AbstractDriverMiddleware::getSchemaManager() is deprecated.'
. ' Use AbstractPlatform::createSchemaManager() instead.'
);

return $this->wrappedDriver->getSchemaManager($conn, $platform);
}

Expand Down
4 changes: 0 additions & 4 deletions src/Driver/Mysqli/Initializer/Secure.php
Expand Up @@ -10,13 +10,9 @@
final class Secure implements Initializer
{
private string $key;

private string $cert;

private string $ca;

private string $capath;

private string $cipher;

public function __construct(string $key, string $cert, string $ca, string $capath, string $cipher)
Expand Down
1 change: 0 additions & 1 deletion src/Driver/OCI8/Connection.php
Expand Up @@ -26,7 +26,6 @@ final class Connection implements ConnectionInterface
private $connection;

private Parser $parser;

private ExecutionMode $executionMode;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/OCI8/ConvertPositionalToNamedPlaceholders.php
Expand Up @@ -20,7 +20,7 @@
final class ConvertPositionalToNamedPlaceholders implements Visitor
{
/** @var list<string> */
private $buffer = [];
private array $buffer = [];

/** @var array<int,string> */
private array $parameterMap = [];
Expand Down
4 changes: 1 addition & 3 deletions src/Driver/PDO/Exception.php
Expand Up @@ -19,9 +19,7 @@ public static function new(PDOException $exception): self
if ($exception->errorInfo !== null) {
[$sqlState, $code] = $exception->errorInfo;

if ($code === null) {
$code = 0;
}
$code ??= 0;
} else {
$code = $exception->getCode();
$sqlState = null;
Expand Down

0 comments on commit eeb5018

Please sign in to comment.