Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v54 #125

Merged
merged 3 commits into from
Nov 16, 2023
Merged

v54 #125

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/db.50.2204.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
neo4j-version: ['5.4', '5.6', '5.8', '5.12']
neo4j-version: ['5.4', '5.6', '5.8', '5.12', '5.13']
php-version: ['8.0', '8.1', '8.2']

services:
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ all available versions and keep up with protocol messages architecture and speci

## Version support

We are trying to keep up and this library supports **Bolt <= 5.3**.
We are trying to keep up and this library supports **Bolt <= 5.4**.

https://www.neo4j.com/docs/bolt/current/bolt-compatibility/

Expand Down Expand Up @@ -121,6 +121,7 @@ foreach ($protocol->getResponses() as $response) {
| commit | Commit transaction | |
| rollback | Rollback transaction | |
| reset | Send message to reset connection | |
| telemetry | | int $api |
| getVersion | Get used protocol version | |
| getResponse | Get waiting response from server | |
| getResponses | Get waiting responses from server | |
Expand Down
1 change: 1 addition & 0 deletions src/protocol/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Response
public const MESSAGE_ACK_FAILURE = 'ACK_FAILURE';
public const MESSAGE_LOGON = 'LOGON';
public const MESSAGE_LOGOFF = 'LOGOFF';
public const MESSAGE_TELEMETRY = 'TELEMETRY';

public const SIGNATURE_SUCCESS = 0x70; //112
public const SIGNATURE_FAILURE = 0x7F; //127
Expand Down
36 changes: 36 additions & 0 deletions src/protocol/V5_4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Bolt\protocol;

/**
* Class Protocol version 5.4
*
* @author Michal Stefanak
* @link https://github.com/neo4j-php/Bolt
* @see https://www.neo4j.com/docs/bolt/current/bolt/message/
* @package Bolt\protocol
*/
class V5_4 extends AProtocol
{
use \Bolt\protocol\v5\AvailableStructures;

use \Bolt\protocol\v1\ResetMessage;

use \Bolt\protocol\v3\RunMessage;
use \Bolt\protocol\v3\BeginMessage;
use \Bolt\protocol\v3\CommitMessage;
use \Bolt\protocol\v3\RollbackMessage;
use \Bolt\protocol\v3\GoodbyeMessage;

use \Bolt\protocol\v4\PullMessage;
use \Bolt\protocol\v4\DiscardMessage;

use \Bolt\protocol\v4_4\RouteMessage;

use \Bolt\protocol\v5_1\LogonMessage;
use \Bolt\protocol\v5_1\LogoffMessage;

use \Bolt\protocol\v5_3\HelloMessage;

use \Bolt\protocol\v5_4\TelemetryMessage;
}
4 changes: 2 additions & 2 deletions src/protocol/v1/ResetMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Bolt\protocol\v1;

use Bolt\protocol\{ServerState, Response, V1, V2, V3, V4, V4_1, V4_2, V4_3, V4_4, V5, V5_1, V5_2, V5_3};
use Bolt\protocol\{ServerState, Response, V1, V2, V3, V4, V4_1, V4_2, V4_3, V4_4, V5, V5_1, V5_2, V5_3, V5_4};
use Bolt\error\BoltException;

trait ResetMessage
Expand All @@ -14,7 +14,7 @@ trait ResetMessage
* @link https://www.neo4j.com/docs/bolt/current/bolt/message/#messages-reset
* @throws BoltException
*/
public function reset(): V1|V2|V3|V4|V4_1|V4_2|V4_3|V4_4|V5|V5_1|V5_2|V5_3
public function reset(): V1|V2|V3|V4|V4_1|V4_2|V4_3|V4_4|V5|V5_1|V5_2|V5_3|V5_4
{
$this->write($this->packer->pack(0x0F));
$this->pipelinedMessages[] = __FUNCTION__;
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/v3/BeginMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Bolt\protocol\v3;

use Bolt\protocol\{ServerState, Response, V3, V4, V4_1, V4_2, V4_3, V4_4, V5, V5_1, V5_2, V5_3};
use Bolt\protocol\{ServerState, Response, V3, V4, V4_1, V4_2, V4_3, V4_4, V5, V5_1, V5_2, V5_3, V5_4};
use Bolt\error\BoltException;

trait BeginMessage
Expand All @@ -14,7 +14,7 @@ trait BeginMessage
* @link https://www.neo4j.com/docs/bolt/current/bolt/message/#messages-begin
* @throws BoltException
*/
public function begin(array $extra = []): V3|V4|V4_1|V4_2|V4_3|V4_4|V5|V5_1|V5_2|V5_3
public function begin(array $extra = []): V3|V4|V4_1|V4_2|V4_3|V4_4|V5|V5_1|V5_2|V5_3|V5_4
{
$this->serverState->is(ServerState::READY);
$this->write($this->packer->pack(0x11, (object)$extra));
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/v3/CommitMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Bolt\protocol\v3;

use Bolt\protocol\{ServerState, Response, V3, V4, V4_1, V4_2, V4_3, V4_4, V5, V5_1, V5_2, V5_3};
use Bolt\protocol\{ServerState, Response, V3, V4, V4_1, V4_2, V4_3, V4_4, V5, V5_1, V5_2, V5_3, V5_4};
use Bolt\error\BoltException;

trait CommitMessage
Expand All @@ -14,7 +14,7 @@ trait CommitMessage
* @link https://www.neo4j.com/docs/bolt/current/bolt/message/#messages-commit
* @throws BoltException
*/
public function commit(): V3|V4|V4_1|V4_2|V4_3|V4_4|V5|V5_1|V5_2|V5_3
public function commit(): V3|V4|V4_1|V4_2|V4_3|V4_4|V5|V5_1|V5_2|V5_3|V5_4
{
$this->serverState->is(ServerState::TX_READY, ServerState::TX_STREAMING);
$this->write($this->packer->pack(0x12));
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/v3/RollbackMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Bolt\protocol\v3;

use Bolt\protocol\{ServerState, Response, V3, V4, V4_1, V4_2, V4_3, V4_4, V5, V5_1, V5_2, V5_3};
use Bolt\protocol\{ServerState, Response, V3, V4, V4_1, V4_2, V4_3, V4_4, V5, V5_1, V5_2, V5_3, V5_4};
use Bolt\error\BoltException;

trait RollbackMessage
Expand All @@ -14,7 +14,7 @@ trait RollbackMessage
* @link https://www.neo4j.com/docs/bolt/current/bolt/message/#messages-rollback
* @throws BoltException
*/
public function rollback(): V3|V4|V4_1|V4_2|V4_3|V4_4|V5|V5_1|V5_2|V5_3
public function rollback(): V3|V4|V4_1|V4_2|V4_3|V4_4|V5|V5_1|V5_2|V5_3|V5_4
{
$this->serverState->is(ServerState::TX_READY, ServerState::TX_STREAMING);
$this->write($this->packer->pack(0x13));
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/v3/RunMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Bolt\protocol\v3;

use Bolt\protocol\{ServerState, Response, V3, V4, V4_1, V4_2, V4_3, V4_4, V5, V5_1, V5_2, V5_3};
use Bolt\protocol\{ServerState, Response, V3, V4, V4_1, V4_2, V4_3, V4_4, V5, V5_1, V5_2, V5_3, V5_4};
use Bolt\error\BoltException;

trait RunMessage
Expand All @@ -14,7 +14,7 @@ trait RunMessage
* @link https://www.neo4j.com/docs/bolt/current/bolt/message/#messages-run
* @throws BoltException
*/
public function run(string $query, array $parameters = [], array $extra = []): V3|V4|V4_1|V4_2|V4_3|V4_4|V5|V5_1|V5_2|V5_3
public function run(string $query, array $parameters = [], array $extra = []): V3|V4|V4_1|V4_2|V4_3|V4_4|V5|V5_1|V5_2|V5_3|V5_4
{
$this->serverState->is(ServerState::READY, ServerState::TX_READY, ServerState::STREAMING, ServerState::TX_STREAMING);

Expand Down
4 changes: 2 additions & 2 deletions src/protocol/v4/DiscardMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Bolt\protocol\v4;

use Bolt\protocol\{ServerState, Response, V4, V4_1, V4_2, V4_3, V4_4, V5, V5_1, V5_2, V5_3};
use Bolt\protocol\{ServerState, Response, V4, V4_1, V4_2, V4_3, V4_4, V5, V5_1, V5_2, V5_3, V5_4};
use Bolt\error\BoltException;

trait DiscardMessage
Expand All @@ -15,7 +15,7 @@ trait DiscardMessage
* @param array $extra [n::Integer, qid::Integer]
* @throws BoltException
*/
public function discard(array $extra = []): V4|V4_1|V4_2|V4_3|V4_4|V5|V5_1|V5_2|V5_3
public function discard(array $extra = []): V4|V4_1|V4_2|V4_3|V4_4|V5|V5_1|V5_2|V5_3|V5_4
{
$this->serverState->is(ServerState::READY, ServerState::TX_READY, ServerState::STREAMING, ServerState::TX_STREAMING);

Expand Down
4 changes: 2 additions & 2 deletions src/protocol/v4/PullMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Bolt\protocol\v4;

use Bolt\protocol\{ServerState, Response, V4, V4_1, V4_2, V4_3, V4_4, V5, V5_1, V5_2, V5_3};
use Bolt\protocol\{ServerState, Response, V4, V4_1, V4_2, V4_3, V4_4, V5, V5_1, V5_2, V5_3, V5_4};
use Bolt\error\BoltException;

trait PullMessage
Expand All @@ -15,7 +15,7 @@ trait PullMessage
* @param array $extra [n::Integer, qid::Integer]
* @throws BoltException
*/
public function pull(array $extra = []): V4|V4_1|V4_2|V4_3|V4_4|V5|V5_1|V5_2|V5_3
public function pull(array $extra = []): V4|V4_1|V4_2|V4_3|V4_4|V5|V5_1|V5_2|V5_3|V5_4
{
$this->serverState->is(ServerState::READY, ServerState::TX_READY, ServerState::STREAMING, ServerState::TX_STREAMING);

Expand Down
4 changes: 2 additions & 2 deletions src/protocol/v4_4/RouteMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Bolt\protocol\v4_4;

use Bolt\protocol\{ServerState, Response, V4_4, V5, V5_1, V5_2, V5_3};
use Bolt\protocol\{ServerState, Response, V4_4, V5, V5_1, V5_2, V5_3, V5_4};
use Bolt\error\BoltException;

trait RouteMessage
Expand All @@ -15,7 +15,7 @@ trait RouteMessage
* @param array $extra [db::String, imp_user::String]
* @throws BoltException
*/
public function route(array $routing, array $bookmarks = [], array $extra = []): V4_4|V5|V5_1|V5_2|V5_3
public function route(array $routing, array $bookmarks = [], array $extra = []): V4_4|V5|V5_1|V5_2|V5_3|V5_4
{
$this->serverState->is(ServerState::READY);
$this->write($this->packer->pack(0x66, (object)$routing, $bookmarks, (object)$extra));
Expand Down
31 changes: 31 additions & 0 deletions src/protocol/v5_4/TelemetryMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Bolt\protocol\v5_4;

use Bolt\error\BoltException;
use Bolt\protocol\Response;
use Bolt\protocol\ServerState;

trait TelemetryMessage
{
/**
* Send TELEMETRY message
* The TELEMETRY message contains an integer representing which driver API was used.
*
* @link https://neo4j.com/docs/bolt/current/bolt/message/#messages-telemetry
* @param int $api
* @return Response
* @throws BoltException
*/
public function telemetry(int $api): Response
{
$this->write($this->packer->pack(0x54, $api));
$content = $this->read($signature);

if ($signature === Response::SIGNATURE_FAILURE) {
$this->serverState->set(ServerState::FAILED);
}

return new Response(Response::MESSAGE_TELEMETRY, $signature, $content);
}
}
5 changes: 3 additions & 2 deletions tests/ATest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ protected function sayHello(AProtocol $protocol, string $name, string $password)
* Neo4j version is received by HTTP request on browser port
* @param string|null $url
* @return float|int
* @link https://neo4j.com/docs/http-api/current/endpoints/#discovery-api
*/
protected function getCompatibleBoltVersion(string $url = null): float|int
{
Expand All @@ -69,8 +70,8 @@ protected function getCompatibleBoltVersion(string $url = null): float|int

$neo4jVersion = $decoded['neo4j_version'];

// if (version_compare($neo4jVersion, '5.13', '>='))
// return 5.4;
if (version_compare($neo4jVersion, '5.13', '>='))
return 5.4;
if (version_compare($neo4jVersion, '5.9', '>='))
return 5.3;
if (version_compare($neo4jVersion, '5.7', '>='))
Expand Down
33 changes: 33 additions & 0 deletions tests/protocol/V5_4Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Bolt\protocol\Response;
use Bolt\protocol\ServerState;
use Bolt\protocol\V5_4;

/**
* Class V5_4Test
*
* @author Michal Stefanak
* @link https://github.com/neo4j-php/Bolt
* @package Bolt\tests\protocol
*/
class V5_4Test extends \Bolt\tests\protocol\ATest
{
public function test__construct(): V5_4
{
$cls = new V5_4(1, $this->mockConnection(), new \Bolt\protocol\ServerState());
$this->assertInstanceOf(V5_4::class, $cls);
$cls->serverState->expectedServerStateMismatchCallback = function (string $current, array $expected) {
$this->markTestIncomplete('Server in ' . $current . ' state. Expected ' . implode(' or ', $expected) . '.');
};
return $cls;
}

/**
* @depends test__construct
*/
public function testTelemetry(V5_4 $cls): void
{
// todo
}
}