Skip to content

Commit 50c0fbc

Browse files
committed
Fix DBAL 4 compatibility
1 parent 53e5e19 commit 50c0fbc

19 files changed

+466
-197
lines changed

src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function guessType(string $class, string $property)
5252
}
5353

5454
switch ($metadata->getTypeOfField($property)) {
55-
case Types::ARRAY:
55+
case 'array': // DBAL < 4
5656
case Types::SIMPLE_ARRAY:
5757
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\CollectionType', [], Guess::MEDIUM_CONFIDENCE);
5858
case Types::BOOLEAN:

src/Symfony/Bridge/Doctrine/Messenger/DoctrinePingConnectionMiddleware.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Messenger;
1313

14+
use Doctrine\DBAL\Connection;
1415
use Doctrine\DBAL\Exception as DBALException;
1516
use Doctrine\ORM\EntityManagerInterface;
1617
use Symfony\Component\Messenger\Envelope;
@@ -33,19 +34,28 @@ protected function handleForManager(EntityManagerInterface $entityManager, Envel
3334
return $stack->next()->handle($envelope, $stack);
3435
}
3536

36-
private function pingConnection(EntityManagerInterface $entityManager)
37+
private function pingConnection(EntityManagerInterface $entityManager): void
3738
{
3839
$connection = $entityManager->getConnection();
3940

4041
try {
41-
$connection->executeQuery($connection->getDatabasePlatform()->getDummySelectSQL());
42+
$this->executeDummySql($connection);
4243
} catch (DBALException $e) {
4344
$connection->close();
44-
$connection->connect();
45+
// Attempt to reestablish the lazy connection by sending another query.
46+
$this->executeDummySql($connection);
4547
}
4648

4749
if (!$entityManager->isOpen()) {
4850
$this->managerRegistry->resetManager($this->entityManagerName);
4951
}
5052
}
53+
54+
/**
55+
* @throws DBALException
56+
*/
57+
private function executeDummySql(Connection $connection): void
58+
{
59+
$connection->executeQuery($connection->getDatabasePlatform()->getDummySelectSQL());
60+
}
5161
}

src/Symfony/Bridge/Doctrine/Middleware/Debug/Connection.php

Lines changed: 37 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,26 @@
1414
use Doctrine\DBAL\Driver\Connection as ConnectionInterface;
1515
use Doctrine\DBAL\Driver\Middleware\AbstractConnectionMiddleware;
1616
use Doctrine\DBAL\Driver\Result;
17-
use Doctrine\DBAL\Driver\Statement as DriverStatement;
1817
use Symfony\Component\Stopwatch\Stopwatch;
1918

