Oihana PHP Arango

Document

Read onlyYes

Immutable value object wrapping a single ArangoDB document.

Exposes lightweight accessors for the three reserved ArangoDB attributes (_key, _id, _rev) along with a generic get() / has() API on the rest of the payload, and a toArray() escape hatch for callers that want to interoperate with array-based code paths (query builders, JSON encoders, oihana\reflect\Reflection::hydrate(), …).

Construction is fire-and-forget: the document is filled in from the server response and never mutated locally. To "modify" a document, send an update request through the parent Database and construct a new instance from the response.

Example:

$document = new Document( [ Schema::_KEY => 'abc' , Schema::_ID => 'users/abc' , 'name' => 'Marc' ] ) ;

$document->getKey() ; // 'abc'
$document->getId()  ; // 'users/abc'
$document->get( 'name' ) ; // 'Marc'
$document->isNew() ; // false

// Hydrate into a typed DTO (delegated to oihana/php-reflect):
$dto = ( new \oihana\reflect\Reflection() )->hydrate( $document->toArray() , UserDto::class ) ;
Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Properties

$data  : array<string|int, mixed>

Methods

__construct()  : mixed
get()  : mixed
Returns the value of a single field on the document, or `$default` when the field is absent.
getId()  : string|null
Returns the ArangoDB document identifier (`_id`), or null when the document has not been persisted yet.
getKey()  : string|null
Returns the ArangoDB document key (`_key`), or null when the document has not been persisted yet.
getRev()  : string|null
Returns the document revision (`_rev`) — read-only, managed by the server. Null when the document has not been persisted yet.
has()  : bool
Returns true when the document has the given field (even when the stored value is null).
isNew()  : bool
Returns true when the document has not been persisted yet (no `_key` assigned by the server).
toArray()  : array<string, mixed>
Returns the underlying raw data array (including reserved attributes).

Properties

$data

public array<string|int, mixed> $data = []

Methods

__construct()

public __construct([array<string, mixed> $data = [] ]) : mixed
Parameters
$data : array<string, mixed> = []

Raw document data as returned by the server (including the reserved _key / _id / _rev attributes when present).

get()

Returns the value of a single field on the document, or `$default` when the field is absent.

public get(string $field[, mixed $default = null ]) : mixed
Parameters
$field : string

Field name (top-level only).

$default : mixed = null

Fallback value when the field is absent.

getId()

Returns the ArangoDB document identifier (`_id`), or null when the document has not been persisted yet.

public getId() : string|null
Return values
string|null

getKey()

Returns the ArangoDB document key (`_key`), or null when the document has not been persisted yet.

public getKey() : string|null
Return values
string|null

getRev()

Returns the document revision (`_rev`) — read-only, managed by the server. Null when the document has not been persisted yet.

public getRev() : string|null
Return values
string|null

has()

Returns true when the document has the given field (even when the stored value is null).

public has(string $field) : bool
Parameters
$field : string
Return values
bool

isNew()

Returns true when the document has not been persisted yet (no `_key` assigned by the server).

public isNew() : bool
Return values
bool

toArray()

Returns the underlying raw data array (including reserved attributes).

public toArray() : array<string, mixed>
Return values
array<string, mixed>
On this page

Search results