Skip to content

Commit ac0adea

Browse files
authored
fix doctrine/dbal 3.x compatibility (#119)
1 parent 1eaebea commit ac0adea

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"require-dev": {
1010
"dibi/dibi": "~3.0 | ~4.0",
1111
"doctrine/cache": "~1.5",
12-
"doctrine/dbal": "~2.5",
12+
"doctrine/dbal": "~2.5 | ~3.0",
1313
"doctrine/orm": "~2.5",
1414
"mockery/mockery": "~0.9 | ~1.0",
1515
"nette/database": "~2.2",

src/Bridges/DoctrineDbal/DoctrineAdapter.php

+10-6
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,41 @@ public function __construct(Doctrine\DBAL\Connection $conn)
2828

2929
public function query($sql)
3030
{
31-
return $this->conn->fetchAll($sql);
31+
return method_exists($this->conn, 'fetchAllAssociative')
32+
? $this->conn->fetchAllAssociative($sql)
33+
: $this->conn->fetchAll($sql);
3234
}
3335

3436

3537
public function exec($sql)
3638
{
37-
return $this->conn->exec($sql);
39+
return method_exists($this->conn, 'executeStatement')
40+
? $this->conn->executeStatement($sql)
41+
: $this->conn->exec($sql);
3842
}
3943

4044

4145
public function escapeString($value)
4246
{
43-
return $this->conn->quote($value, Doctrine\DBAL\Types\Type::STRING);
47+
return $this->conn->quote($value, 'string');
4448
}
4549

4650

4751
public function escapeInt($value)
4852
{
49-
return $this->conn->quote($value, Doctrine\DBAL\Types\Type::INTEGER);
53+
return $this->conn->quote($value, 'integer');
5054
}
5155

5256

5357
public function escapeBool($value)
5458
{
55-
return $this->conn->quote($value, Doctrine\DBAL\Types\Type::BOOLEAN);
59+
return $this->conn->quote($value, 'boolean');
5660
}
5761

5862

5963
public function escapeDateTime(DateTime $value)
6064
{
61-
return $this->conn->quote($value, Doctrine\DBAL\Types\Type::DATETIME);
65+
return $this->conn->quote($value, 'datetime');
6266
}
6367

6468

tests/cases/integration/nette-di/MigrationsExtension.diffGenerator.configA.neon

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ migrations:
88
diffGenerator: doctrine
99

1010
services:
11-
- Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration([%doctrineDir%], true)
11+
- Doctrine\ORM\Tools\Setup::createXMLMetadataConfiguration([%doctrineDir%], true)
1212
- Doctrine\DBAL\DriverManager::getConnection(%doctrineConfig%, @Doctrine\ORM\Configuration)
1313
- Doctrine\ORM\EntityManager::create(@Doctrine\DBAL\Connection, @Doctrine\ORM\Configuration)

tests/cases/integration/nette-di/MigrationsExtension.diffGenerator.configB.neon

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ migrations:
77
driver: mysql
88

99
services:
10-
- Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration([%doctrineDir%], true)
10+
- Doctrine\ORM\Tools\Setup::createXMLMetadataConfiguration([%doctrineDir%], true)
1111
- Doctrine\DBAL\DriverManager::getConnection(%doctrineConfig%, @Doctrine\ORM\Configuration)
1212
- Doctrine\ORM\EntityManager::create(@Doctrine\DBAL\Connection, @Doctrine\ORM\Configuration)

tests/matrix/dbal/doctrine-3.0.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
PHP_VERSION_MIN="70300"
3+
PHP_VERSION_MAX="80099"
4+
COMPOSER_REQUIRE="$COMPOSER_REQUIRE doctrine/dbal:~3.0"
5+
COMPOSER_REQUIRE="$COMPOSER_REQUIRE nette/tester:~2.3"
6+
DBAL="doctrine"

0 commit comments

Comments
 (0)