Skip to content

Commit f804b48

Browse files
Merge branch '6.3' into 6.4
* 6.3: Sync .github/expected-missing-return-types.diff [FrameworkBundle] Add void return-type to ErrorLoggerCompilerPass [DoctrineBridge] Fix cross-versions compat [HttpKernel] Handle nullable callback of StreamedResponse [Mailer] Capitalize sender header for Mailgun [FrameworkBundle] Configure `logger` as error logger if the Monolog Bundle is not registered DX: PHP CS Fixer - drop explicit nullable_type_declaration_for_default_null_value config, as it's part of ruleset anyway DX: PHP CS Fixer - drop explicit no_superfluous_phpdoc_tags config, as it's part of ruleset already Revert "Add keyword `dev` to leverage composer hint" [Validator] Add missing Ukrainian translations #51960 [Validator] Add missing translations for Indonesian (id) [Validator] Add missing translations for Vietnamese (VI) Add missing Validator translations - Croatian (hr) Run high-deps tests with ORM 3 and DBAL 4 [FrameworkBundle] Fix calling Kernel::warmUp() when running cache:warmup
2 parents 1618825 + 0b3fbbe commit f804b48

27 files changed

+521
-186
lines changed

Form/DoctrineOrmTypeGuesser.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function guessType(string $class, string $property): ?TypeGuess
6161
}
6262

6363
return match ($metadata->getTypeOfField($property)) {
64-
Types::ARRAY,
64+
'array',
6565
Types::SIMPLE_ARRAY => new TypeGuess(CollectionType::class, [], Guess::MEDIUM_CONFIDENCE),
6666
Types::BOOLEAN => new TypeGuess(CheckboxType::class, [], Guess::HIGH_CONFIDENCE),
6767
Types::DATETIME_MUTABLE,

Messenger/DoctrinePingConnectionMiddleware.php

+12-2
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;
@@ -38,14 +39,23 @@ private function pingConnection(EntityManagerInterface $entityManager): void
3839
$connection = $entityManager->getConnection();
3940

4041
try {
41-
$connection->executeQuery($connection->getDatabasePlatform()->getDummySelectSQL());
42+
$this->executeDummySql($connection);
4243
} catch (DBALException) {
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
}

Middleware/Debug/Connection.php

+21-37
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,16 @@
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 int $nestingLevel = 0;
28-
2927
public function __construct(
3028
ConnectionInterface $connection,
3129
private DebugDataHolder $debugDataHolder,
@@ -35,7 +33,7 @@ public function __construct(
3533
parent::__construct($connection);
3634
}
3735

38-
public function prepare(string $sql): DriverStatement
36+
public function prepare(string $sql): Statement
3937
{
4038
return new Statement(
4139
parent::prepare($sql),
@@ -54,13 +52,11 @@ public function query(string $sql): Result
5452
$query->start();
5553

5654
try {
57-
$result = parent::query($sql);
55+
return parent::query($sql);
5856
} finally {
5957
$query->stop();
6058
$this->stopwatch?->stop('doctrine');
6159
}
62-
63-
return $result;
6460
}
6561

6662
public function exec(string $sql): int
@@ -80,63 +76,51 @@ public function exec(string $sql): int
8076
return $affectedRows;
8177
}
8278

83-
public function beginTransaction(): bool
79+
public function beginTransaction(): void
8480
{
85-
$query = null;
86-
if (1 === ++$this->nestingLevel) {
87-
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query('"START TRANSACTION"'));
88-
}
81+
$query = new Query('"START TRANSACTION"');
82+
$this->debugDataHolder->addQuery($this->connectionName, $query);
8983

9084
$this->stopwatch?->start('doctrine', 'doctrine');
91-
$query?->start();
85+
$query->start();
9286

9387
try {
94-
$ret = parent::beginTransaction();
88+
parent::beginTransaction();
9589
} finally {
96-
$query?->stop();
90+
$query->stop();
9791
$this->stopwatch?->stop('doctrine');
9892
}
99-
100-
return $ret;
10193
}
10294

103-
public function commit(): bool
95+
public function commit(): void
10496
{
105-
$query = null;
106-
if (1 === $this->nestingLevel--) {
107-
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query('"COMMIT"'));
108-
}
97+
$query = new Query('"COMMIT"');
98+
$this->debugDataHolder->addQuery($this->connectionName, $query);
10999

110100
$this->stopwatch?->start('doctrine', 'doctrine');
111-
$query?->start();
101+
$query->start();
112102

113103
try {
114-
$ret = parent::commit();
104+
parent::commit();
115105
} finally {
116-
$query?->stop();
106+
$query->stop();
117107
$this->stopwatch?->stop('doctrine');
118108
}
119-
120-
return $ret;
121109
}
122110

123-
public function rollBack(): bool
111+
public function rollBack(): void
124112
{
125-
$query = null;
126-
if (1 === $this->nestingLevel--) {
127-
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query('"ROLLBACK"'));
128-
}
113+
$query = new Query('"ROLLBACK"');
114+
$this->debugDataHolder->addQuery($this->connectionName, $query);
129115

130116
$this->stopwatch?->start('doctrine', 'doctrine');
131-
$query?->start();
117+
$query->start();
132118

133119
try {
134-
$ret = parent::rollBack();
120+
parent::rollBack();
135121
} finally {
136-
$query?->stop();
122+
$query->stop();
137123
$this->stopwatch?->stop('doctrine');
138124
}
139-
140-
return $ret;
141125
}
142126
}

