Skip to content

Commit

Permalink
Allow DBAL 4.0.x and make composer bootstrap passing
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Feb 3, 2024
1 parent e7156aa commit 57fcde6
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 15 deletions.
5 changes: 4 additions & 1 deletion bootstrap-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

// force Doctrine\DBAL\Platforms\SQLitePlatform class load as in DBAL 3.x it is named with a different case
// remove once DBAL 3.x support is dropped
new SqlitePlatform();
try {
new SqlitePlatform();
} catch (\Error $e) {
}

DbalTypes\Type::addType(Types::LOCAL_OBJECT, LocalObjectType::class);
DbalTypes\Type::addType(Types::MONEY, MoneyType::class);
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
"require": {
"php": ">=7.4 <8.4",
"atk4/core": "dev-develop",
"doctrine/dbal": "~3.5.1 || ~3.6.0",
"doctrine/dbal": "~3.5.1 || ~3.6.0 || ~4.0.0",
"mvorisek/atk4-hintable": "~1.9.0"
},
"require-release": {
"php": ">=7.4 <8.4",
"atk4/core": "~5.1.0",
"doctrine/dbal": "~3.5.1 || ~3.6.0",
"doctrine/dbal": "~3.5.1 || ~3.6.0 || ~4.0.0",
"mvorisek/atk4-hintable": "~1.9.0"
},
"require-dev": {
Expand Down
10 changes: 5 additions & 5 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ parameters:
path: '*'
count: 3

# FC for DBAL 4.0, remove once DBAL 3.x support is dropped
-
message: '~^Class Doctrine\\DBAL\\Platforms\\SqlitePlatform referenced with incorrect case: Doctrine\\DBAL\\Platforms\\SQLitePlatform\.$~'
path: '*'
count: 25
# remove once DBAL 3.x support is dropped
-
message: '~^(Class Doctrine\\DBAL\\Platforms\\SQLitePlatform referenced with incorrect case: Doctrine\\DBAL\\Platforms\\SqlitePlatform\.|Dead catch - Error is never thrown in the try block\.)$~'
path: 'bootstrap-types.php'
count: 3

# TODO these rules are generated, this ignores should be fixed in the code
# for src/Schema/TestCase.php
Expand Down
4 changes: 3 additions & 1 deletion src/Persistence/GenericPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ private function createNotSupportedException(): \Exception
return DbalException::notSupported('SQL');
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function getName(): string
{
return 'atk4_data_generic';
Expand Down
5 changes: 5 additions & 0 deletions src/Persistence/Sql/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public function getConnection(): DbalConnection
return $this->_connection;
}

final public static function isDbal3x(): bool
{
return (new \ReflectionClass(AbstractPlatform::class))->hasMethod('getName');
}

/**
* Normalize DSN connection string or DBAL connection params described in:
* https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html .
Expand Down
8 changes: 6 additions & 2 deletions src/Type/LocalObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ protected function init(): void
$this->handlesIndex = [];
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function getName(): string
{
return Types::LOCAL_OBJECT;
Expand Down Expand Up @@ -112,7 +114,9 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?object
return $res;
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function requiresSQLCommentHint(AbstractPlatform $platform): bool
{
return true;
Expand Down
8 changes: 6 additions & 2 deletions src/Type/MoneyType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

class MoneyType extends DbalTypes\Type
{
#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function getName(): string
{
return Types::MONEY;
Expand Down Expand Up @@ -37,7 +39,9 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?float
return $this->convertToDatabaseValue($value, $platform);
}

#[\Override]
/**
* @deprecated remove once DBAL 3.x support is dropped
*/
public function requiresSQLCommentHint(AbstractPlatform $platform): bool
{
return true;
Expand Down
3 changes: 1 addition & 2 deletions tests/ReferenceSqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,8 @@ public function testReferenceWithObjectId(): void

$integerWrappedType = new class() extends DbalTypes\Type {
/**
* TODO: Remove once DBAL 3.x support is dropped.
* @deprecated remove once DBAL 3.x support is dropped
*/
#[\Override]
public function getName(): string
{
return self::class;
Expand Down

0 comments on commit 57fcde6

Please sign in to comment.