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.
- OMIT_WHEN_DEPRECATION : string = 'Arango::CONDITIONS carrying callables on a wri...
- The deprecation logged when a write still carries its compression predicates under the shared `Arango::CONDITIONS` 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).
- resolveAqlConditions() : array<string|int, mixed>
- Resolves the **AQL predicates** a write adds to its `FILTER`, from {@see Arango::CONDITIONS} — the same key, and the same meaning, as every read of the model and as `delete()`, which carried them alone until now.
- resolveOmitWhen() : mixed
- Resolves the predicates deciding which attributes of the payload are dropped before a write, from the new {@see Arango::OMIT_WHEN} key or the deprecated {@see Arango::CONDITIONS} one.
Constants
FILLABLE
The 'fillable' parameter key.
public
string
FILLABLE
= 'fillable'
OMIT_WHEN_DEPRECATION
The deprecation logged when a write still carries its compression predicates under the shared `Arango::CONDITIONS` key.
public
string
OMIT_WHEN_DEPRECATION
= 'Arango::CONDITIONS carrying callables on a write is deprecated, use Arango::OMIT_WHEN — the key means AQL predicates everywhere else.'
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
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
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
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
staticprepareDocument()
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
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
Return values
string —The AQL document clause as a string.
resolveAqlConditions()
Resolves the **AQL predicates** a write adds to its `FILTER`, from {@see Arango::CONDITIONS} — the same key, and the same meaning, as every read of the model and as `delete()`, which carried them alone until now.
protected
resolveAqlConditions(array<string|int, mixed> $init) : array<string|int, mixed>
This is what makes a write scopeable: an UPDATE / REPLACE narrowed by the
caller's predicate matches nothing when the document is outside the scope, so
it writes nothing and RETURN NEW yields null.
Only the strings are kept. During the deprecation window the key can still
carry the write-side callables, which belong to resolveOmitWhen() and
would break predicates() if they reached the FILTER. Once the deprecation
is removed the filter becomes unnecessary and the key can be spread as-is,
exactly like the reads do.
Parameters
- $init : array<string|int, mixed>
-
The write configuration.
Return values
array<string|int, mixed> —The AQL predicate strings to append to the write's FILTER.
resolveOmitWhen()
Resolves the predicates deciding which attributes of the payload are dropped before a write, from the new {@see Arango::OMIT_WHEN} key or the deprecated {@see Arango::CONDITIONS} one.
protected
resolveOmitWhen(array<string|int, mixed> $init[, mixed $default = null ]) : mixed
CONDITIONS is read as AQL predicate strings by every read of the model
— and by delete() — but as callables by the four writes, which is why a
cross-cutting hook posing a scope on every model call used to answer
All conditions in the array must be callable on POST / PATCH / PUT.
OMIT_WHEN gives the write meaning a name of its own, so the shared key can
eventually mean one thing everywhere.
Resolution, in order:
OMIT_WHENpresent → used as-is, including an explicitnull(restore the default null-compression) or[](disable it) ;- otherwise
CONDITIONSis read with the caller's own default, and a deprecation is logged only when it actually carries callables — the legacy write usage. A caller that never used it sees nothing.
Strings are handed through untouched, so they keep raising in compress()
rather than being silently ignored: the write FILTER does not read them
yet, and turning a loud failure into a write that proceeds without the scope
its author intended would be the worse outcome.
Parameters
- $init : array<string|int, mixed>
-
The write configuration.
- $default : mixed = null
-
The caller's own default —
nullrestores the null-compression,[]disables it.
Return values
mixed —The compression predicates to hand to prepareDocumentClause().