Oihana PHP Arango

PrepareDocumentTrait uses trait:short

This trait contains methods to prepare a document in the insert/update/replace/upsert methods.

Table of Contents

Constants

FILLABLE  : string = 'fillable'
The 'fillable' parameter key.

Properties

$fillable  : array<string|int, mixed>|null
The optional enumeration of all the fillable fields.

Methods

bind()  : string
Bind a value to an AQL query variable.
bindCollection()  : string
Bind a collection name to an AQL query variable.
bindView()  : string
Bind the model's declared View name (`AQL::VIEW` block, {@see Search::NAME}) to an AQL query variable — collection bind parameters (`@@view`) are valid for View names as well.
initializeFillable()  : static
Initialize the 'fillable' property.
prepareDocument()  : array<string|int, mixed>
Prepare a document before an insert, update, replace or upsert methods.
prepareDocumentClause()  : string
Prepares the document clause for a write operation (INSERT, UPDATE, REPLACE, UPSERT).

Constants

Properties

$fillable

The optional enumeration of all the fillable fields.

public array<string|int, mixed>|null $fillable = null

If the fillable property is null, all attributes can be inserted or updated.

Methods

bind()

Bind a value to an AQL query variable.

public bind(mixed $value[, array<string|int, mixed> &$binds = [] ][, string|null $to = null ]) : string
Parameters
$value : mixed

The value to bind to the query.

$binds : array<string|int, mixed> = []

Reference to the array of existing bind variables.

$to : string|null = null

Optional name of the bind variable. If null, a unique name is generated.

Tags
throws
BindException

If the provided bind variable name is invalid.

Return values
string

The formatted bind variable (including the "@" prefix as needed) for use in the query.

bindCollection()

Bind a collection name to an AQL query variable.

public bindCollection([array<string|int, mixed> &$binds = [] ][, array<string|int, mixed> $init = [] ]) : string

Prepares a bind variable for a collection name. Uses the collection defined in $init or falls back to $this->collection if none is provided.

Parameters
$binds : array<string|int, mixed> = []

Reference to the array of existing bind variables. If null, a new array is used.

$init : array<string|int, mixed> = []

Optional initialization array with keys:

  • Arango::COLLECTION => the collection name to bind
  • Arango::NAME => optional bind variable name
Tags
throws
BindException

If the bind variable name is invalid.

Return values
string

The formatted bind variable representing the collection.

bindView()

Bind the model's declared View name (`AQL::VIEW` block, {@see Search::NAME}) to an AQL query variable — collection bind parameters (`@@view`) are valid for View names as well.

public bindView([array<string|int, mixed> &$binds = [] ]) : string
Parameters
$binds : array<string|int, mixed> = []

Reference to the array of existing bind variables.

Tags
throws
BindException

If the bind variable name is invalid.

Return values
string

The formatted bind variable representing the View.

initializeFillable()

Initialize the 'fillable' property.

public initializeFillable([array<string|int, mixed> $init = [] ]) : static
Parameters
$init : array<string|int, mixed> = []
Return values
static

prepareDocument()

Prepare a document before an insert, update, replace or upsert methods.

public prepareDocument(string|array<string|int, mixed>|object|null $definition, array<string|int, mixed> &$binds[, array<string|int, mixed> $document = [] ][, array<string|int, mixed>|null $excludes = null ]) : array<string|int, mixed>

Filter the document attributes if the fillable property definition exist.

Parameters
$definition : string|array<string|int, mixed>|object|null

The document definition to prepare.

$binds : array<string|int, mixed>

The binding variable container.

$document : array<string|int, mixed> = []

The optional key/value pairs to insert in the final document.

$excludes : array<string|int, mixed>|null = null

The optional properties to excludes in the final document definition.

Tags
throws
BindException
Return values
array<string|int, mixed>

prepareDocumentClause()

Prepares the document clause for a write operation (INSERT, UPDATE, REPLACE, UPSERT).

protected prepareDocumentClause(mixed $doc, string $operation, array<string|int, mixed> &$binds[, array<string|int, mixed>|null $removeKeys = null ][, array<string|int, mixed>|null $conditions = null ][, Closure|null $ensure = null ]) : string

This method processes a document (array, object, or AQL string) to transform it into a usable AQL string. It also handles the automatic addition of created and modified fields, and binds the values to query variables.

Parameters
$doc : mixed

The document to prepare (associative array, object, or AQL string).

$operation : string

The current operation (e.g., Operation::UPDATE, Operation::INSERT, Operation::REPLACE, Operation::SEARCH).

$binds : array<string|int, mixed>

The binds array, passed by reference to be modified.

$removeKeys : array<string|int, mixed>|null = null

An array of attributes to remove keys from the document.

$conditions : array<string|int, mixed>|null = null

One or more callback conditions: fn(mixed $value): bool. If null, the null properties (object) and keys (array) are unset. If [], the document is not compressed.

$ensure : Closure|null = null

A callback function to ensure some attributes in the final document clause ensureKeyValue()

Tags
throws
BindException
DateMalformedStringException
DateInvalidTimeZoneException
Return values
string

The AQL document clause as a string.

On this page

Search results