Oihana PHP Arango

ArangoDB uses AnalyzerManagementTrait, CollectionManagementTrait, IndexManagementTrait, ToStringTrait, ViewManagementTrait

High-level façade for ArangoDB operations.

Delegates to the oihana\arango\clients\… library (Database / Collection / Cursor / AqlQuery). The 19 public methods (10 on this class plus 9 on CollectionManagementTrait) keep their signatures byte-identical so models, traits and controllers consume the façade unchanged.

Table of Contents

Properties

$database  : Database
$logger  : LoggerInterface|null
$batchSize  : int
$client  : ArangoClient
$cursor  : Cursor|null
$data  : array<string, mixed>
$maxRuntime  : float|null

Methods

__construct()  : mixed
Creates a new ArangoDB façade.
analyzerDependentViews()  : array<int, string>
Returns the names of the Views whose links reference the given analyzer (at link level or on any nested field), so a caller can know what a drop + recreate of the analyzer would cascade to.
analyzerDiff()  : DiffReport
Compares a declared analyzer with the server state and reports the differences — the read-only half of {@see analyzerSync()}.
analyzerExists()  : bool
Checks if an analyzer exists — built-in analyzers (`identity`, `text_en`, `text_fr`, …) are always reported by the server.
analyzerSync()  : DiffReport
Reconciles a declared analyzer with its server state.
collectionCreate()  : bool
Creates a new collection if it does not already exist.
collectionDiff()  : DiffReport
Compares a declared collection with the server state and reports the difference — the collection half of the `doctor` diagnosis.
collectionDrop()  : bool
Drops a collection if it exists.
collectionExists()  : bool
Checks if a collection exists.
collectionRename()  : bool
Renames a collection if it exists.
collectionTruncate()  : bool
Truncates a collection if it exists.
createIndex()  : array<string|int, mixed>|null
Creates an index on a collection.
database()  : Database
Returns the underlying low-level {@see Database} client — the direct access to `query()` and `collection()` used by the migration engine (and available to a {@see \oihana\arango\migrations\Migration} through `$this->db->database()`).
dropIndex()  : bool
Drops an index from a collection.
execute()  : static
Executes the prepared query against the server and stores the resulting cursor.
explain()  : ExplainResult
Asks the optimizer for the execution plan of a query **without running it**, and returns it as a typed {@see ExplainResult} (optimizer rules applied, collections touched, estimated cost, and the indexes actually used).
getCursor()  : Cursor|null
Returns the current Cursor reference, or null when no query has been executed yet (or after {@see streamDocuments()} reset the state).
getDocuments()  : array<int, mixed>
Returns the list of documents from the last executed cursor.
getExtra()  : array<string, mixed>
Returns the extra data attached to the last executed cursor.
getFirstResult()  : mixed
Returns the first result from the last executed cursor.
getFoundRows()  : int
Returns the total number of rows of the last query (when `fullCount: true` was requested on the cursor options).
getIndex()  : array<string|int, mixed>
Returns a specific index of a collection by its ID.
getIndexes()  : array<string|int, mixed>
Returns all indexes of a collection.
getObject()  : object|null
Returns the first result as an object.
getProfile()  : ProfileResult
Returns the typed profile of the last **profiled** query run (per-phase timings + {@see ExecutionStats} + warnings), read from the cursor's `extra`.
getResult()  : array<int, mixed>|null
Returns the query result as a list of hydrated documents.
getStats()  : ExecutionStats
Returns the typed execution statistics of the last query, read from the cursor's `extra.stats` (populated when the query ran with the `profile` option, or for the parts the server always reports).
indexesDiff()  : DiffReport
Compares the declared indexes of a collection with the server state and reports the differences in one aggregated report — the index half of the `doctor` diagnosis.
indexesSync()  : DiffReport
Reconciles the declared indexes of a collection with the server: missing indexes are created; drifted ones are repaired by **drop + recreate** — but only when `$force` is true, because an index is immutable and the rebuild opens a window where queries lose it (and a unique index may fail to recreate over duplicated data). Without `$force` the drift is only reported. Server indexes that no declaration mentions are never touched.
login()  : string
Authenticates against ArangoDB by posting `{username, password}` to the `/_open/auth` endpoint and stores the returned JWT on the underlying client for subsequent requests.
prepare()  : static
Prepares the query data for the next call to {@see execute()}.
searchAliasViewCreate()  : bool
Creates a `search-alias` view if it does not already exist.
searchAliasViewDiff()  : DiffReport
Compares a `search-alias` view declaration with the server state and reports the differences — the read-only half of {@see searchAliasViewSync()}.
searchAliasViewSync()  : DiffReport
Reconciles a `search-alias` view with its declaration: creates it when missing, drop + recreate on drift, does nothing when already in sync.
streamDocuments()  : Generator<string|int, mixed>
Returns a generator yielding documents one by one from the current cursor.
useBasicAuth()  : void
Switches the underlying client to Basic auth with the given credentials. Subsequent requests carry `Authorization: basic base64(user:password)`. Any bearer token previously set is cleared.
useBearerAuth()  : void
Switches the underlying client to JWT/Bearer mode with the given token. Subsequent requests carry `Authorization: bearer <token>`.
viewCreate()  : bool
Creates an `arangosearch` View if it does not already exist.
viewDiff()  : DiffReport
Compares a View declaration with the server state and reports the differences — the read-only half of {@see viewSync()}.
viewDrop()  : bool
Drops a View if it exists. Underlying source collections are not touched.
viewExists()  : bool
Checks if a View exists.
viewSync()  : DiffReport
Reconciles a View with its declaration: creates it when missing, repairs a drift with `updateProperties()` (the View stays available while the inverted index rebuilds in the background — and PATCH replaces each declared collection link wholesale, so removed fields do unindex), does nothing when already in sync.
hydrateDocument()  : mixed
Hydrates a document according to the given schema hint.
resolveCollectionName()  : string
Resolves a collection reference (string name or {@see Collection} client handle) to its string name.
canonicaliseInvertedBodies()  : array{0: array, 1: array}
Canonicalises a declared inverted-index body and its matched server body so the per-key comparison of {@see compareIndexBody()} no longer trips over the shapes the server normalises:
compareIndexBody()  : array<int, string>
Accumulates one line per declared key whose server value differs — see {@see indexesDiff()} for the comparison semantics. The `fields` lists compare order-sensitively; every drift line carries the `drop + recreate` reminder (indexes are immutable).
comparePipeline()  : array<int, string>
Compares a declared `pipeline` sub-analyzer chain with the server one using declaration-oriented (subset) semantics — the same rule the top-level property loop gets for free by iterating only the declared keys.
compareViewIndexes()  : array<int, string>
Accumulates one change line per `{collection, index}` pair that differs between the declared list and the server `indexes` — see {@see searchAliasViewDiff()} for the comparison semantics.
compareViewLinkNode()  : void
Recursively compares one declared link node with its server counterpart: declared keys must match (lists like `analyzers` are compared order-insensitively, server defaults that the declaration omits are ignored), and the `fields` maps are checked both ways.
compareViewLinks()  : array<int, string>
Walks the declared link map and accumulates one line per difference with the server `links` — see {@see viewDiff()} for the comparison semantics.
fieldsSignature()  : array<int, mixed>
Returns the ordered `fields` signature used to match an unnamed index.
indexBody()  : array<string, mixed>
Normalises a declared index ({@see IndexDefinition} value object, {@see IndexOptions} value object or raw array) into its comparable body: the serialised creation payload, minus `inBackground` (a creation-time option the server never echoes).
indexLabel()  : string
Returns the human label of a declared index for the change lines: its `name` when declared, its `type(field, …)` signature otherwise.
linksReferenceAnalyzer()  : bool
Walks a link node (and recursively its `fields`) and tells whether any `analyzers` list references the given analyzer (short form).
loadViewProperties()  : array<string, mixed>|DiffReport
Loads a view's server properties, guarding both existence and type — the shared preamble of {@see viewDiff()} and {@see searchAliasViewDiff()}.
matchServerIndex()  : array<string, mixed>|null
Finds the server index a declared body targets: by `name` when one is declared, by `type` + ordered `fields` signature otherwise. Returns null when nothing matches (the index is missing).
normalisePrimarySort()  : mixed
Folds a `primarySort` definition to one canonical spelling of its sort direction: the declared `{ field, direction:"asc"|"desc" }` and the server's `{ field, asc:bool }` both become `{ field, asc:bool }`, so the two compare equal. Non-array input and direction-less fields pass through untouched.
normalizeAnalyzerValue()  : mixed
Normalizes a property value for an order-insensitive comparison: lists are sorted, maps are key-sorted, recursively; scalars pass through.
projectOntoDeclared()  : mixed
Projects `$actual` onto the shape of `$declared`, recursively: only the keys present in `$declared` are kept (by key for maps, by position for lists), so the defaults the server fills in but the declaration omits never read as drift. A scalar (or a `$declared` leaf) returns `$actual` verbatim.
rebuildDependentViews()  : void
Rebuilds the inverted index of every View referencing the analyzer, by removing then re-adding each referencing collection link. That remove + re-add is the only thing the server treats as a real rebuild after the analyzer was recreated — re-applying an identical link is a no-op, and a recreated analyzer otherwise leaves a stale index. Used by the forced cascade of {@see analyzerSync()}.
searchAliasViewRecreate()  : bool
Drops and recreates a `search-alias` view to repair a drift — safe because the alias owns no data (the underlying inverted indexes survive).
serverIndexes()  : array<int, array<string, mixed>>
Returns the server indexes of a collection minus the automatic `primary` and `edge` ones — the comparison scope of {@see indexesDiff()} / {@see indexesSync()}.
stripAnalyzerNamespace()  : string
Strips the `dbname::` namespace prefix the server prepends to analyzer names, leaving the short name links and declarations use.

