Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 990a91c

Browse files
committed
Fix DBAL 4 compatibility
1 parent 53e5e19 commit 990a91c

21 files changed

+471
-215
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':
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 & 2 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,29 @@ protected function handleForManager(EntityManagerInterface $entityManager, Envel
3334
return $stack->next()->handle($envelope, $stack);
3435
}
3536

37+
/** @return void */
3638
private function pingConnection(EntityManagerInterface $entityManager)
3739
{
3840
$connection = $entityManager->getConnection();
3941

4042
try {
41-
$connection->executeQuery($connection->getDatabasePlatform()->getDummySelectSQL());
43+
$this->executeDummySql($connection);
4244
} catch (DBALException $e) {
4345
$connection->close();
44-
$connection->connect();
46+
// Attempt to reestablish the lazy connection by sending another query.
47+
$this->executeDummySql($connection);
4548
}
4649

4750
if (!$entityManager->isOpen()) {
4851
$this->managerRegistry->resetManager($this->entityManagerName);
4952
}
5053
}
54+
55+
/**
56+
* @throws DBALException
57+
*/
58+
private function executeDummySql(Connection $connection): void
59+
{
60+
$connection->executeQuery($connection->getDatabasePlatform()->getDummySelectSQL());
61+
}
5162
}

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 <[email protected]>
21+
* @author Alexander M. Turek <[email protected]>
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)