\triagens\ArangoDbConnection

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.

Summary

Methods
Properties
Constants
__construct()
__destruct()
getOption()
get()
post()
put()
head()
patch()
delete()
parseResponse()
getVersion()
getClientVersion()
stopCaptureBatch()
getActiveBatch()
setActiveBatch()
setCaptureBatch()
setBatchRequest()
isInBatchCaptureMode()
getBatches()
detect_utf()
check_encoding()
json_encode_wrapper()
setDatabase()
getDatabase()
$_apiVersion
No constants found
No protected methods found
No protected properties found
N/A
getHandle()
executeRequest()
doBatch()
$_options
$_handle
$_useKeepAlive
$_batches
$_activeBatch
$_captureBatch
$_batchRequest
$_database
N/A

Properties

$_apiVersion

$_apiVersion : string

Api Version

Type

string

$_options

$_options : array

Connection options

Type

array

$_handle

$_handle : resource

Connection handle, used in case of keep-alive

Type

resource

$_useKeepAlive

$_useKeepAlive : boolean

Flag if keep-alive connections are used

Type

boolean

$_batches

$_batches : array

Batches Array

Type

array

$_activeBatch

$_activeBatch : array

$_activeBatch object

Type

array

$_captureBatch

$_captureBatch : boolean

$_captureBatch boolean

Type

boolean

$_batchRequest

$_batchRequest : boolean

$_batchRequest boolean

Type

boolean

$_database

$_database : string

$_database string

Type

string

Methods

__construct()

__construct(array $options) : \triagens\ArangoDb\Connection

Set up the connection object, validate the options provided

Parameters

array $options
  • initial connection options

Throws

\triagens\ArangoDb\Exception

Returns

\triagens\ArangoDb\Connection

__destruct()

__destruct() : void

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

getOption()

getOption(string $name) : mixed

Get an option set for the connection

Parameters

string $name
  • name of option

Throws

\triagens\ArangoDb\ClientException

Returns

mixed

get()

get(string $url, array $customerHeader) : \triagens\ArangoDb\HttpResponse

Issue an HTTP GET request

Parameters

string $url
  • GET URL
array $customerHeader

Throws

\triagens\ArangoDb\Exception

Returns

\triagens\ArangoDb\HttpResponse

post()

post(string $url, string $data) : \triagens\ArangoDb\HttpResponse

Issue an HTTP POST request with the data provided

Parameters

string $url
  • POST URL
string $data
  • body to post

Throws

\triagens\ArangoDb\Exception

Returns

\triagens\ArangoDb\HttpResponse

put()

put(string $url, string $data) : \triagens\ArangoDb\HttpResponse

Issue an HTTP PUT request with the data provided

Parameters

string $url
  • PUT URL
string $data
  • body to post

Throws

\triagens\ArangoDb\Exception

Returns

\triagens\ArangoDb\HttpResponse

head()

head(string $url, array $customerHeader) : \triagens\ArangoDb\HttpResponse

Issue an HTTP Head request with the data provided

Parameters

string $url
  • PUT URL
array $customerHeader

Throws

\triagens\ArangoDb\Exception

Returns

\triagens\ArangoDb\HttpResponse

patch()

patch(string $url, string $data) : \triagens\ArangoDb\HttpResponse

Issue an HTTP PATCH request with the data provided

Parameters

string $url
  • PATCH URL
string $data
  • patch body

Throws

\triagens\ArangoDb\Exception

Returns

\triagens\ArangoDb\HttpResponse

delete()

delete(string $url) : \triagens\ArangoDb\HttpResponse

Issue an HTTP DELETE request with the data provided

Parameters

string $url
  • DELETE URL

Throws

\triagens\ArangoDb\Exception

Returns

\triagens\ArangoDb\HttpResponse

parseResponse()

parseResponse(\triagens\ArangoDb\HttpResponse $response) : \triagens\ArangoDb\HttpResponse

Parse the response return the body values as an assoc array

Parameters

\triagens\ArangoDb\HttpResponse $response
  • the response as supplied by the server

Throws

\triagens\ArangoDb\Exception

Returns

\triagens\ArangoDb\HttpResponse

getVersion()

getVersion() : string

Get the client version (alias for getClientVersion)

Returns

string

getClientVersion()

getClientVersion() : string

Get the client version

Returns

string

stopCaptureBatch()

stopCaptureBatch() : \triagens\ArangoDb\Batch

Stop capturing commands

Returns

\triagens\ArangoDb\Batch
  • Returns the active batch object

getActiveBatch()

getActiveBatch() : \triagens\ArangoDb\Batch

returns the active batch

Returns

\triagens\ArangoDb\Batch

active batch

setActiveBatch()

setActiveBatch(\triagens\ArangoDb\Batch $batch) : \triagens\ArangoDb\Batch

Sets the active Batch for this connection

Parameters

\triagens\ArangoDb\Batch $batch
  • Sets the given batch as active

Returns

\triagens\ArangoDb\Batch

active batch

setCaptureBatch()

setCaptureBatch(boolean $state)

Sets the batch capture state (true, if capturing)

Parameters

boolean $state

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

setBatchRequest()

setBatchRequest(boolean $state)

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

Parameters

boolean $state

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

isInBatchCaptureMode()

isInBatchCaptureMode() : boolean

Returns true if this connection is in Batch-Capture mode

Returns

boolean —

returns the active batch

getBatches()

getBatches()

returns the active batch

detect_utf()

detect_utf(array $string) : boolean

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

It only checks for printable characters.

Parameters

array $string

the data to check

Returns

boolean —

true if string is UTF-8, false if not

check_encoding()

check_encoding(array $data)

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

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

Parameters

array $data

the data to check

Throws

\triagens\ArangoDb\ClientException

json_encode_wrapper()

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

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

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

mixed $data

the data to encode

mixed $options

the options for the json_encode() call

Returns

string —

the result of the json_encode

setDatabase()

setDatabase(string $database)

Set the database to use with this connection

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

string $database

the database to use

getDatabase()

getDatabase() : string

Get the database that is currently used with this connection

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

Returns

string

getHandle()

getHandle() : resource

Get a connection handle

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

Throws

\triagens\ArangoDb\ClientException

Returns

resource —
  • connection handle

executeRequest()

executeRequest(string $method, string $url, string $data, array $customerHeader) : \triagens\ArangoDb\HttpResponse

Execute an HTTP request and return the results

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

string $method
  • HTTP request method
string $url
  • HTTP URL
string $data
  • data to post in body
array $customerHeader
  • any arry containing header elements

Throws

\triagens\ArangoDb\Exception

Returns

\triagens\ArangoDb\HttpResponse

doBatch()

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

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

Parameters

mixed $method
  • The method of the request (GET, POST...)
string $request
  • 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 doesn't return anything, and

Returns

mixed —

Batchpart or null if not in batch capturing mode