Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit65788a3

Browse files
committed
[DoctrineBridge] fix issue with missing stopwatch events
1 parent01344e3 commit65788a3

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public function prepare(string $sql): DriverStatement
4444
parent::prepare($sql),
4545
$this->debugDataHolder,
4646
$this->connectionName,
47-
$sql
47+
$sql,
48+
$this->stopwatch
4849
);
4950
}
5051

‎src/Symfony/Bridge/Doctrine/Middleware/Debug/Statement.php‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
useDoctrine\DBAL\Driver\ResultasResultInterface;
1616
useDoctrine\DBAL\Driver\StatementasStatementInterface;
1717
useDoctrine\DBAL\ParameterType;
18+
useSymfony\Component\Stopwatch\Stopwatch;
1819

1920
/**
2021
* @author Laurent VOULLEMIER <laurent.voullemier@gmail.com>
@@ -26,14 +27,16 @@ final class Statement extends AbstractStatementMiddleware
2627
private$debugDataHolder;
2728
private$connectionName;
2829
private$query;
30+
private$stopwatch;
2931

30-
publicfunction__construct(StatementInterface$statement,DebugDataHolder$debugDataHolder,string$connectionName,string$sql)
32+
publicfunction__construct(StatementInterface$statement,DebugDataHolder$debugDataHolder,string$connectionName,string$sql, ?Stopwatch$stopwatch =null)
3133
{
3234
parent::__construct($statement);
3335

3436
$this->debugDataHolder =$debugDataHolder;
3537
$this->connectionName =$connectionName;
3638
$this->query =newQuery($sql);
39+
$this->stopwatch =$stopwatch;
3740
}
3841

3942
publicfunctionbindParam($param, &$variable,$type = ParameterType::STRING,$length =null):bool
@@ -59,12 +62,20 @@ public function execute($params = null): ResultInterface
5962
// clone to prevent variables by reference to change
6063
$this->debugDataHolder->addQuery($this->connectionName,$query =clone$this->query);
6164

65+
if (null !==$this->stopwatch) {
66+
$this->stopwatch->start('doctrine','doctrine');
67+
}
68+
6269
$query->start();
6370

6471
try {
6572
$result =parent::execute($params);
6673
}finally {
6774
$query->stop();
75+
76+
if (null !==$this->stopwatch) {
77+
$this->stopwatch->stop('doctrine');
78+
}
6879
}
6980

7081
return$result;

‎src/Symfony/Bridge/Doctrine/Tests/Middleware/Debug/MiddlewareTest.php‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,6 @@ public function testWithParamBound(callable $executeMethod)
161161
$executeMethod($stmt);
162162

163163
// Debug data should not be affected by these changes
164-
$product ='product2';
165-
$price =13.5;
166-
$stock =4;
167-
168164
$debug =$this->debugDataHolder->getData()['default'] ?? [];
169165
$this->assertCount(2,$debug);
170166
$this->assertSame('INSERT INTO products(name, price, stock) VALUES (?, ?, ?)',$debug[1]['sql']);
@@ -242,6 +238,14 @@ static function (Connection $conn): bool {
242238
return$conn->rollBack();
243239
},
244240
],
241+
'prepared statement' => [
242+
staticfunction (Connection$conn,string$sql):Result {
243+
return$conn->prepare($sql)->executeQuery();
244+
},
245+
staticfunction (Connection$conn):bool {
246+
return$conn->commit();
247+
},
248+
],
245249
];
246250
}
247251

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp