From 6e2b6155023c9448959b0e030c3b69183416859c Mon Sep 17 00:00:00 2001 From: exaby73 Date: Tue, 23 Jul 2024 11:12:14 +0530 Subject: [PATCH 1/4] feat: Add support for Bolt 5.2 and 5.1 --- src/Bolt/ProtocolFactory.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Bolt/ProtocolFactory.php b/src/Bolt/ProtocolFactory.php index 97335e31..e2557dbb 100644 --- a/src/Bolt/ProtocolFactory.php +++ b/src/Bolt/ProtocolFactory.php @@ -15,8 +15,12 @@ use Bolt\Bolt; use Bolt\connection\IConnection; +use Bolt\error\BoltException; +use Bolt\error\ConnectException; use Bolt\protocol\V4_4; use Bolt\protocol\V5; +use Bolt\protocol\V5_1; +use Bolt\protocol\V5_2; use Bolt\protocol\V5_3; use Bolt\protocol\V5_4; use Laudis\Neo4j\Contracts\AuthenticateInterface; @@ -25,16 +29,23 @@ class ProtocolFactory { /** - * @return array{0: V4_4|V5|V5_3|V5_4, 1: array{server: string, connection_id: string, hints: list}} + * @return array{0: V4_4|V5|V5_1|V5_2|V5_3|V5_4, 1: array{server: string, connection_id: string, hints: list}} */ public function createProtocol(IConnection $connection, AuthenticateInterface $auth, string $userAgent): array { $bolt = new Bolt($connection); $bolt->setProtocolVersions(5.4, 5.3, 5, 4.4); - $protocol = $bolt->build(); + try { + $protocol = $bolt->build(); + } catch (BoltException $e) { + if ($e instanceof ConnectException && $e->getMessage() === 'Wrong version') { + $bolt->setProtocolVersions(5.2, 5.1); + $protocol = $bolt->build(); + } + } - if (!($protocol instanceof V4_4 || $protocol instanceof V5 || $protocol instanceof V5_3 || $protocol instanceof V5_4)) { + if (!($protocol instanceof V4_4 || $protocol instanceof V5 || $protocol instanceof V5_1 || $protocol instanceof V5_2 || $protocol instanceof V5_3 || $protocol instanceof V5_4)) { throw new RuntimeException('Client only supports bolt version 4.4 and ^5.0'); } From 7c8b6909561a665d21443f12cf867ea8486a8dc5 Mon Sep 17 00:00:00 2001 From: exaby73 Date: Tue, 23 Jul 2024 11:20:52 +0530 Subject: [PATCH 2/4] feat: Check for 5.2 and 5.1 on generic ConnectException --- src/Bolt/ProtocolFactory.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Bolt/ProtocolFactory.php b/src/Bolt/ProtocolFactory.php index e2557dbb..4f9294ba 100644 --- a/src/Bolt/ProtocolFactory.php +++ b/src/Bolt/ProtocolFactory.php @@ -15,7 +15,6 @@ use Bolt\Bolt; use Bolt\connection\IConnection; -use Bolt\error\BoltException; use Bolt\error\ConnectException; use Bolt\protocol\V4_4; use Bolt\protocol\V5; @@ -38,11 +37,10 @@ public function createProtocol(IConnection $connection, AuthenticateInterface $a try { $protocol = $bolt->build(); - } catch (BoltException $e) { - if ($e instanceof ConnectException && $e->getMessage() === 'Wrong version') { - $bolt->setProtocolVersions(5.2, 5.1); - $protocol = $bolt->build(); - } + } catch (ConnectException $e) { + // Assume incorrect protocol version + $bolt->setProtocolVersions(5.2, 5.1); + $protocol = $bolt->build(); } if (!($protocol instanceof V4_4 || $protocol instanceof V5 || $protocol instanceof V5_1 || $protocol instanceof V5_2 || $protocol instanceof V5_3 || $protocol instanceof V5_4)) { From 97744d74970aeaf5eb3bb07344aeef6761e7884a Mon Sep 17 00:00:00 2001 From: exaby73 Date: Tue, 23 Jul 2024 11:23:39 +0530 Subject: [PATCH 3/4] feat: Update BoltConnection to accept new added versions --- src/Bolt/BoltConnection.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Bolt/BoltConnection.php b/src/Bolt/BoltConnection.php index 3b68a525..fb600c49 100644 --- a/src/Bolt/BoltConnection.php +++ b/src/Bolt/BoltConnection.php @@ -18,6 +18,8 @@ use Bolt\protocol\Response; use Bolt\protocol\V4_4; use Bolt\protocol\V5; +use Bolt\protocol\V5_1; +use Bolt\protocol\V5_2; use Bolt\protocol\V5_3; use Bolt\protocol\V5_4; use Laudis\Neo4j\Common\ConnectionConfiguration; @@ -68,7 +70,7 @@ public function getImplementation(): array * @psalm-mutation-free */ public function __construct( - private V4_4|V5|V5_3|V5_4 $boltProtocol, + private V4_4|V5|V5_1|V5_2|V5_3|V5_4 $boltProtocol, private readonly Connection $connection, private readonly AuthenticateInterface $auth, private readonly string $userAgent, From a1b8aeff01e5408654497d9c29f055b83d028054 Mon Sep 17 00:00:00 2001 From: exaby73 Date: Tue, 23 Jul 2024 11:28:44 +0530 Subject: [PATCH 4/4] feat: Update BoltConnection types --- src/Bolt/BoltConnection.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Bolt/BoltConnection.php b/src/Bolt/BoltConnection.php index fb600c49..8bf528a0 100644 --- a/src/Bolt/BoltConnection.php +++ b/src/Bolt/BoltConnection.php @@ -37,7 +37,7 @@ use WeakReference; /** - * @implements ConnectionInterface + * @implements ConnectionInterface * * @psalm-import-type BoltMeta from FormatterInterface */ @@ -59,7 +59,7 @@ class BoltConnection implements ConnectionInterface private array $subscribedResults = []; /** - * @return array{0: V4_4|V5|V5_3|V5_4, 1: Connection} + * @return array{0: V4_4|V5|V5_1|V5_2|V5_3|V5_4, 1: Connection} */ public function getImplementation(): array { @@ -270,7 +270,7 @@ public function rollback(): void $this->assertNoFailure($response); } - public function protocol(): V4_4|V5|V5_3|V5_4 + public function protocol(): V4_4|V5|V5_1|V5_2|V5_3|V5_4 { return $this->boltProtocol; }