1515use Doctrine \DBAL \Driver \Result as ResultInterface ;
1616use Doctrine \DBAL \Driver \Statement as StatementInterface ;
1717use Doctrine \DBAL \ParameterType ;
18+ use Symfony \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- 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 )
3133 {
3234 parent ::__construct ($ statement );
3335
3436 $ this ->debugDataHolder = $ debugDataHolder ;
3537 $ this ->connectionName = $ connectionName ;
3638 $ this ->query = new Query ($ sql );
39+ $ this ->stopwatch = $ stopwatch ;
3740 }
3841
3942 public function bindParam ($ 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 ($ 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 ($ this ->stopwatch ) {
77+ $ this ->stopwatch ->stop ('doctrine ' );
78+ }
6879 }
6980
7081 return $ result ;
0 commit comments