22
33use Bolt \Bolt ;
44use Bolt \connection \{Socket , StreamSocket };
5- use Bolt \protocol \{AProtocol , Response };
5+ use Bolt \protocol \{AProtocol , Response , V4_1 , V4 , V3 };
66
77/**
88 * Class Memgraph - adapter for Bolt library
@@ -33,14 +33,13 @@ class Memgraph
3333 public static int $ port = 7687 ;
3434 public static float $ timeout = 15 ;
3535
36- private static ? AProtocol $ protocol = null ;
36+ private static AProtocol | V4_1 | V4 | V3 | null $ protocol = null ;
3737 private static array $ statistics ;
3838
3939 /**
4040 * Get connection protocol for bolt communication
41- * @return AProtocol
4241 */
43- protected static function getProtocol (): AProtocol
42+ protected static function getProtocol (): AProtocol | V4_1 | V4 | V3
4443 {
4544 if (is_null (self ::$ protocol )) {
4645 try {
@@ -98,6 +97,7 @@ public static function query(string $query, array $params = [], array $extra = [
9897 $ all [] = $ response ->getContent ();
9998 }
10099 } catch (Exception $ e ) {
100+ self ::getProtocol ()->reset ();
101101 self ::handleException ($ e );
102102 return [];
103103 }
@@ -129,7 +129,7 @@ public static function query(string $query, array $params = [], array $extra = [
129129 * @param array $extra
130130 * @return mixed
131131 */
132- public static function queryFirstField (string $ query , array $ params = [], array $ extra = [])
132+ public static function queryFirstField (string $ query , array $ params = [], array $ extra = []): mixed
133133 {
134134 $ data = self ::query ($ query , $ params , $ extra );
135135 if (empty ($ data )) {
@@ -175,6 +175,7 @@ public static function begin(array $extra = []): bool
175175 }
176176 return true ;
177177 } catch (Exception $ e ) {
178+ self ::getProtocol ()->reset ();
178179 self ::handleException ($ e );
179180 }
180181 return false ;
@@ -197,6 +198,7 @@ public static function commit(): bool
197198 }
198199 return true ;
199200 } catch (Exception $ e ) {
201+ self ::getProtocol ()->reset ();
200202 self ::handleException ($ e );
201203 }
202204 return false ;
@@ -219,6 +221,7 @@ public static function rollback(): bool
219221 }
220222 return true ;
221223 } catch (Exception $ e ) {
224+ self ::getProtocol ()->reset ();
222225 self ::handleException ($ e );
223226 }
224227 return false ;
@@ -253,7 +256,7 @@ public static function statistic(string $key): int
253256 /**
254257 * @param Exception $e
255258 */
256- private static function handleException (Exception $ e )
259+ private static function handleException (Exception $ e ): void
257260 {
258261 if (is_callable (self ::$ errorHandler )) {
259262 call_user_func (self ::$ errorHandler , $ e );
0 commit comments