Properties

$logger

protected LoggerInterface|null $logger

Optional PSR-3 logger.

$batchSize

private int $batchSize = 10000

Default batch size for queries.

$cursor

private Cursor|null $cursor = null

Internal reference to the last executed cursor.

$data

private array<string, mixed> $data

Query parameters and options (filled by prepare(), consumed by execute()).

$maxRuntime

private float|null $maxRuntime = null

Number of seconds after which the query is automatically terminated server-side.

Methods

__construct()

Creates a new ArangoDB façade.

public __construct([array<string, mixed> $config = [] ][, LoggerInterface|null $logger = null ]) : mixed
Parameters
$config : array<string, mixed> = []

Configuration array, typically the [arango] TOML section.

$logger : LoggerInterface|null = null

Optional PSR-3 logger.

Tags
throws
Throwable

When the underlying ArangoClient / Database cannot be built.

analyzerDependentViews()

Returns the names of the Views whose links reference the given analyzer (at link level or on any nested field), so a caller can know what a drop + recreate of the analyzer would cascade to.

public analyzerDependentViews(string $name) : array<int, string>

Names are compared by their short form (the dbname:: prefix the server may carry is stripped on both sides). Defensive: returns an empty list when the server is unreachable.

Parameters
$name : string

The analyzer name.

