A document handler that fetches documents from the server and
persists them on the server. It does so by issuing the
appropriate HTTP requests to the server.
package |
ArangoDBClient |
since |
0.2 |
inherited_from |
\ArangoDBClient\Handler |
Methods
Construct a new handler
__construct(\ArangoDBClient\Connection $connection)
Inherited
Parameters
$connection
\ArangoDBClient\Connection
Get a single document from a collection
get(string $collection, mixed $documentId, array $options = array()
) : \ArangoDBClient\Document
Alias method for getById()
Parameters
$collection
string
- collection id as a string or number
$options
array
- optional, array of options
Options are :
- '_includeInternals' - true to include the internal attributes. Defaults to false
- '_ignoreHiddenAttributes' - true to show hidden attributes. Defaults to false
- 'revision' - the documents revision
- 'ifMatch' - boolean if given revision should match or not
Exceptions
\ArangoDBClient\Exception |
|
Returns
\ArangoDBClient\Document
- the document fetched from the server
Get a single document from a collection
getById(string $collection, mixed $documentId, array $options = array()
) : \ArangoDBClient\Document
This will throw if the document cannot be fetched from the server.
Parameters
$collection
string
- collection id as a string or number
$options
array
- optional, array of options
Options are :
- '_includeInternals' - true to include the internal attributes. Defaults to false
- '_ignoreHiddenAttributes' - true to show hidden attributes. Defaults to false
- 'ifMatch' - boolean if given revision should match or not
- 'revision' - The document is returned if it matches/not matches revision.
Exceptions
\ArangoDBClient\Exception |
|
Returns
\ArangoDBClient\Document
- the document fetched from the server
Gets information about a single documents from a collection
getHead(string $collection, mixed $documentId, string $revision = null
, boolean $ifMatch = null
) : array
This will throw if the document cannot be fetched from the server
Parameters
$collection
string
- collection id as a string or number.
$revision
string
- The document is returned if it matches/not matches revision.
$ifMatch
boolean
- boolean if given revision should match or not.
Exceptions
\ArangoDBClient\Exception |
|
Returns
array
- an array containing the complete header including the key httpCode.
Check if a document exists
has(string $collection, mixed $documentId) : boolean
This will call self::get() internally and checks if there
was an exception thrown which represents an 404 request.
Parameters
$collection
string
- collection id as a string or number
Exceptions
\ArangoDBClient\Exception |
When any other error than a 404 occurs |
Returns
boolean
insert a document into a collection
insert(mixed $collection, \ArangoDBClient\Document|array $document, array $options = array()
) : mixed
This will add the document to the collection and return the document's id
This will throw if the document cannot be saved
Parameters
$collection
mixed
- collection id as string or number
$document
\ArangoDBClient\Document
array
- the document to be added, can be passed as a document or an array
$options
array
- optional, array of options
Options are :
- 'createCollection' - create the collection if it does not yet exist.
- 'waitForSync' - if set to true, then all removal operations will instantly be synchronised to disk / If this is not specified, then the collection's default sync behavior will be applied.
- 'overwrite' - if set to true, will turn the insert into a replace operation if a document with the specified key already exists.
- 'returnNew' - if set to true, then the newly created document will be returned.
- 'returnOld' - if set to true, then the replaced document will be returned - useful only when using overwrite = true.
Exceptions
\ArangoDBClient\Exception |
|
Returns
mixed
- id of document created
Remove a document from a collection, identified by the document itself
remove(\ArangoDBClient\Document $document, array $options = array()
) : boolean
Parameters
$document
\ArangoDBClient\Document
$options
array
- optional, array of options
Options are :
- 'policy' - update policy to be used in case of conflict ('error', 'last' or NULL [use default])
- 'waitForSync' - can be used to force synchronisation of the document removal operation to disk even in case that the waitForSync flag had been disabled for the entire collection
Exceptions
\ArangoDBClient\Exception |
|
Returns
boolean
- always true, will throw if there is an error
Remove a document from a collection, identified by the collection id and document id
removeById(mixed $collection, mixed $documentId, mixed $revision = null
, array $options = array()
) : boolean
Parameters
$collection
mixed
- collection id as string or number
$documentId
mixed
- document id as string or number
$revision
mixed
- optional revision of the document to be deleted
$options
array
- optional, array of options
Options are :
- 'policy' - update policy to be used in case of conflict ('error', 'last' or NULL [use default])
- 'waitForSync' - can be used to force synchronisation of the document removal operation to disk even in case that the waitForSync flag had been disabled for the entire collection
Exceptions
\ArangoDBClient\Exception |
|
Returns
boolean
- always true, will throw if there is an error
Replace an existing document in a collection, identified by the document itself
replace(\ArangoDBClient\Document $document, array $options = array()
) : boolean
This will replace the document on the server
This will throw if the document cannot be replaced
If policy is set to error (locally or globally through the ConnectionOptions)
and the passed document has a _rev value set, the database will check
that the revision of the to-be-replaced document is the same as the one given.
Parameters
$document
\ArangoDBClient\Document
$options
array
- optional, array of options
Options are :
- 'policy' - replace policy to be used in case of conflict ('error', 'last' or NULL [use default])
- 'waitForSync' - can be used to force synchronisation of the document update operation to disk even in case that the waitForSync flag had been disabled for the entire collection
Exceptions
\ArangoDBClient\Exception |
|
Returns
boolean
- always true, will throw if there is an error
Replace an existing document in a collection, identified by collection id and document id
replaceById(mixed $collection, mixed $documentId, \ArangoDBClient\Document $document, array $options = array()
) : boolean
This will update the document on the server
This will throw if the document cannot be Replaced
If policy is set to error (locally or globally through the ConnectionOptions)
and the passed document has a _rev value set, the database will check
that the revision of the to-be-replaced document is the same as the one given.
Parameters
$collection
mixed
- collection id as string or number
$documentId
mixed
- document id as string or number
$document
\ArangoDBClient\Document
$options
array
- optional, array of options
Options are :
- 'policy' - update policy to be used in case of conflict ('error', 'last' or NULL [use default])
- 'waitForSync' - can be used to force synchronisation of the document replacement operation to disk even in case that the waitForSync flag had been disabled for the entire collection
Exceptions
\ArangoDBClient\Exception |
|
Returns
boolean
- always true, will throw if there is an error
Insert a document into a collection
save($collection, $document, array $options = array()
)
This is an alias for insert().
Parameters
$collection
$document
$options
Sets the document class to use
setDocumentClass(string $class) : \ArangoDBClient\DocumentClassable
Inherited
Parameters
$class
string
Document class to use
Returns
\ArangoDBClient\DocumentClassable
Sets the edge class to use
setEdgeClass(string $class) : \ArangoDBClient\DocumentClassable
Inherited
Parameters
$class
string
Edge class to use
Returns
\ArangoDBClient\DocumentClassable
Store a document to a collection
store(\ArangoDBClient\Document $document, mixed $collection = null
, array $options = array()
) : mixed
This is an alias/shortcut to save() and replace(). Instead of having to determine which of the 3 functions to use,
simply pass the document to store() and it will figure out which one to call.
This will throw if the document cannot be saved or replaced.
Parameters
$document
\ArangoDBClient\Document
- the document to be added, can be passed as a document or an array
$collection
mixed
- collection id as string or number
$options
array
- optional, array of options
Options are :
- 'createCollection' - create the collection if it does not yet exist.
- 'waitForSync' - if set to true, then all removal operations will instantly be synchronised to disk / If this is not specified, then the collection's default sync behavior will be applied.
Exceptions
\ArangoDBClient\Exception |
|
Returns
mixed
- id of document created
Update an existing document in a collection, identified by the including _id and optionally _rev in the patch document.
update(\ArangoDBClient\Document $document, array $options = array()
) : boolean
Attention - The behavior of this method has changed since version 1.1
This will update the document on the server
This will throw if the document cannot be updated
If policy is set to error (locally or globally through the ConnectionOptions)
and the passed document has a _rev value set, the database will check
that the revision of the document to-be-replaced is the same as the one given.
Parameters
$document
\ArangoDBClient\Document
- The patch document that will update the document in question
$options
array
- optional, array of options
Options are :
- 'policy' - update policy to be used in case of conflict ('error', 'last' or NULL [use default])
- 'keepNull' - can be used to instruct ArangoDB to delete existing attributes instead setting their values to null. Defaults to true (keep attributes when set to null)
- 'waitForSync' - can be used to force synchronisation of the document update operation to disk even in case that the waitForSync flag had been disabled for the entire collection
Exceptions
\ArangoDBClient\Exception |
|
Returns
boolean
- always true, will throw if there is an error
Update an existing document in a collection, identified by collection id and document id
Attention - The behavior of this method has changed since version 1.1
updateById(string $collection, mixed $documentId, \ArangoDBClient\Document $document, array $options = array()
) : boolean
This will update the document on the server
This will throw if the document cannot be updated
If policy is set to error (locally or globally through the ConnectionOptions)
and the passed document has a _rev value set, the database will check
that the revision of the document to-be-updated is the same as the one given.
Parameters
$collection
string
- collection id as string or number
$documentId
mixed
- document id as string or number
$document
\ArangoDBClient\Document
- patch document which contains the attributes and values to be updated
$options
array
- optional, array of options
Options are :
- 'policy' - update policy to be used in case of conflict ('error', 'last' or NULL [use default])
- 'keepNull' - can be used to instruct ArangoDB to delete existing attributes instead setting their values to null. Defaults to true (keep attributes when set to null)
- 'waitForSync' - can be used to force synchronisation of the document update operation to disk even in case that the waitForSync flag had been disabled for the entire collection
Exceptions
\ArangoDBClient\Exception |
|
Returns
boolean
- always true, will throw if there is an error
Intermediate function to call the createFromArray function from the right context
createFromArrayWithContext($data, $options) : \ArangoDBClient\Document
Parameters
$data
$options
Exceptions
\ArangoDBClient\ClientException |
|
Returns
\ArangoDBClient\Document
Return the connection object
getConnection() : \ArangoDBClient\Connection
Inherited
Returns
\ArangoDBClient\Connection
- the connection object
Return a connection option
This is a convenience function that calls json_encode_wrapper on the connection
getConnectionOption($optionName) : mixed
Inherited
Parameters
$optionName
- The option to return a value for
Exceptions
\ArangoDBClient\ClientException |
|
Returns
mixed
- the option's value
Helper function that runs through the options given and includes them into the parameters array given.
includeOptionsInBody(array $options, array $body, array $includeArray = array()
) : array
Inherited
Only options that are set in $includeArray will be included.
This is only for options that are to be sent to the ArangoDB server in a json body(like 'limit', 'skip', etc...) .
Parameters
$options
array
- The options array that holds the options to include in the parameters
$body
array
- The array into which the options will be included.
$includeArray
array
- The array that defines which options are allowed to be included, and what their default value is. for example: 'waitForSync'=>true
Returns
array
$params - array of parameters for use in a url
Return a json encoded string for the array passed.
json_encode_wrapper(array $body) : string
Inherited
This is a convenience function that calls json_encode_wrapper on the connection
Parameters
$body
array
- The body to encode into json
Exceptions
\ArangoDBClient\ClientException |
|
Returns
string
- json string of the body that was passed
lazyCreateCollection()
lazyCreateCollection(mixed $collection, array $options)
Parameters
$collection
mixed
collection name or id
$options
array
- optional, array of options
Options are :
- 'createCollectionType' - "document" or 2 for document collection
- "edge" or 3 for edge collection
- 'waitForSync' - if set to true, then all removal operations will instantly be synchronised to disk / If this is not specified, then the collection's default sync behavior will be applied.
Turn a value into a collection name
makeCollection(mixed $value) : string
Inherited
Parameters
$value
mixed
- document, collection or string
Exceptions
\ArangoDBClient\ClientException |
|
Returns
string
- collection name
Helper function to get a document id from a document or a document id value
getDocumentId(mixed $document) : mixed
Parameters
$document
mixed
- document id OR document to be updated
Exceptions
\ArangoDBClient\ClientException |
|
Returns
mixed
- document id, will throw if there is an error
Helper function to get a document id from a document or a document id value
getRevision(mixed $document) : mixed
Parameters
$document
mixed
- document id OR document to be updated
Exceptions
\ArangoDBClient\ClientException |
|
Returns
mixed
- document id, will throw if there is an error
Properties
Document class to use
$_documentClass : string
Default
'\ArangoDBClient\Document'
Edge class to use
$_edgeClass : string
Default
'\ArangoDBClient\Edge'
Connection object
$_connection
Constants
documents array index
ENTRY_DOCUMENTS = 'documents'
collection parameter
OPTION_COLLECTION = 'collection'
example parameter
OPTION_EXAMPLE = 'example'
overwrite option
OPTION_OVERWRITE = 'overwrite'
option for returning the new document
OPTION_RETURN_NEW = 'returnNew'
option for returning the old document
OPTION_RETURN_OLD = 'returnOld'