Skip to content

Commit

Permalink
⬆️ Compatibility with doctrine/dbal 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Nek- committed Oct 14, 2022
1 parent aa121d5 commit 7810b3e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
- { php: '8.1', packages: 'aws/aws-sdk-php:^3.158', phpspec: 'spec/Gaufrette/Adapter/AwsS3Spec.php' }
- { php: '8.1', packages: 'google/apiclient:^2.12', phpspec: 'spec/Gaufrette/Adapter/GoogleCloudStorageSpec.php' }
- { php: '8.1', packages: 'doctrine/dbal:^2.3', phpspec: 'spec/Gaufrette/Adapter/DoctrineDbalSpec.php' }
- { php: '8.1', packages: 'doctrine/dbal:^3.4', phpspec: 'spec/Gaufrette/Adapter/DoctrineDbalSpec.php' }
- { php: '8.1', packages: 'league/flysystem:^1.0', phpspec: 'spec/Gaufrette/Adapter/FlysystemSpec.php' }
- { php: '8.1', packages: 'microsoft/azure-storage-blob:^1.0', phpspec: 'spec/Gaufrette/Adapter/AzureBlobStore' }
- { php: '8.1', packages: 'mongodb/mongodb:^1.1', phpspec: 'spec/Gaufrette/Adapter/GridFSSpec.php' }
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ docker.all-deps: docker.deps ## Install dependencies
docker/run-task php${PHP_VERSION} composer require --no-update \
aws/aws-sdk-php:^3.158 \
google/apiclient:^2.12 \
doctrine/dbal:^2.3 \
doctrine/dbal:^3.4 \
league/flysystem:^1.0 \
microsoft/azure-storage-blob:^1.0 \
phpseclib/phpseclib:^2.0 \
Expand Down Expand Up @@ -67,7 +67,7 @@ require-all-legacy: # kept for compatibility with the old CI config, to be remov
composer require --no-update \
aws/aws-sdk-php:^3.158 \
google/apiclient:^2.12 \
doctrine/dbal:^2.3 \
doctrine/dbal:^3.4 \
league/flysystem:^1.0 \
microsoft/azure-storage-blob:^1.0 \
phpseclib/phpseclib:^2.0 \
Expand Down
21 changes: 18 additions & 3 deletions src/Gaufrette/Adapter/DoctrineDbal.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ public function checksum($key)
*/
public function exists($key)
{
return (boolean) $this->connection->fetchColumn(
$method = 'fetchOne'; // dbal 3.x
if (!method_exists($this->connection, $method)) {
$method = 'fetchColumn'; // dbal 2.x
}

return (boolean) $this->connection->$method(
sprintf(
'SELECT COUNT(%s) FROM %s WHERE %s = :key',
$this->getQuotedColumn('key'),
Expand Down Expand Up @@ -153,7 +158,12 @@ public function isDirectory($key)

private function getColumnValue($key, $column)
{
$value = $this->connection->fetchColumn(
$method = 'fetchOne'; // dbal 3.x
if (!method_exists($this->connection, $method)) {
$method = 'fetchColumn'; // dbal 2.x
}

$value = $this->connection->$method(
sprintf(
'SELECT %s FROM %s WHERE %s = :key',
$this->getQuotedColumn($column),
Expand All @@ -173,7 +183,12 @@ public function listKeys($prefix = '')
{
$prefix = trim($prefix);

$keys = $this->connection->fetchAll(
$method = 'fetchAllAssociative'; // dbal 3.x
if (!method_exists($this->connection, 'fetchAllAssociative')) {
$method = 'fetchAll'; // dbal 2.x
}

$keys = $this->connection->$method(
sprintf(
'SELECT %s AS _key FROM %s WHERE %s LIKE :pattern',
$this->getQuotedColumn('key'),
Expand Down
9 changes: 8 additions & 1 deletion tests/Gaufrette/Functional/Adapter/DoctrineDbalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ protected function setUp(): void
$schema = $this->connection->getSchemaManager()->createSchema();

$table = $schema->createTable('gaufrette');
$table->addColumn('key', 'string', ['unique' => true]);
$column = $table->addColumn('key', 'string');
if (method_exists($column, 'setPlatformOption')) {
// dbal 3.4+
$column->setPlatformOption('unique', true);
} else {
// dbal 2.x
$column->setUnique(true);
}
$table->addColumn('content', 'blob');
$table->addColumn('mtime', 'integer');
$table->addColumn('checksum', 'string', ['length' => 32]);
Expand Down

0 comments on commit 7810b3e

Please sign in to comment.