Return values
array<int, string>

The dependent View names.

analyzerDiff()

Compares a declared analyzer with the server state and reports the differences — the read-only half of {@see analyzerSync()}.

public analyzerDiff(AnalyzerDefinition $definition) : DiffReport

The comparison is declaration-oriented: the type must match exactly, declared properties must be present and equal (server defaults the declaration omits are ignored), and features are compared as a set (order-insensitive). A difference yields DiffStatus::DRIFTED with a drop + recreate required note and the dependent Views (immutable analyzer). An empty name is DiffStatus::INVALID.

Parameters
$definition : AnalyzerDefinition

The declared analyzer.

Return values
DiffReport

The typed report — see DiffStatus for the possible statuses.

analyzerExists()

Checks if an analyzer exists — built-in analyzers (`identity`, `text_en`, `text_fr`, …) are always reported by the server.

public analyzerExists(string $name) : bool
Parameters
$name : string

The name of the analyzer.

Return values
bool

analyzerSync()

Reconciles a declared analyzer with its server state.

public analyzerSync(AnalyzerDefinition $definition[, bool $force = false ]) : DiffReport

A missing analyzer is always created. A drifted analyzer is only repaired when $force is true — it is immutable, so repairing it means a drop + recreate that cascades to its dependent Views (their inverted index is rebuilt). Without $force a drift is left untouched (the safe default — repair it deliberately, through a migration). DiffStatus::IN_SYNC, DiffStatus::INVALID and DiffStatus::UNREACHABLE reports are always returned as-is.

⚠ The forced repair is not transactional: between the drop and the recreate the analyzer briefly does not exist, and a failure there leaves the dependent Views referencing a missing analyzer. The truly safe path for changing an analyzer is a new-name migration (see db/analyzers.md).

Parameters
$definition : AnalyzerDefinition

The declared analyzer.

$force : bool = false

Allow the drop + recreate (and dependent-View rebuild) of a drifted analyzer.

Return values
DiffReport

The analyzerDiff() report, with $applied set when the analyzer has been created or recreated.

collectionCreate()

Creates a new collection if it does not already exist.

public collectionCreate(string $name[, array<string, mixed> $options = [] ]) : bool
Parameters
$name : string

The name of the new collection.

$options : array<string, mixed> = []

Forwarded to POST /_api/collection (type, waitForSync, keyOptions, numberOfShards, replicationFactor, writeConcern, shardKeys, shardingStrategy, schema, …).

Return values
bool

TRUE when the collection has been created, FALSE when it already existed or the request failed.

collectionDiff()

Compares a declared collection with the server state and reports the difference — the collection half of the `doctor` diagnosis.

public collectionDiff(string $name[, int|null $type = null ]) : DiffReport

The check is existence first (DiffStatus::MISSING when the collection is absent), then — when $type is given — the collection type (2 document / 3 edge): a mismatch is reported as DiffStatus::DRIFTED (a collection type cannot be changed, the repair is manual by design).

Parameters
$name : string

The name of the collection.

$type : int|null = null

The declared collection type (2 document, 3 edge), or null to skip the type check.

Return values
DiffReport

The typed report (DiffKind::COLLECTION).

collectionDrop()

Drops a collection if it exists.

public collectionDrop(string $name) : bool
Parameters
$name : string

The name of the collection.

Return values
bool

