Skip to content

Commit

Permalink
v5.1 (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanak-michal authored Mar 13, 2023
1 parent af9d8e6 commit 77425e0
Show file tree
Hide file tree
Showing 25 changed files with 361 additions and 228 deletions.
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.1', '5.2', '5.3', '5.4']
neo4j-version: ['5.1', '5.2', '5.3', '5.4', '5.5']
php-version: ['8.0', '8.1', '8.2']

services:
Expand Down
2 changes: 1 addition & 1 deletion src/Bolt.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class Bolt

public function __construct(private IConnection $connection)
{
$this->setProtocolVersions(5, 4.4);
$this->setProtocolVersions(5.1, 5, 4.4);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/protocol/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Response
public const MESSAGE_ROLLBACK = 'ROLLBACK';
public const MESSAGE_ROUTE = 'ROUTE';
public const MESSAGE_ACK_FAILURE = 'ACK_FAILURE';
public const MESSAGE_LOGON = 'LOGON';
public const MESSAGE_LOGOFF = 'LOGOFF';

public const SIGNATURE_SUCCESS = 0x70; //112
public const SIGNATURE_FAILURE = 0x7F; //127
Expand Down
8 changes: 7 additions & 1 deletion src/protocol/ServerState.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ class ServerState
*/
public const INTERRUPTED = 'INTERRUPTED';

/**
* Connection has been established and metadata has been sent back from the HELLO message or a LOGOFF message was received whilst in ready state. Ready to accept a LOGON message with authentication information.
*/
public const UNAUTHENTICATED = 'UNAUTHENTICATED';

/**
* Internal pointer for current server state
*/
Expand All @@ -87,7 +92,8 @@ class ServerState
self::TX_READY,
self::TX_STREAMING,
self::FAILED,
self::INTERRUPTED
self::INTERRUPTED,
self::UNAUTHENTICATED
];

/**
Expand Down
33 changes: 33 additions & 0 deletions src/protocol/V5_1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Bolt\protocol;

/**
* Class Protocol version 5.1
*
* @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_1 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\HelloMessage;
use \Bolt\protocol\v5_1\LogonMessage;
use \Bolt\protocol\v5_1\LogoffMessage;
}
16 changes: 2 additions & 14 deletions src/protocol/v1/ResetMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,7 @@

namespace Bolt\protocol\v1;

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

trait ResetMessage
Expand All @@ -26,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
public function reset(): V1|V2|V3|V4|V4_1|V4_2|V4_3|V4_4|V5|V5_1
{
$this->write($this->packer->pack(0x0F));
$this->pipelinedMessages[] = __FUNCTION__;
Expand Down
14 changes: 2 additions & 12 deletions src/protocol/v3/BeginMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@

namespace Bolt\protocol\v3;

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

trait BeginMessage
Expand All @@ -24,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
public function begin(array $extra = []): V3|V4|V4_1|V4_2|V4_3|V4_4|V5|V5_1
{
$this->serverState->is(ServerState::READY);
$this->write($this->packer->pack(0x11, (object)$extra));
Expand Down
14 changes: 2 additions & 12 deletions src/protocol/v3/CommitMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@

namespace Bolt\protocol\v3;

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

trait CommitMessage
Expand All @@ -24,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
public function commit(): V3|V4|V4_1|V4_2|V4_3|V4_4|V5|V5_1
{
$this->serverState->is(ServerState::TX_READY, ServerState::TX_STREAMING);
$this->write($this->packer->pack(0x12));
Expand Down
14 changes: 2 additions & 12 deletions src/protocol/v3/RollbackMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@

namespace Bolt\protocol\v3;

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

trait RollbackMessage
Expand All @@ -24,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
public function rollback(): V3|V4|V4_1|V4_2|V4_3|V4_4|V5|V5_1
{
$this->serverState->is(ServerState::TX_READY, ServerState::TX_STREAMING);
$this->write($this->packer->pack(0x13));
Expand Down
14 changes: 2 additions & 12 deletions src/protocol/v3/RunMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@

namespace Bolt\protocol\v3;

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

trait RunMessage
Expand All @@ -24,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
public function run(string $query, array $parameters = [], array $extra = []): V3|V4|V4_1|V4_2|V4_3|V4_4|V5|V5_1
{
$this->serverState->is(ServerState::READY, ServerState::TX_READY, ServerState::STREAMING, ServerState::TX_STREAMING);

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

namespace Bolt\protocol\v4;

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

trait DiscardMessage
Expand All @@ -24,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
public function discard(array $extra = []): V4|V4_1|V4_2|V4_3|V4_4|V5|V5_1
{
$this->serverState->is(ServerState::READY, ServerState::TX_READY, ServerState::STREAMING, ServerState::TX_STREAMING);

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

namespace Bolt\protocol\v4;

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

trait PullMessage
Expand All @@ -24,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
public function pull(array $extra = []): V4|V4_1|V4_2|V4_3|V4_4|V5|V5_1
{
$this->serverState->is(ServerState::READY, ServerState::TX_READY, ServerState::STREAMING, ServerState::TX_STREAMING);

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

namespace Bolt\protocol\v4_4;

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

trait RouteMessage
Expand All @@ -20,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
public function route(array $routing, array $bookmarks = [], array $extra = []): V4_4|V5|V5_1
{
$this->serverState->is(ServerState::READY);
$this->write($this->packer->pack(0x66, (object)$routing, $bookmarks, (object)$extra));
Expand Down
38 changes: 38 additions & 0 deletions src/protocol/v5_1/HelloMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Bolt\protocol\v5_1;

use Bolt\protocol\{ServerState, Response};
use Bolt\error\BoltException;

trait HelloMessage
{
/**
* Send HELLO message
* The HELLO message request the connection to be authorized for use with the remote database.
*
* @link https://www.neo4j.com/docs/bolt/current/bolt/message/#messages-hello
* @throws BoltException
*/
public function hello(array $extra = []): Response
{
$this->serverState->is(ServerState::CONNECTED);

if (empty($extra['user_agent']))
$extra['user_agent'] = \Bolt\helpers\Auth::$defaultUserAgent;
if (isset($extra['routing']) && is_array($extra['routing']))
$extra['routing'] = (object)$extra['routing'];

$this->write($this->packer->pack(0x01, (object)$extra));
$content = $this->read($signature);

if ($signature == Response::SIGNATURE_SUCCESS) {
$this->serverState->set(ServerState::UNAUTHENTICATED);
} elseif ($signature == Response::SIGNATURE_FAILURE) {
$this->connection->disconnect();
$this->serverState->set(ServerState::DEFUNCT);
}

return new Response(Response::MESSAGE_HELLO, $signature, $content);
}
}
32 changes: 32 additions & 0 deletions src/protocol/v5_1/LogoffMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Bolt\protocol\v5_1;

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

trait LogoffMessage
{
/**
* Send LOGOFF message
* A LOGOFF message logs off the currently authenticated user. The connection is then ready for another LOGON message.
*
* @link https://www.neo4j.com/docs/bolt/current/bolt/message/#messages-logoff
* @throws BoltException
*/
public function logoff(): Response
{
$this->serverState->is(ServerState::READY);
$this->write($this->packer->pack(0x6B));
$content = $this->read($signature);
if ($signature == Response::SIGNATURE_SUCCESS) {
$this->serverState->set(ServerState::UNAUTHENTICATED);
} else {
$this->connection->disconnect();
$this->serverState->set(ServerState::DEFUNCT);
}
return new Response(Response::MESSAGE_LOGOFF, $signature, $content);
}
}
Loading

0 comments on commit 77425e0

Please sign in to comment.