Class Brightzone\GremlinDriver\Connection

InheritanceBrightzone\GremlinDriver\Connection

Gremlin-server PHP Driver client Connection class

Example of basic use:

$connection = new Connection(['host' => 'localhost']);
$connection->open();
$resultSet = $connection->send('g.V'); //returns array with results

Some more customising of message to send can be done with the message object

$connection = new Connection(['host' => 'localhost']);
$connection->open();
$connection->message->gremlin = 'g.V';
$connection->send();

See Message for more details

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$aliases array Aliases to be used for this connection. Brightzone\GremlinDriver\Connection
$emptySet boolean Whether or not the driver should return empty result sets as an empty array (the default behavior is to propagate the exception from the server - yes the server throws exceptions on empty result sets. Brightzone\GremlinDriver\Connection
$graph string The graph to use. Brightzone\GremlinDriver\Connection
$host string Contains the host information required to connect to the database. Brightzone\GremlinDriver\Connection
$message Brightzone\GremlinDriver\Message Message object Brightzone\GremlinDriver\Connection
$password string The password for establishing DB connection. Brightzone\GremlinDriver\Connection
$port string Contains port information to connect to the database Default : 8182 Brightzone\GremlinDriver\Connection
$retryAttempts integer The number of attempts before total failure Brightzone\GremlinDriver\Connection
$retryStrategy string The strategy to use for retry Brightzone\GremlinDriver\Connection
$saslMechanism string Which sasl mechanism to use for authentication. Brightzone\GremlinDriver\Connection
$ssl boolean|array Whether or not we're using ssl. Brightzone\GremlinDriver\Connection
$timeout float Timeout to use for connection to Rexster. Brightzone\GremlinDriver\Connection
$username string The username for establishing DB connection. Brightzone\GremlinDriver\Connection

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$_inTransaction boolean Tells us if we're inside a transaction Brightzone\GremlinDriver\Connection
$_sessionUuid string The session ID for this connection. Brightzone\GremlinDriver\Connection
$_socket resource Rexpro socket connection Brightzone\GremlinDriver\Connection

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__construct() Overloading constructor to instantiate a Message instance and provide it with a default serializer. Brightzone\GremlinDriver\Connection
__destruct() Make sure the session is closed on destruction of the object Brightzone\GremlinDriver\Connection
close() Close connection to server This closes the current session on the server then closes the socket Brightzone\GremlinDriver\Connection
closeSession() Closes an open session if it exists You can use this to close open sessions on the server end. This allows to free up threads on the server end. Brightzone\GremlinDriver\Connection
getSession() Retrieve the current session UUID Brightzone\GremlinDriver\Connection
inTransaction() Return whether or not this cnnection object is in transaction mode Brightzone\GremlinDriver\Connection
isConnected() Checks if the socket is currently open Brightzone\GremlinDriver\Connection
isSessionOpen() Checks if the session is currently open Brightzone\GremlinDriver\Connection
open() Connects to socket and starts a session with gremlin-server Brightzone\GremlinDriver\Connection
run() Constructs and sends a Message entity or gremlin script to the server without waiting for a response. Brightzone\GremlinDriver\Connection
send() Constructs and sends a Message entity or gremlin script to the server and then waits for response Brightzone\GremlinDriver\Connection
transaction() Run a callback in a transaction. Brightzone\GremlinDriver\Connection
transactionStart() Start a transaction. Brightzone\GremlinDriver\Connection
transactionStop() End a transaction Brightzone\GremlinDriver\Connection

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
authenticate() Builds an authentication message when challenged by the server Once you respond and authenticate you will receive the response for the request you made prior to the challenge Brightzone\GremlinDriver\Connection
makeHandshake() Make Original handshake with the server Brightzone\GremlinDriver\Connection
socketGetUnpack() Recieves binary data over the socket and parses it Brightzone\GremlinDriver\Connection

Property Details

$_inTransaction protected property

Tells us if we're inside a transaction

protected boolean $_inTransaction FALSE
$_sessionUuid protected property

The session ID for this connection. Session ID allows us to access variable bindings made in previous requests. It is binary data

protected string $_sessionUuid null
$_socket protected property

Rexpro socket connection

protected resource $_socket null
$aliases public property

Aliases to be used for this connection. Allows users to set up whichever character on the db end such as "g" and reference it with another alias.

public array $aliases = []
$emptySet public property

Whether or not the driver should return empty result sets as an empty array (the default behavior is to propagate the exception from the server - yes the server throws exceptions on empty result sets.)

public boolean $emptySet FALSE
$graph public property

The graph to use.

public string $graph null
$host public property

Contains the host information required to connect to the database.

Default: localhost

public string $host 'localhost'
$message public property

Message object

$password public property

The password for establishing DB connection. Defaults to NULL.

public string $password null
$port public property

Contains port information to connect to the database

Default : 8182

public string $port 8182
$retryAttempts public property

The number of attempts before total failure

$retryStrategy public property

The strategy to use for retry

public string $retryStrategy 'linear'
$saslMechanism public property

Which sasl mechanism to use for authentication. Can be either PLAIN or GSSAPI. This is ignored by gremlin-server by default but some custom server implementations may use this

public string $saslMechanism "PLAIN"
$ssl public property

Whether or not we're using ssl. If an array is set it should correspond to a

 stream_context_create() array.
public boolean|array $ssl FALSE
$timeout public property

Timeout to use for connection to Rexster. If not set the timeout set in php.ini will be used:

 ini_get("default_socket_timeout")
public float $timeout null
$username public property

The username for establishing DB connection. Defaults to NULL.

public string $username null

Method Details

__construct() public method

Overloading constructor to instantiate a Message instance and provide it with a default serializer.

public void __construct ( $options = [] )
$options array

The class options

__destruct() public method

Make sure the session is closed on destruction of the object

public void __destruct ( )
authenticate() protected method

Builds an authentication message when challenged by the server Once you respond and authenticate you will receive the response for the request you made prior to the challenge

protected array authenticate ( )
return array

The server response.

close() public method

Close connection to server This closes the current session on the server then closes the socket

public boolean close ( )
return boolean

TRUE on success

closeSession() public method

Closes an open session if it exists You can use this to close open sessions on the server end. This allows to free up threads on the server end.

public void closeSession ( )
getSession() public method

Retrieve the current session UUID

public string getSession ( )
return string

Current UUID

inTransaction() public method

Return whether or not this cnnection object is in transaction mode

public boolean inTransaction ( )
return boolean

TRUE if in transaction, FALSE otherwise

isConnected() public method

Checks if the socket is currently open

public boolean isConnected ( )
return boolean

TRUE if it is open FALSE if not

isSessionOpen() public method

Checks if the session is currently open

public boolean isSessionOpen ( )
return boolean

TRUE if it's open is FALSE if not.

makeHandshake() protected method

Make Original handshake with the server

protected boolean makeHandshake ( $origin FALSE )
$origin boolean

Whether or not to provide the origin header. currently unsupported

return boolean

TRUE on success FALSE on failure

open() public method

Connects to socket and starts a session with gremlin-server

public boolean open ( )
return boolean

TRUE on success FALSE on error

run() public method

Constructs and sends a Message entity or gremlin script to the server without waiting for a response.

public void run ( $msg NULL, $processor '', $op 'eval', $args = [], $expectResponse TRUE )
$msg mixed

(Message|String|NULL) the message to send, NULL means use $this->message

$processor string

OpProcessor to use.

$op string

Operation to run against opProcessor.

$args array

Arguments to overwrite.

$expectResponse boolean

Arguments to overwrite.

throws Exception
send() public method

Constructs and sends a Message entity or gremlin script to the server and then waits for response

public array send ( $msg NULL, $processor '', $op 'eval', $args = [] )
$msg mixed

(Message|String|NULL) the message to send, NULL means use $this->message

$processor string

OpProcessor to use.

$op string

Operation to run against opProcessor.

$args array

Arguments to overwrite.

return array

Reply from server.

throws Brightzone\GremlinDriver\ServerException
socketGetUnpack() protected method

Recieves binary data over the socket and parses it

protected array socketGetUnpack ( )
return array

PHP native result from server

transaction() public method

Run a callback in a transaction.

The advantage of this is that it allows for fail-retry strategies

public mixed transaction ( callable $callback, $params = [] )
$callback callable

The code to execute within the scope of this transaction

$params array

The params to pass to the callback

return mixed

The return value of the provided callable

transactionStart() public method

Start a transaction.

Transaction start only makes sens if committing is set to manual on the server. Manual is not the default setting so we will assume a session UUID must exists

public boolean transactionStart ( )
return boolean

TRUE on success FALSE on failure

transactionStop() public method

End a transaction

public boolean transactionStop ( $success TRUE )
$success boolean

Should the transaction commit or revert changes

return boolean

TRUE on success FALSE on failure.