TRUE when the collection has been dropped, FALSE otherwise.

collectionExists()

Checks if a collection exists.

public collectionExists(string $name) : bool
Parameters
$name : string

The name of the collection.

Return values
bool

collectionRename()

Renames a collection if it exists.

public collectionRename(string $oldName, string $name) : bool
Parameters
$oldName : string

The current name of the collection.

$name : string

The new name of the collection.

Tags
throws
ArangoException

When the rename request fails on a collection that does exist (e.g. cluster restriction, duplicate target name).

Return values
bool

TRUE when the collection has been renamed.

collectionTruncate()

Truncates a collection if it exists.

public collectionTruncate(string $name) : bool
Parameters
$name : string

The name of the collection.

Return values
bool

TRUE when the collection has been truncated.

createIndex()

Creates an index on a collection.

public createIndex(string|Collection $collection, IndexDefinition|IndexOptions|array<string|int, mixed> $indexOptions) : array<string|int, mixed>|null
Parameters
$collection : string|Collection

Collection name or Collection client handle.

$indexOptions : IndexDefinition|IndexOptions|array<string|int, mixed>

An IndexDefinition value object (e.g. InvertedIndex), an IndexOptions value object, or a raw associative array matching the POST /_api/index body.

Tags
throws
ReflectionException

When the IndexOptions cannot be serialised.

Return values
array<string|int, mixed>|null

The server response of the created index, or null on failure.

database()

Returns the underlying low-level {@see Database} client — the direct access to `query()` and `collection()` used by the migration engine (and available to a {@see \oihana\arango\migrations\Migration} through `$this->db->database()`).

public database() : Database
Return values
Database

dropIndex()

Drops an index from a collection.

public dropIndex(string|Collection $collection[, string|null $indexHandle = null ]) : bool
Parameters
$collection : string|Collection

Collection name or Collection handle — or the full index handle (collection/indexId) when $indexHandle is null.

$indexHandle : string|null = null

Index id / name suffix; when null, $collection is treated as the full handle.

Return values
bool

TRUE when the index has been dropped.

execute()

Executes the prepared query against the server and stores the resulting cursor.

public execute() : static

Cursor options that the server only honours under the nested options.{...} sub-object (fullCount, profile, stream, maxRuntime, failOnWarning, optimizer.*, …) are automatically moved there. Root-level cursor options (count, batchSize, ttl, cache, memoryLimit) stay at the body root.

Tags
throws
ArangoException

When the request fails.

Return values
static

explain()

Asks the optimizer for the execution plan of a query **without running it**, and returns it as a typed {@see ExplainResult} (optimizer rules applied, collections touched, estimated cost, and the indexes actually used).

public explain(AqlQuery|string $query[, array<string, mixed> $bindVars = [] ][, array<string, mixed> $options = [] ]) : ExplainResult
Parameters
$query : AqlQuery|string

The AQL query (or an AqlQuery carrying its own binds).

$bindVars : array<string, mixed> = []

Bind variables (omit when $query is an AqlQuery).

$options : array<string, mixed> = []

Explain options (allPlans, optimizer.rules, …).

Tags
throws
ArangoException

When the request fails.

Return values
ExplainResult

getCursor()

Returns the current Cursor reference, or null when no query has been executed yet (or after {@see streamDocuments()} reset the state).

public getCursor() : Cursor|null
Return values
Cursor|null

getDocuments()

Returns the list of documents from the last executed cursor.

public getDocuments([null|SchemaResolver|Closure|string $schema = null ]) : array<int, mixed>
Parameters
$schema : null|SchemaResolver|Closure|string = null

Optional class / resolver / closure to map the documents.

Tags
throws
ArangoException
ReflectionException
Return values
array<int, mixed>

getExtra()

Returns the extra data attached to the last executed cursor.

public getExtra() : array<string, mixed>
Return values
array<string, mixed>

getFirstResult()

Returns the first result from the last executed cursor.

public getFirstResult([null|SchemaResolver|Closure|string $schema = null ]) : mixed
Parameters
$schema : null|SchemaResolver|Closure|string = null

Optional class / resolver / closure to map the documents.

Tags
throws
ArangoException
ReflectionException

getFoundRows()

Returns the total number of rows of the last query (when `fullCount: true` was requested on the cursor options).

public getFoundRows() : int
Return values
int

getIndex()

Returns a specific index of a collection by its ID.

public getIndex(string $collection, string $indexId) : array<string|int, mixed>
Parameters
$collection : string

The name of the collection.

$indexId : string

The index ID (full handle or bare key — bare keys are auto-prefixed with the collection name).

Tags
throws
ArangoException

When the index is missing or the request fails.

Return values
array<string|int, mixed>

The index definition from the server.

getIndexes()

Returns all indexes of a collection.

public getIndexes(string $name) : array<string|int, mixed>
Parameters
$name : string

The name of the collection.

