From 1fca1c180b27cb7864954dff84629bd9523e4546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Thu, 26 Aug 2021 15:34:05 +0200 Subject: [PATCH] Error out if incompatible DBAL version is detected (#38543) doctrine/dbal is an optional dependency of laravel/framework, and v3 of the DBAL has been released recently, but obviously, Laravel 6 was never meant to be compatible with that version. Users still using Laravel 6 and updating their dependencies get confused and file invalid reports on the DBAL, see for instance doctrine/dbal#4439 or doctrine/dbal#4757 Fixes laravel#24271 --- src/Illuminate/Database/MySqlConnection.php | 7 +++++++ src/Illuminate/Database/PostgresConnection.php | 7 +++++++ src/Illuminate/Database/SQLiteConnection.php | 7 +++++++ src/Illuminate/Database/SqlServerConnection.php | 7 +++++++ 4 files changed, 28 insertions(+) diff --git a/src/Illuminate/Database/MySqlConnection.php b/src/Illuminate/Database/MySqlConnection.php index 94b5b57d87e0..532b0f1facef 100755 --- a/src/Illuminate/Database/MySqlConnection.php +++ b/src/Illuminate/Database/MySqlConnection.php @@ -7,6 +7,7 @@ use Illuminate\Database\Query\Processors\MySqlProcessor; use Illuminate\Database\Schema\Grammars\MySqlGrammar as SchemaGrammar; use Illuminate\Database\Schema\MySqlBuilder; +use LogicException; class MySqlConnection extends Connection { @@ -61,6 +62,12 @@ protected function getDefaultPostProcessor() */ protected function getDoctrineDriver() { + if (! class_exists(DoctrineDriver::class)) { + throw new LogicException( + 'Laravel v6 is only compatible with doctrine/dbal 2, in order to use this feature you must require the package "doctrine/dbal:^2.6".' + ); + } + return new DoctrineDriver; } } diff --git a/src/Illuminate/Database/PostgresConnection.php b/src/Illuminate/Database/PostgresConnection.php index 5555df1a2e32..8d207b3ed3c8 100755 --- a/src/Illuminate/Database/PostgresConnection.php +++ b/src/Illuminate/Database/PostgresConnection.php @@ -7,6 +7,7 @@ use Illuminate\Database\Query\Processors\PostgresProcessor; use Illuminate\Database\Schema\Grammars\PostgresGrammar as SchemaGrammar; use Illuminate\Database\Schema\PostgresBuilder; +use LogicException; class PostgresConnection extends Connection { @@ -61,6 +62,12 @@ protected function getDefaultPostProcessor() */ protected function getDoctrineDriver() { + if (! class_exists(DoctrineDriver::class)) { + throw new LogicException( + 'Laravel v6 is only compatible with doctrine/dbal 2, in order to use this feature you must require the package "doctrine/dbal:^2.6".' + ); + } + return new DoctrineDriver; } } diff --git a/src/Illuminate/Database/SQLiteConnection.php b/src/Illuminate/Database/SQLiteConnection.php index 4990fdd299a1..a622df325829 100755 --- a/src/Illuminate/Database/SQLiteConnection.php +++ b/src/Illuminate/Database/SQLiteConnection.php @@ -7,6 +7,7 @@ use Illuminate\Database\Query\Processors\SQLiteProcessor; use Illuminate\Database\Schema\Grammars\SQLiteGrammar as SchemaGrammar; use Illuminate\Database\Schema\SQLiteBuilder; +use LogicException; class SQLiteConnection extends Connection { @@ -85,6 +86,12 @@ protected function getDefaultPostProcessor() */ protected function getDoctrineDriver() { + if (! class_exists(DoctrineDriver::class)) { + throw new LogicException( + 'Laravel v6 is only compatible with doctrine/dbal 2, in order to use this feature you must require the package "doctrine/dbal:^2.6".' + ); + } + return new DoctrineDriver; } diff --git a/src/Illuminate/Database/SqlServerConnection.php b/src/Illuminate/Database/SqlServerConnection.php index 8a642572104f..ab523576e75e 100755 --- a/src/Illuminate/Database/SqlServerConnection.php +++ b/src/Illuminate/Database/SqlServerConnection.php @@ -9,6 +9,7 @@ use Illuminate\Database\Query\Processors\SqlServerProcessor; use Illuminate\Database\Schema\Grammars\SqlServerGrammar as SchemaGrammar; use Illuminate\Database\Schema\SqlServerBuilder; +use LogicException; use Throwable; class SqlServerConnection extends Connection @@ -108,6 +109,12 @@ protected function getDefaultPostProcessor() */ protected function getDoctrineDriver() { + if (! class_exists(DoctrineDriver::class)) { + throw new LogicException( + 'Laravel v6 is only compatible with doctrine/dbal 2, in order to use this feature you must require the package "doctrine/dbal:^2.6".' + ); + } + return new DoctrineDriver; } }