Skip to content

Commit

Permalink
feat: Add support for Bolt 5.2 and 5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
exaby73 committed Jul 23, 2024
1 parent 17c7db1 commit 6e2b615
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/Bolt/ProtocolFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)) {

Check failure on line 48 in src/Bolt/ProtocolFactory.php

View workflow job for this annotation

GitHub Actions / Lint & Analyse

PossiblyUndefinedVariable

src/Bolt/ProtocolFactory.php:48:15: PossiblyUndefinedVariable: Possibly undefined variable $protocol defined in try block (see https://psalm.dev/018)

Check failure on line 48 in src/Bolt/ProtocolFactory.php

View workflow job for this annotation

GitHub Actions / Lint & Analyse

PossiblyUndefinedVariable

src/Bolt/ProtocolFactory.php:48:44: PossiblyUndefinedVariable: Possibly undefined variable $protocol defined in try block (see https://psalm.dev/018)

Check failure on line 48 in src/Bolt/ProtocolFactory.php

View workflow job for this annotation

GitHub Actions / Lint & Analyse

PossiblyUndefinedVariable

src/Bolt/ProtocolFactory.php:48:71: PossiblyUndefinedVariable: Possibly undefined variable $protocol defined in try block (see https://psalm.dev/018)

Check failure on line 48 in src/Bolt/ProtocolFactory.php

View workflow job for this annotation

GitHub Actions / Lint & Analyse

PossiblyUndefinedVariable

src/Bolt/ProtocolFactory.php:48:100: PossiblyUndefinedVariable: Possibly undefined variable $protocol defined in try block (see https://psalm.dev/018)

Check failure on line 48 in src/Bolt/ProtocolFactory.php

View workflow job for this annotation

GitHub Actions / Lint & Analyse

PossiblyUndefinedVariable

src/Bolt/ProtocolFactory.php:48:129: PossiblyUndefinedVariable: Possibly undefined variable $protocol defined in try block (see https://psalm.dev/018)

Check failure on line 48 in src/Bolt/ProtocolFactory.php

View workflow job for this annotation

GitHub Actions / Lint & Analyse

PossiblyUndefinedVariable

src/Bolt/ProtocolFactory.php:48:158: PossiblyUndefinedVariable: Possibly undefined variable $protocol defined in try block (see https://psalm.dev/018)
throw new RuntimeException('Client only supports bolt version 4.4 and ^5.0');
}

Expand Down

0 comments on commit 6e2b615

Please sign in to comment.