Tags
throws
ArangoException

When the request fails.

Return values
array<string|int, mixed>

The indexes array from the server response.

getObject()

Returns the first result as an object.

public getObject([null|SchemaResolver|Closure|string $schema = null ]) : object|null
Parameters
$schema : null|SchemaResolver|Closure|string = null

Optional class / resolver / closure to map the documents.

Tags
throws
ArangoException
ReflectionException
Return values
object|null

getProfile()

Returns the typed profile of the last **profiled** query run (per-phase timings + {@see ExecutionStats} + warnings), read from the cursor's `extra`.

public getProfile() : ProfileResult
Return values
ProfileResult

getResult()

Returns the query result as a list of hydrated documents.

public getResult([null|SchemaResolver|Closure|string $schema = null ]) : array<int, mixed>|null
Parameters
$schema : null|SchemaResolver|Closure|string = null

Optional class / resolver / closure to map the documents.

Tags
throws
ArangoException
ReflectionException
Return values
array<int, mixed>|null

getStats()

Returns the typed execution statistics of the last query, read from the cursor's `extra.stats` (populated when the query ran with the `profile` option, or for the parts the server always reports).

public getStats() : ExecutionStats
Return values
ExecutionStats

indexesDiff()

Compares the declared indexes of a collection with the server state and reports the differences in one aggregated report — the index half of the `doctor` diagnosis.

public indexesDiff(string $collection, array<int, IndexDefinition|IndexOptions|array<string, mixed>> $indexes) : DiffReport

Matching: a declared index is looked up on the server by its name when one is declared, by its type + fields signature otherwise. The comparison covers every declared key (fields order-sensitively — ["a","b"] and ["b","a"] are different indexes) and ignores the server-side extras the declaration does not mention (id, selectivityEstimate, …); inBackground is a creation-time option never echoed by the server, it is excluded. The automatic primary and edge indexes are out of scope both ways. Server indexes that no declaration mentions are reported as drift.

Statuses: declared indexes absent from the server only → DiffStatus::MISSING (safe to create); any definition mismatch or undeclared server index → DiffStatus::DRIFTED (an index is immutable — repairing means drop + recreate, see indexesSync() $force); a missing collection → DiffStatus::INVALID.

Inverted indexes are diffed canonically: a declared string field ("name") is lined up with the server's { name } object, the primarySort direction is normalised across its direction / asc spellings, and the server defaults the declaration omits (compression, per-field flags, …) are projected away — so an inverted index that is actually in sync no longer reads as drift.

Parameters
$collection : string

The name of the collection.

$indexes : array<int, IndexDefinition|IndexOptions|array<string, mixed>>

The declared indexes (the model AQL::INDEXES list).

Tags
throws
ReflectionException

When an IndexOptions cannot be serialised.

Return values
DiffReport

The typed report (DiffKind::INDEXES).

indexesSync()

Reconciles the declared indexes of a collection with the server: missing indexes are created; drifted ones are repaired by **drop + recreate** — but only when `$force` is true, because an index is immutable and the rebuild opens a window where queries lose it (and a unique index may fail to recreate over duplicated data). Without `$force` the drift is only reported. Server indexes that no declaration mentions are never touched.

public indexesSync(string $collection, array<int, IndexDefinition|IndexOptions|array<string, mixed>> $indexes[, bool $force = false ]) : DiffReport
Parameters
$collection : string

The name of the collection.

$indexes : array<int, IndexDefinition|IndexOptions|array<string, mixed>>

The declared indexes (the model AQL::INDEXES list).

$force : bool = false

Allow the drop + recreate of drifted indexes.

Tags
throws
ReflectionException

When an IndexOptions cannot be serialised.

Return values
DiffReport

The indexesDiff() report, with $applied set when at least one index has been created or rebuilt.

login()

Authenticates against ArangoDB by posting `{username, password}` to the `/_open/auth` endpoint and stores the returned JWT on the underlying client for subsequent requests.

public login(string $user, string $password) : string

The basic credentials are also stashed on the transport so it can transparently refresh the JWT on 401 — useful for long-running commands whose run time exceeds the server-side JWT TTL.

Parameters
$user : string
$password : string
Tags
throws
ArangoException

When the login request fails (401, network, …).

Return values
string

The JWT returned by the server.

prepare()

Prepares the query data for the next call to {@see execute()}.

public prepare([array<string, mixed> $data = [] ]) : static

Default batchSize and maxRuntime (when configured on the façade) are folded in when the caller did not provide them.

Parameters
$data : array<string, mixed> = []
Return values
static

searchAliasViewCreate()

Creates a `search-alias` view if it does not already exist.

public searchAliasViewCreate(SearchAliasView $view) : bool
Parameters
$view : SearchAliasView

The declared search-alias view.

Return values
bool

TRUE when the view has been created, FALSE when it already existed or the request failed.

searchAliasViewDiff()