2019
/**
2120
* @author Laurent VOULLEMIER <laurent.voullemier@gmail.com>
21+
* @author Alexander M. Turek <me@derrabus.de>
2222
*
2323
* @internal
2424
*/
2525
final class Connection extends AbstractConnectionMiddleware
2626
{
27-
private $nestingLevel = 0;
28-
private $debugDataHolder;
29-
private $stopwatch;
30-
private $connectionName;
31-
32-
public function __construct(ConnectionInterface $connection, DebugDataHolder $debugDataHolder, ?Stopwatch $stopwatch, string $connectionName)
33-
{
27+
public function __construct(
28+
ConnectionInterface $connection,
29+
private DebugDataHolder $debugDataHolder,
30+
private ?Stopwatch $stopwatch,
31+
private string $connectionName,
32+
) {
3433
parent::__construct($connection);
35-
36-
$this->debugDataHolder = $debugDataHolder;
37-
$this->stopwatch = $stopwatch;
38-
$this->connectionName = $connectionName;
3934
}
4035

41-
public function prepare(string $sql): DriverStatement
36+
public function prepare(string $sql): Statement
4237
{
4338
return new Statement(
4439
parent::prepare($sql),
@@ -53,135 +48,79 @@ public function query(string $sql): Result
5348
{
5449
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query($sql));
5550

56-
if (null !== $this->stopwatch) {
57-
$this->stopwatch->start('doctrine', 'doctrine');
58-
}
59-
51+
$this->stopwatch?->start('doctrine', 'doctrine');
6052
$query->start();
6153

6254
try {
63-
$result = parent::query($sql);
55+
return parent::query($sql);
6456
} finally {
6557
$query->stop();
66-
67-
if (null !== $this->stopwatch) {
68-
$this->stopwatch->stop('doctrine');
69-
}
58+
$this->stopwatch?->stop('doctrine');
7059
}
71-
72-
return $result;
7360
}
7461

7562
public function exec(string $sql): int
7663
{
7764
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query($sql));
7865

79-
if (null !== $this->stopwatch) {
80-
$this->stopwatch->start('doctrine', 'doctrine');
81-
}
82-
66+
$this->stopwatch?->start('doctrine', 'doctrine');
8367
$query->start();
8468

8569
try {
8670
$affectedRows = parent::exec($sql);
8771
} finally {
8872
$query->stop();
89-
90-
if (null !== $this->stopwatch) {
91-
$this->stopwatch->stop('doctrine');
92-
}
73+
$this->stopwatch?->stop('doctrine');
9374
}
9475

9576
return $affectedRows;
9677
}
9778

98-
public function beginTransaction(): bool
79+
public function beginTransaction(): void
9980
{
100-
$query = null;
101-
if (1 === ++$this->nestingLevel) {
102-
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query('"START TRANSACTION"'));
103-
}
104-
105-
if (null !== $this->stopwatch) {
106-
$this->stopwatch->start('doctrine', 'doctrine');
107-
}
81+
$query = new Query('"START TRANSACTION"');
82+
$this->debugDataHolder->addQuery($this->connectionName, $query);
10883

109-
if (null !== $query) {
110-
$query->start();
111-
}
84+
$this->stopwatch?->start('doctrine', 'doctrine');
85+
$query->start();
11286

11387
try {
114-
$ret = parent::beginTransaction();
88+
parent::beginTransaction();
11589
} finally {
116-
if (null !== $query) {
117-
$query->stop();
118-
}
119-
120-
if (null !== $this->stopwatch) {
121-
$this->stopwatch->stop('doctrine');
122-
}
90+
$query->stop();
91+
$this->stopwatch?->stop('doctrine');
12392
}
124-
125-
return $ret;
12693
}
12794

128-
public function commit(): bool
95+
public function commit(): void
12996
{
130-
$query = null;
131-
if (1 === $this->nestingLevel--) {
132-
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query('"COMMIT"'));
133-
}
97+
$query = new Query('"COMMIT"');
98+
$this->debugDataHolder->addQuery($this->connectionName, $query);
13499

135-
if (null !== $this->stopwatch) {
136-
$this->stopwatch->start('doctrine', 'doctrine');
137-
}
138-
139-
if (null !== $query) {
140-
$query->start();
141-
}
100+
$this->stopwatch?->start('doctrine', 'doctrine');
101+
$query->start();
142102

143103
try {
144-
$ret = parent::commit();
104+
parent::commit();
145105
} finally {
146-
if (null !== $query) {
147-
$query->stop();
148-
}
149-
150-
if (null !== $this->stopwatch) {
151-
$this->stopwatch->stop('doctrine');
152-
}
106+
$query->stop();
107+
$this->stopwatch?->stop('doctrine');
153108
}
154-
155-
return $ret;
156109
}
157110

158-
public function rollBack(): bool
111+
public function rollBack(): void
159112
{
160-
$query = null;
161-
if (1 === $this->nestingLevel--) {
162-
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query('"ROLLBACK"'));
163-
}
164-
165-
if (null !== $this->stopwatch) {
166-
$this->stopwatch->start('doctrine', 'doctrine');
167-
}
113+
$query = new Query('"ROLLBACK"');
114+
$this->debugDataHolder->addQuery($this->connectionName, $query);
168115

169-
if (null !== $query) {
170-
$query->start();
171-
}
116+
$this->stopwatch?->start('doctrine', 'doctrine');
117+
$query->start();
172118

173119
try {
174-
$ret = parent::rollBack();
120+
parent::rollBack();
175121
} finally {
176-
if (null !== $query) {
177-
$query->stop();
178-
}
179-
180-
if (null !== $this->stopwatch) {
181-
$this->stopwatch->stop('doctrine');
182-
}
122+
$query->stop();
123+
$this->stopwatch?->stop('doctrine');
183124
}
184-
185-
return $ret;
186125
}
187126
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy