Skip to content

Commit 3158357

Browse files
exaby73transistive
authored andcommitted
feat: Add support for Bolt 5.2 and 5.1
1 parent 17c7db1 commit 3158357

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/Bolt/ProtocolFactory.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515

1616
use Bolt\Bolt;
1717
use Bolt\connection\IConnection;
18+
use Bolt\error\BoltException;
19+
use Bolt\error\ConnectException;
1820
use Bolt\protocol\V4_4;
1921
use Bolt\protocol\V5;
22+
use Bolt\protocol\V5_1;
23+
use Bolt\protocol\V5_2;
2024
use Bolt\protocol\V5_3;
2125
use Bolt\protocol\V5_4;
2226
use Laudis\Neo4j\Contracts\AuthenticateInterface;
@@ -25,16 +29,23 @@
2529
class ProtocolFactory
2630
{
2731
/**
28-
* @return array{0: V4_4|V5|V5_3|V5_4, 1: array{server: string, connection_id: string, hints: list}}
32+
* @return array{0: V4_4|V5|V5_1|V5_2|V5_3|V5_4, 1: array{server: string, connection_id: string, hints: list}}
2933
*/
3034
public function createProtocol(IConnection $connection, AuthenticateInterface $auth, string $userAgent): array
3135
{
3236
$bolt = new Bolt($connection);
3337
$bolt->setProtocolVersions(5.4, 5.3, 5, 4.4);
3438

35-
$protocol = $bolt->build();
39+
try {
40+
$protocol = $bolt->build();
41+
} catch (BoltException $e) {
42+
if ($e instanceof ConnectException && $e->getMessage() === 'Wrong version') {
43+
$bolt->setProtocolVersions(5.2, 5.1);
44+
$protocol = $bolt->build();
45+
}
46+
}
3647

37-
if (!($protocol instanceof V4_4 || $protocol instanceof V5 || $protocol instanceof V5_3 || $protocol instanceof V5_4)) {
48+
if (!($protocol instanceof V4_4 || $protocol instanceof V5 || $protocol instanceof V5_1 || $protocol instanceof V5_2 || $protocol instanceof V5_3 || $protocol instanceof V5_4)) {
3849
throw new RuntimeException('Client only supports bolt version 4.4 and ^5.0');
3950
}
4051

0 commit comments

Comments
 (0)