Compares a `search-alias` view declaration with the server state and reports the differences — the read-only half of {@see searchAliasViewSync()}.

public searchAliasViewDiff(SearchAliasView $view) : DiffReport

The comparison is set-oriented on the {collection, index} pairs: every declared pair must be aliased on the server, and any server pair absent from the declaration is reported as drift.

Parameters
$view : SearchAliasView

The declared search-alias view.

Return values
DiffReport

The typed report — see DiffStatus for the possible statuses.

searchAliasViewSync()

Reconciles a `search-alias` view with its declaration: creates it when missing, drop + recreate on drift, does nothing when already in sync.

public searchAliasViewSync(SearchAliasView $view) : DiffReport

A search-alias view holds no data — it only references the inverted indexes declared on the collections — so a drop + recreate is safe (the underlying indexes survive) and far simpler than the per-entry add/del PATCH operations. It is not transactional: between the drop and the recreate the view briefly does not exist (search unavailable for a few ms), which is acceptable for a maintenance sync.

Parameters
$view : SearchAliasView

The declared search-alias view.

Return values
DiffReport

The searchAliasViewDiff() report, with $applied set when created or recreated.

streamDocuments()

Returns a generator yielding documents one by one from the current cursor.

public streamDocuments([null|SchemaResolver|Closure|string $schema = null ]) : Generator<string|int, mixed>
Parameters
$schema : null|SchemaResolver|Closure|string = null

Optional class / resolver / closure to map the documents.

Tags
throws
ReflectionException
Return values
Generator<string|int, mixed>

useBasicAuth()

Switches the underlying client to Basic auth with the given credentials. Subsequent requests carry `Authorization: basic base64(user:password)`. Any bearer token previously set is cleared.

public useBasicAuth(string $user, string $password) : void
Parameters
$user : string
$password : string

useBearerAuth()

Switches the underlying client to JWT/Bearer mode with the given token. Subsequent requests carry `Authorization: bearer <token>`.

public useBearerAuth(string|null $token) : void

Pass null to revert to the configured basic credentials (or to anonymous mode when none are configured).

Parameters
$token : string|null

JWT to send on subsequent requests.

viewCreate()

Creates an `arangosearch` View if it does not already exist.

public viewCreate(string $name[, array<string, ArangoSearchLink|array<string, mixed>> $links = [] ][, array<string, mixed> $options = [] ]) : bool
Parameters
$name : string

The name of the new View.

$links : array<string, ArangoSearchLink|array<string, mixed>> = []

Per-collection link map (collection name → link definition).

$options : array<string, mixed> = []

Extra arangosearch options forwarded verbatim (commitIntervalMsec, primarySort, …).

Return values
bool

TRUE when the View has been created, FALSE when it already existed or the request failed.

viewDiff()

Compares a View declaration with the server state and reports the differences — the read-only half of {@see viewSync()}.

public viewDiff(string $name, array<string, ArangoSearchLink|array<string, mixed>> $links) : DiffReport

The comparison is declaration-oriented: every declared key must be present and equal on the server (server-side defaults that the declaration does not mention are ignored), and fields indexed on the server but absent from the declaration are reported as drift.

Parameters
$name : string

The name of the View.

$links : array<string, ArangoSearchLink|array<string, mixed>>

Desired per-collection link map (collection name → link definition).

Return values
DiffReport

The typed report — see DiffStatus for the possible statuses.

viewDrop()

Drops a View if it exists. Underlying source collections are not touched.

public viewDrop(string $name) : bool
Parameters
$name : string

The name of the View.

Return values
bool

TRUE when the View has been dropped, FALSE otherwise.

viewExists()

Checks if a View exists.

public viewExists(string $name) : bool
Parameters
$name : string

The name of the View.

Return values
bool

viewSync()

Reconciles a View with its declaration: creates it when missing, repairs a drift with `updateProperties()` (the View stays available while the inverted index rebuilds in the background — and PATCH replaces each declared collection link wholesale, so removed fields do unindex), does nothing when already in sync.

public viewSync(string $name, array<string, ArangoSearchLink|array<string, mixed>> $links) : DiffReport

updateProperties() is preferred over replaceProperties() because it leaves the view-level options (commitIntervalMsec, …) and the links of undeclared collections untouched.

Parameters
$name : string

The name of the View.

$links : array<string, ArangoSearchLink|array<string, mixed>>

Desired per-collection link map (collection name → link definition).

Return values
DiffReport

The viewDiff() report, with $applied set when the View has been created or updated.

hydrateDocument()

Hydrates a document according to the given schema hint.

protected hydrateDocument(mixed $document[, Closure|SchemaResolver|string|null $schema = null ]) : mixed
Parameters
$document : mixed

The document to hydrate.

$schema : Closure|SchemaResolver|string|null = null

Optional class / resolver / closure.

Tags
throws
ReflectionException

resolveCollectionName()

