Provides access to the ArangoDB server

As all access is done using HTTP, we do not need to establish a persistent connection and keep its state.
Instead, connections are established on the fly for each request and are destroyed afterwards.

package ArangoDBClient
since 0.2

 Methods

Set up the connection object, validate the options provided

__construct(array $options) 

Parameters

$options

array
  • initial connection options

Exceptions

\ArangoDBClient\Exception

Close existing connection handle if a keep-alive connection was used

__destruct() : void

This function checks that the encoding of the keys and values of the array are utf-8, recursively.

check_encoding(array $data) 
Static

It will raise an exception if it encounters wrong encoded strings.

Parameters

$data

array

the data to check

Exceptions

\ArangoDBClient\ClientException

Issue an HTTP DELETE request with the data provided

delete(string $url, array $customHeaders = array(), string $data = '') : \ArangoDBClient\HttpResponse

Parameters

$url

string
  • DELETE URL

$customHeaders

array

$data

string
  • delete body

Exceptions

\ArangoDBClient\Exception

Returns

\ArangoDBClient\HttpResponse

This function checks that the encoding of a string is utf.

detect_utf(array $string) : boolean
Static

It only checks for printable characters.

Parameters

$string

array

the data to check

Returns

booleantrue if string is UTF-8, false if not

Issue an HTTP GET request

get(string $url, array $customHeaders = array()) : \ArangoDBClient\HttpResponse

Parameters

$url

string
  • GET URL

$customHeaders

array

Exceptions

\ArangoDBClient\Exception

Returns

\ArangoDBClient\HttpResponse

returns the active batch

getActiveBatch() : \ArangoDBClient\Batch

Returns

\ArangoDBClient\Batchactive batch

returns the active batch

getBatches() 

Returns the current endpoint we are currently connected to (or, if no connection has been established yet, the next endpoint that we will connect to)

getCurrentEndpoint() : string

Returns

string- the current endpoint that we are connected to

Get the database to use with this connection, for example: 'my_database'

getDatabase() : string

Returns

string

Get an option set for the connection

getOption(string $name) : mixed

Parameters

$name

string
  • name of option

Exceptions

\ArangoDBClient\ClientException

Returns

mixed

Get the options set for the connection

getOptions() : \ArangoDBClient\ConnectionOptions

Returns

\ArangoDBClient\ConnectionOptions

Issue an HTTP Head request with the data provided

head(string $url, array $customHeaders = array()) : \ArangoDBClient\HttpResponse

Parameters

$url

string
  • PUT URL

$customHeaders

array

Exceptions

\ArangoDBClient\Exception

Returns

\ArangoDBClient\HttpResponse

Returns true if this connection is in Batch-Capture mode

isInBatchCaptureMode() : boolean

Returns

boolean

This is a json_encode() wrapper that also checks if the data is utf-8 conform.

json_encode_wrapper(mixed $data, mixed $options = 0) : string

internally it calls the check_encoding() method. If that method does not throw an Exception, this method will happily return the json_encoded data.

Parameters

$data

mixed

the data to encode

$options

mixed

the options for the json_encode() call

Exceptions

\ArangoDBClient\ClientException

Returns

stringthe result of the json_encode

Parse the response return the body values as an assoc array

parseResponse(\ArangoDBClient\HttpResponse $response) : \ArangoDBClient\HttpResponse

Parameters

$response

\ArangoDBClient\HttpResponse
  • the response as supplied by the server

Exceptions

\ArangoDBClient\Exception

Returns

\ArangoDBClient\HttpResponse

Issue an HTTP PATCH request with the data provided

patch(string $url, string $data, array $customHeaders = array()) : \ArangoDBClient\HttpResponse

Parameters

$url

string
  • PATCH URL

$data

string
  • patch body

$customHeaders

array

Exceptions

\ArangoDBClient\Exception

Returns

\ArangoDBClient\HttpResponse

Issue an HTTP POST request with the data provided

post(string $url, string $data, array $customHeaders = array()) : \ArangoDBClient\HttpResponse

Parameters

$url

string
  • POST URL

$data

string
  • body to post

$customHeaders

array

Exceptions

\ArangoDBClient\Exception

Returns

\ArangoDBClient\HttpResponse

Issue an HTTP PUT request with the data provided

put(string $url, string $data, array $customHeaders = array()) : \ArangoDBClient\HttpResponse

Parameters

$url

string
  • PUT URL