Middleware/Debug/DBAL3/Connection.php

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Doctrine\Middleware\Debug\DBAL3;
13+
14+
use Doctrine\DBAL\Driver\Connection as ConnectionInterface;
15+
use Doctrine\DBAL\Driver\Middleware\AbstractConnectionMiddleware;
16+
use Doctrine\DBAL\Driver\Result;
17+
use Symfony\Bridge\Doctrine\Middleware\Debug\DebugDataHolder;
18+
use Symfony\Bridge\Doctrine\Middleware\Debug\Query;
19+
use Symfony\Component\Stopwatch\Stopwatch;
20+
21+
/**
22+
* @author Laurent VOULLEMIER <[email protected]>
23+
*
24+
* @internal
25+
*/
26+
final class Connection extends AbstractConnectionMiddleware
27+
{
28+
private int $nestingLevel = 0;
29+
30+
public function __construct(
31+
ConnectionInterface $connection,
32+
private DebugDataHolder $debugDataHolder,
33+
private ?Stopwatch $stopwatch,
34+
private string $connectionName,
35+
) {
36+
parent::__construct($connection);
37+
}
38+
39+
public function prepare(string $sql): Statement
40+
{
41+
return new Statement(
42+
parent::prepare($sql),
43+
$this->debugDataHolder,
44+
$this->connectionName,
45+
$sql,
46+
$this->stopwatch,
47+
);
48+
}
49+
50+
public function query(string $sql): Result
51+
{
52+
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query($sql));
53+
54+
$this->stopwatch?->start('doctrine', 'doctrine');
55+
$query->start();
56+
57+
try {
58+
return parent::query($sql);
59+
} finally {
60+
$query->stop();
61+
$this->stopwatch?->stop('doctrine');
62+
}
63+
}
64+
65+
public function exec(string $sql): int
66+
{
67+
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query($sql));
68+
69+
$this->stopwatch?->start('doctrine', 'doctrine');
70+
$query->start();
71+
72+
try {
73+
return parent::exec($sql);
74+
} finally {
75+
$query->stop();
76+
$this->stopwatch?->stop('doctrine');
77+
}
78+
}
79+
80+
public function beginTransaction(): bool
81+
{
82+
$query = null;
83+
if (1 === ++$this->nestingLevel) {
84+
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query('"START TRANSACTION"'));
85+
}
86+
87+
$this->stopwatch?->start('doctrine', 'doctrine');
88+
$query?->start();
89+
90+
try {
91+
return parent::beginTransaction();
92+
} finally {
93+
$query?->stop();
94+
$this->stopwatch?->stop('doctrine');
95+
}
96+
}
97+
98+
public function commit(): bool
99+
{
100+
$query = null;
101+
if (1 === $this->nestingLevel--) {
102+
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query('"COMMIT"'));
103+
}
104+
105+
$this->stopwatch?->start('doctrine', 'doctrine');
106+
$query?->start();
107+
108+
try {
109+
return parent::commit();
110+
} finally {
111+
$query?->stop();
112+
$this->stopwatch?->stop('doctrine');
113+
}
114+
}
115+
116+
public function rollBack(): bool
117+
{
118+
$query = null;
119+
if (1 === $this->nestingLevel--) {
120+
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query('"ROLLBACK"'));
121+
}
122+
123+
$this->stopwatch?->start('doctrine', 'doctrine');
124+
$query?->start();
125+
126+
try {
127+
return parent::rollBack();
128+
} finally {
129+
$query?->stop();
130+
$this->stopwatch?->stop('doctrine');
131+
}
132+
}
133+
}

Middleware/Debug/DBAL3/Statement.php

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Doctrine\Middleware\Debug\DBAL3;
13+
14+
use Doctrine\DBAL\Driver\Middleware\AbstractStatementMiddleware;
15+
use Doctrine\DBAL\Driver\Result as ResultInterface;
16+
use Doctrine\DBAL\Driver\Statement as StatementInterface;
17+
use Doctrine\DBAL\ParameterType;
18+
use Symfony\Bridge\Doctrine\Middleware\Debug\DebugDataHolder;
19+
use Symfony\Bridge\Doctrine\Middleware\Debug\Query;
20+
use Symfony\Component\Stopwatch\Stopwatch;
21+
22+
/**
23+
* @author Laurent VOULLEMIER <[email protected]>
24+
*
25+
* @internal
26+
*/
27+
final class Statement extends AbstractStatementMiddleware
28+
{
29+
private Query $query;
30+
31+
public function __construct(
32+
StatementInterface $statement,
33+
private DebugDataHolder $debugDataHolder,
34+
private string $connectionName,
35+
string $sql,
36+
private ?Stopwatch $stopwatch = null,
37+
) {
38+
parent::__construct($statement);
39+
40+
$this->query = new Query($sql);
41+
}
42+
43+
public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null): bool
44+
{
45+
$this->query->setParam($param, $variable, $type);
46+
47+
return parent::bindParam($param, $variable, $type, ...\array_slice(\func_get_args(), 3));
48+
}
49+
50+
public function bindValue($param, $value, $type = ParameterType::STRING): bool
51+
{
52+
$this->query->setValue($param, $value, $type);
53+
54+
return parent::bindValue($param, $value, $type);
55+
}
56+
57+
public function execute($params = null): ResultInterface
58+
{
59+
if (null !== $params) {
60+
$this->query->setValues($params);
61+
}
62+
63+
// clone to prevent variables by reference to change
64+
$this->debugDataHolder->addQuery($this->connectionName, $query = clone $this->query);
65+
66+
$this->stopwatch?->start('doctrine', 'doctrine');
67+
$query->start();
68+
69+
try {
70+
return parent::execute($params);
71+
} finally {
72+
$query->stop();
73+
$this->stopwatch?->stop('doctrine');
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)