diff --git a/src/Bolt/BoltConnection.php b/src/Bolt/BoltConnection.php index 3b68a525..8bf528a0 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; @@ -35,7 +37,7 @@ use WeakReference; /** - * @implements ConnectionInterface + * @implements ConnectionInterface * * @psalm-import-type BoltMeta from FormatterInterface */ @@ -57,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 { @@ -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, @@ -268,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; } diff --git a/src/Bolt/ProtocolFactory.php b/src/Bolt/ProtocolFactory.php index 97335e31..4f9294ba 100644 --- a/src/Bolt/ProtocolFactory.php +++ b/src/Bolt/ProtocolFactory.php @@ -15,8 +15,11 @@ use Bolt\Bolt; use Bolt\connection\IConnection; +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 +28,22 @@ 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 (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_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'); }