$data

string
  • body to post

$customHeaders

array

Exceptions

\ArangoDBClient\Exception

Returns

\ArangoDBClient\HttpResponse

Sets the active Batch for this connection

setActiveBatch(\ArangoDBClient\Batch $batch) : \ArangoDBClient\Batch

Parameters

$batch

\ArangoDBClient\Batch
  • Sets the given batch as active

Returns

\ArangoDBClient\Batchactive batch

Sets connection into Batch-request mode. This is needed for some operations to act differently when in this mode.

setBatchRequest(boolean $state) 

Parameters

$state

boolean

sets the connection state to batch request, meaning it is currently doing a batch request.

Sets the batch capture state (true, if capturing)

setCaptureBatch(boolean $state) 

Parameters

$state

boolean

true to turn on capture batch mode, false to turn it off

Set the database to use with this connection

setDatabase(string $database) 

Sets the database to use with this connection, for example: 'my_database'
Further calls to the database will be addressed to the given database.

Parameters

$database

string

the database to use

Set an option set for the connection

setOption(string $name, string $value) 

Parameters

$name

string
  • name of option

$value

string
  • value of option

Exceptions

\ArangoDBClient\ClientException

Stop capturing commands

stopCaptureBatch() : \ArangoDBClient\Batch

Returns

\ArangoDBClient\Batch- Returns the active batch object

Test if a connection can be made using the specified connection options, i.e. endpoint (host/port), username, password

test() : boolean

Returns

boolean- true if the connection succeeds, false if not

Close an existing connection handle

closeHandle() : void

This is a helper function to executeRequest that captures requests if we're in batch mode

doBatch(mixed $method, string $request) : mixed

Parameters

$method

mixed
  • The method of the request (GET, POST...)

$request

string
  • The request to process

This checks if we're in batch mode and returns a placeholder object, since we need to return some object that is expected by the caller. if we're not in batch mode it does not return anything, and

Exceptions

\ArangoDBClient\ClientException

Returns

mixedBatchpart or null if not in batch capturing mode

Execute an HTTP request and return the results

executeRequest(string $method, string $url, string $data, array $customHeaders = array()) : \ArangoDBClient\HttpResponse

This function will throw if no connection to the server can be established or if there is a problem during data exchange with the server.

will restore it.

Parameters

$method

string
  • HTTP request method

$url

string
  • HTTP URL

$data

string
  • data to post in body

$customHeaders

array
  • any array containing header elements

Exceptions

\ArangoDBClient\Exception

Returns

\ArangoDBClient\HttpResponse

Get a connection handle

getHandle() : resource

If keep-alive connections are used, the handle will be stored and re-used

Exceptions

\ArangoDBClient\ClientException
\ArangoDBClient\ConnectException

Returns

resource- connection handle

Execute the specified callback, and try again if it fails because the target server is not available. In this case, try again with failing over to an alternative server (the new leader) until the maximum number of failover attempts have been made

handleFailover(mixed $cb) : \ArangoDBClient\HttpResponse

Parameters

$cb

mixed
  • the callback function to execute

Exceptions

\ArangoDBClient\Exception - either a ConnectException or a FailoverException or an Exception produced by the callback function

Returns

\ArangoDBClient\HttpResponse

Calls the notification callback function to inform to make the client application aware of some failure so it can do something appropriate (e.g. logging)

notify($message) : void

Parameters

$message

Recalculate the static HTTP header string used for all HTTP requests in this connection

updateHttpHeader() 

 Properties

 

$_activeBatch object

$_activeBatch : \ArangoDBClient\Batch

Default

 

Pre-assembled base URL for the current database This is pre-calculated when connection options are set/changed, to avoid calculation of the same base URL in each request done via the connection

$_baseUrl : string

Default

''
 

$_batchRequest boolean

$_batchRequest : boolean

Default

false
 

Batches Array

$_batches : array

Default

array()
 

$_captureBatch boolean

$_captureBatch : boolean

Default

false
 

$_database string

$_database : string

Default

''
 

Connection handle, used in case of keep-alive

$_handle : resource

Default

 

Pre-assembled HTTP headers string for connection This is pre-calculated when connection options are set/changed, to avoid calculation of the same HTTP header values in each request done via the connection

$_httpHeader : string

Default

''
 

Connection options

$_options : array

Default

 

Flag if keep-alive connections are used

$_useKeepAlive : boolean

Default