1414use Doctrine \DBAL \Driver \Connection as ConnectionInterface ;
1515use Doctrine \DBAL \Driver \Middleware \AbstractConnectionMiddleware ;
1616use Doctrine \DBAL \Driver \Result ;
17- use Doctrine \DBAL \Driver \Statement as DriverStatement ;
1817use Symfony \Component \Stopwatch \Stopwatch ;
1918
2019/**
2120 * @author Laurent VOULLEMIER <laurent.voullemier@gmail.com>
21+ * @author Alexander M. Turek <me@derrabus.de>
2222 *
2323 * @internal
2424 */
2525final class Connectionextends 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+ ) {
3433parent ::__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 {
4338return new Statement (
4439parent ::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
6254try {
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
7562public 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
8569try {
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
9576return $ 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
11387try {
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
143103try {
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
173119try {
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}