Resolves a collection reference (string name or {@see Collection} client handle) to its string name.

protected resolveCollectionName(string|Collection $collection) : string
Parameters
$collection : string|Collection
Return values
string

canonicaliseInvertedBodies()

Canonicalises a declared inverted-index body and its matched server body so the per-key comparison of {@see compareIndexBody()} no longer trips over the shapes the server normalises:

private canonicaliseInvertedBodies(array<string, mixed> $declared, array<string, mixed> $actual) : array{0: array, 1: array}
  • fields — a declared string "x" is the server's { name:"x", … }, so declared strings are lifted to { name } objects;
  • primarySort — the declared { direction:"asc" } and the server's { asc:true } are folded to one spelling (see normalisePrimarySort());
  • features — compared order-insensitively (the server may reorder them);
  • fields / primarySort / storedValues — every server key the declaration does not mention (compression, per-field flags, …) is projected away (see projectOntoDeclared()), per the "compare only what is declared" contract.
Parameters
$declared : array<string, mixed>

The declared inverted-index body.

$actual : array<string, mixed>

The matched server index body.

Return values
array{0: array, 1: array}

The canonicalised [ declared , actual ] pair.

compareIndexBody()

Accumulates one line per declared key whose server value differs — see {@see indexesDiff()} for the comparison semantics. The `fields` lists compare order-sensitively; every drift line carries the `drop + recreate` reminder (indexes are immutable).

private compareIndexBody(string $label, array<string, mixed> $body, array<string, mixed> $actual) : array<int, string>
Parameters
$label : string

The declared index label used in the change lines.

$body : array<string, mixed>

The declared index body (indexBody()).

$actual : array<string, mixed>

The matched server index.

Return values
array<int, string>

comparePipeline()

Compares a declared `pipeline` sub-analyzer chain with the server one using declaration-oriented (subset) semantics — the same rule the top-level property loop gets for free by iterating only the declared keys.

private comparePipeline(string $name, mixed $declared, mixed $server) : array<int, string>

A pipeline analyzer nests its sub-analyzers inside a list, and the server reads each one back with every default property filled in (a declared norm carrying only { locale } returns { locale, case, accent }; an ngram returns its startMarker / endMarker / streamType defaults too). A plain deep-equality of the two lists would therefore flag a permanent false drift — the very bug the identity analyzer hit on View links. Instead each member is matched by position (the chain order is significant) and by type, and only the declared sub-properties are checked: server defaults the declaration omits are ignored. A RawAnalyzer dumped from the server (all defaults present) stays a valid round-trip.

Parameters
$name : string

The analyzer name, for the change lines.

$declared : mixed

The declared properties.pipeline value.

$server : mixed

The server properties.pipeline value.

Return values
array<int, string>

The change lines, empty when the chains are equivalent.

compareViewIndexes()

Accumulates one change line per `{collection, index}` pair that differs between the declared list and the server `indexes` — see {@see searchAliasViewDiff()} for the comparison semantics.

private compareViewIndexes(array<int, array{collection: string, index: string}> $desired, array<int, mixed> $actual) : array<int, string>
Parameters
$desired : array<int, array{collection: string, index: string}>

Declared, normalized {collection, index} list.

$actual : array<int, mixed>

Server-side indexes list (from properties()).

Return values
array<int, string>

compareViewLinkNode()

Recursively compares one declared link node with its server counterpart: declared keys must match (lists like `analyzers` are compared order-insensitively, server defaults that the declaration omits are ignored), and the `fields` maps are checked both ways.

private compareViewLinkNode(string $path, array<string, mixed> $desired, array<string, mixed> $actual, array<int, string> &$changes) : void
Parameters
$path : string

Dotted breadcrumb used in the change lines.

$desired : array<string, mixed>

Declared link node.

$actual : array<string, mixed>

Server link node.

$changes : array<int, string>

Accumulated change lines, by reference.

Walks the declared link map and accumulates one line per difference with the server `links` — see {@see viewDiff()} for the comparison semantics.

private compareViewLinks(array<string, ArangoSearchLink|array<string, mixed>> $desired, array<string, mixed> $actual) : array<int, string>
Parameters
$desired : array<string, ArangoSearchLink|array<string, mixed>>

Declared per-collection link map.

$actual : array<string, mixed>

Server-side links map (from properties()).

Return values
array<int, string>

fieldsSignature()

Returns the ordered `fields` signature used to match an unnamed index.

private fieldsSignature(array<string, mixed> $body) : array<int, mixed>

For an inverted index the server expands each declared string field into a { name, … } object, so both sides are reduced to their bare attribute names; every other type keeps its raw fields list.

Parameters
$body : array<string, mixed>

The declared or server index body.

Return values
array<int, mixed>

indexBody()

Normalises a declared index ({@see IndexDefinition} value object, {@see IndexOptions} value object or raw array) into its comparable body: the serialised creation payload, minus `inBackground` (a creation-time option the server never echoes).

