15
15
use Doctrine \DBAL \Driver \Result as ResultInterface ;
16
16
use Doctrine \DBAL \Driver \Statement as StatementInterface ;
17
17
use Doctrine \DBAL \ParameterType ;
18
+ use Symfony \Component \Stopwatch \Stopwatch ;
18
19
19
20
/**
20
21
* @author Laurent VOULLEMIER <laurent.voullemier@gmail.com>
@@ -26,14 +27,16 @@ final class Statement extends AbstractStatementMiddleware
26
27
private $ debugDataHolder ;
27
28
private $ connectionName ;
28
29
private $ query ;
30
+ private $ stopwatch ;
29
31
30
- public function __construct (StatementInterface $ statement , DebugDataHolder $ debugDataHolder , string $ connectionName , string $ sql )
32
+ public function __construct (StatementInterface $ statement , DebugDataHolder $ debugDataHolder , string $ connectionName , string $ sql, ? Stopwatch $ stopwatch = null )
31
33
{
32
34
parent ::__construct ($ statement );
33
35
34
36
$ this ->debugDataHolder = $ debugDataHolder ;
35
37
$ this ->connectionName = $ connectionName ;
36
38
$ this ->query = new Query ($ sql );
39
+ $ this ->stopwatch = $ stopwatch ;
37
40
}
38
41
39
42
public function bindParam ($ param , &$ variable , $ type = ParameterType::STRING , $ length = null ): bool
@@ -59,12 +62,20 @@ public function execute($params = null): ResultInterface
59
62
// clone to prevent variables by reference to change
60
63
$ this ->debugDataHolder ->addQuery ($ this ->connectionName , $ query = clone $ this ->query );
61
64
65
+ if (null !== $ this ->stopwatch ) {
66
+ $ this ->stopwatch ->start ('doctrine ' , 'doctrine ' );
67
+ }
68
+
62
69
$ query ->start ();
63
70
64
71
try {
65
72
$ result = parent ::execute ($ params );
66
73
} finally {
67
74
$ query ->stop ();
75
+
76
+ if (null !== $ this ->stopwatch ) {
77
+ $ this ->stopwatch ->stop ('doctrine ' );
78
+ }
68
79
}
69
80
70
81
return $ result ;
0 commit comments