Skip to content

Commit 54ec033

Browse files
committed
Require DBAL ^3.1 || ^4.4 and remove usage of methods that have been removed
1 parent 703cb34 commit 54ec033

2 files changed

Lines changed: 29 additions & 16 deletions

File tree

Storage/DoctrineStorage.php

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Doctrine\DBAL\Connection;
66
use Doctrine\DBAL\Schema\AbstractSchemaManager;
77
use Doctrine\DBAL\Schema\Column;
8+
use Doctrine\DBAL\Schema\PrimaryKeyConstraint;
89
use Doctrine\DBAL\Schema\Table;
910
use Doctrine\DBAL\Types\Type;
1011
use Doctrine\DBAL\Types\Types;
@@ -50,10 +51,19 @@ class DoctrineStorage implements StorageInterface {
5051
public function __construct(Connection $conn, StorageKeyGeneratorInterface $storageKeyGenerator) {
5152
$this->conn = $conn;
5253
$this->storageKeyGenerator = $storageKeyGenerator;
53-
// TODO just call `createSchemaManager()` as soon as DBAL >= 3.1 is required
54-
$this->schemaManager = \method_exists($this->conn, 'createSchemaManager') ? $this->conn->createSchemaManager() : $this->conn->getSchemaManager();
55-
$this->keyColumn = $this->conn->quoteIdentifier(self::KEY_COLUMN);
56-
$this->valueColumn = $this->conn->quoteIdentifier(self::VALUE_COLUMN);
54+
$this->schemaManager = $this->conn->createSchemaManager();
55+
56+
// BC for doctrine/dbal < 4
57+
/* @phpstan-ignore function.alreadyNarrowedType */
58+
if(method_exists($this->conn, 'quoteSingleIdentifier')) {
59+
$this->keyColumn = $this->conn->quoteSingleIdentifier(self::KEY_COLUMN);
60+
$this->valueColumn = $this->conn->quoteSingleIdentifier(self::VALUE_COLUMN);
61+
} else {
62+
/* @phpstan-ignore method.deprecated */
63+
$this->keyColumn = $this->conn->quoteIdentifier(self::KEY_COLUMN);
64+
/* @phpstan-ignore method.deprecated */
65+
$this->valueColumn = $this->conn->quoteIdentifier(self::VALUE_COLUMN);
66+
}
5767
}
5868

5969
/**
@@ -134,15 +144,7 @@ private function getRawValueForKey($key) {
134144
->setParameter('key', $this->generateKey($key))
135145
;
136146

137-
// TODO just call `executeQuery()` as soon as DBAL >= 2.13.1 is required
138-
$result = \method_exists($qb, 'executeQuery') ? $qb->executeQuery() : $qb->execute();
139-
140-
// TODO remove as soon as Doctrine DBAL >= 3.0 is required
141-
if (!\method_exists($result, 'fetchOne')) {
142-
return $result->fetchColumn();
143-
}
144-
145-
return $result->fetchOne();
147+
return $qb->executeQuery()->fetchOne();
146148
}
147149

148150
private function tableExists() {
@@ -155,12 +157,23 @@ private function createTable() {
155157
new Column($this->valueColumn, Type::getType(Types::TEXT)),
156158
]);
157159

158-
$table->setPrimaryKey([$this->keyColumn]);
160+
// BC for doctrine/dbal < 4
161+
/* @phpstan-ignore function.alreadyNarrowedType */
162+
if (method_exists($table, 'addPrimaryKeyConstraint')) {
163+
$table->addPrimaryKeyConstraint(
164+
PrimaryKeyConstraint::editor()
165+
->setUnquotedColumnNames($this->keyColumn)
166+
->create()
167+
);
168+
} else {
169+
/* @phpstan-ignore method.deprecated */
170+
$table->setPrimaryKey([$this->keyColumn]);
171+
}
172+
159173
$this->schemaManager->createTable($table);
160174
}
161175

162176
private function generateKey($key) {
163177
return $this->storageKeyGenerator->generate($key);
164178
}
165-
166179
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"craue/translations-tests": "^1.1",
3939
"doctrine/collections": "^1.8 || ^2.1",
4040
"doctrine/common": "^2.9 || ^3.0",
41-
"doctrine/dbal": "^2.10 || ^3.0",
41+
"doctrine/dbal": "^3.1 || ^4.4",
4242
"doctrine/doctrine-bundle": "^1.10 || ^2.0",
4343
"phpstan/extension-installer": "^1.1",
4444
"phpstan/phpstan": "^1.10",

0 commit comments

Comments
 (0)