private indexBody(IndexDefinition|IndexOptions|array<string, mixed> $declared) : array<string, mixed>
Parameters
$declared : IndexDefinition|IndexOptions|array<string, mixed>
Tags
throws
ReflectionException

When the IndexOptions cannot be serialised.

Return values
array<string, mixed>

indexLabel()

Returns the human label of a declared index for the change lines: its `name` when declared, its `type(field, …)` signature otherwise.

private indexLabel(array<string, mixed> $body) : string
Parameters
$body : array<string, mixed>

The declared index body.

Return values
string

linksReferenceAnalyzer()

Walks a link node (and recursively its `fields`) and tells whether any `analyzers` list references the given analyzer (short form).

private linksReferenceAnalyzer(array<string, mixed> $node, string $needle) : bool
Parameters
$node : array<string, mixed>

A link node or the whole links map.

$needle : string

The analyzer short name to look for.

Return values
bool

loadViewProperties()

Loads a view's server properties, guarding both existence and type — the shared preamble of {@see viewDiff()} and {@see searchAliasViewDiff()}.

private loadViewProperties(string $name, string $expectedType) : array<string, mixed>|DiffReport
Parameters
$name : string

The view name.

$expectedType : string

The expected ViewType of the server view.

Tags
throws
ArangoException

When the server is unreachable.

Return values
array<string, mixed>|DiffReport

The server properties on success, or a terminal DiffStatus::MISSING / DiffStatus::INVALID report the caller must return as-is.

matchServerIndex()

Finds the server index a declared body targets: by `name` when one is declared, by `type` + ordered `fields` signature otherwise. Returns null when nothing matches (the index is missing).

private matchServerIndex(array<string, mixed> $body, array<int, array<string, mixed>> $actual) : array<string, mixed>|null
Parameters
$body : array<string, mixed>

The declared index body.

$actual : array<int, array<string, mixed>>

The non-system server indexes.

Return values
array<string, mixed>|null

normalisePrimarySort()

Folds a `primarySort` definition to one canonical spelling of its sort direction: the declared `{ field, direction:"asc"|"desc" }` and the server's `{ field, asc:bool }` both become `{ field, asc:bool }`, so the two compare equal. Non-array input and direction-less fields pass through untouched.

private normalisePrimarySort(mixed $primarySort) : mixed
Parameters
$primarySort : mixed

The declared or server primarySort value.

Return values
mixed

The canonicalised value (an array when the input was one).

normalizeAnalyzerValue()

Normalizes a property value for an order-insensitive comparison: lists are sorted, maps are key-sorted, recursively; scalars pass through.

private normalizeAnalyzerValue(mixed $value) : mixed
Parameters
$value : mixed

projectOntoDeclared()

Projects `$actual` onto the shape of `$declared`, recursively: only the keys present in `$declared` are kept (by key for maps, by position for lists), so the defaults the server fills in but the declaration omits never read as drift. A scalar (or a `$declared` leaf) returns `$actual` verbatim.

private projectOntoDeclared(mixed $declared, mixed $actual) : mixed
Parameters
$declared : mixed

The declared sub-tree.

$actual : mixed

The matched server sub-tree.

Return values
mixed

The server value reduced to the declared shape.

rebuildDependentViews()

Rebuilds the inverted index of every View referencing the analyzer, by removing then re-adding each referencing collection link. That remove + re-add is the only thing the server treats as a real rebuild after the analyzer was recreated — re-applying an identical link is a no-op, and a recreated analyzer otherwise leaves a stale index. Used by the forced cascade of {@see analyzerSync()}.

private rebuildDependentViews(string $name) : void
Parameters
$name : string

The analyzer that was just recreated.

Tags
throws
ArangoException

When a View update fails.

searchAliasViewRecreate()

Drops and recreates a `search-alias` view to repair a drift — safe because the alias owns no data (the underlying inverted indexes survive).

private searchAliasViewRecreate(SearchAliasView $view) : bool
Parameters
$view : SearchAliasView

The declared search-alias view.

Tags
throws
ArangoException

When the drop or the recreate fails.

Return values
bool

Always TRUE (a failure surfaces as the thrown ArangoException).

serverIndexes()

Returns the server indexes of a collection minus the automatic `primary` and `edge` ones — the comparison scope of {@see indexesDiff()} / {@see indexesSync()}.

private serverIndexes(string $collection) : array<int, array<string, mixed>>
Parameters
$collection : string

The name of the collection.

Tags
throws
ArangoException

When the request fails.

Return values
array<int, array<string, mixed>>

stripAnalyzerNamespace()

Strips the `dbname::` namespace prefix the server prepends to analyzer names, leaving the short name links and declarations use.

private stripAnalyzerNamespace(string $name) : string
Parameters
$name : string
Return values
string
On this page

Search results