ArangoCasbinAdapter implements Adapter, BatchAdapter, FilteredAdapter, UpdatableAdapter uses AdapterHelper
ArangoDB adapter for Casbin using composition with a Documents model.
Delegates all CRUD operations to an oihana\models\interfaces\Documents
instance configured for the rbac collection. This ensures consistent
query building, bind variable management, and alignment with the
project's existing model architecture.
The adapter implements all Casbin persistence interfaces:
- Adapter : basic load/save/add/remove policy
- BatchAdapter : batch add/remove policies
- FilteredAdapter : filtered policy loading
- UpdatableAdapter : policy updates
Tags
Table of Contents
Interfaces
- Adapter
- BatchAdapter
- FilteredAdapter
- UpdatableAdapter
Constants
- KEYS : array<string|int, mixed> = ['ptype', 'v0', 'v1', 'v2', 'v3', 'v4', 'v5']
- The Casbin policy field keys.
Properties
- $logger : LoggerInterface|null
- The optional logger.
- $model : Documents|DocumentsModel
- The Documents model for the rbac collection.
- $filtered : bool
- Whether the loaded policies have been filtered.
Methods
- __construct() : mixed
- Creates a new ArangoCasbinAdapter instance.
- addPolicies() : void
- Adds multiple policy rules to the storage.
- addPolicy() : void
- Adds a single policy rule to the storage.
- filterRule() : array<string|int, mixed>
- Filters trailing empty values from a rule array.
- isFiltered() : bool
- Returns whether the loaded policy has been filtered.
- loadFilteredPolicy() : void
- Loads only policy rules that match the filter.
- loadPolicy() : void
- Loads all policy rules from the storage.
- removeFilteredPolicy() : void
- Removes policy rules that match the filter from the storage.
- removePolicies() : void
- Removes multiple policy rules from the storage.
- removePolicy() : void
- Removes a single policy rule from the storage.
- savePolicy() : void
- Saves all policy rules to the storage.
- setFiltered() : void
- Sets the filtered flag.
- updateFilteredPolicies() : array<string|int, mixed>
- Deletes old rules matching the filter and adds new rules.
- updatePolicies() : void
- Updates multiple policy rules in the storage.
- updatePolicy() : void
- Updates a policy rule in the storage.
- _removeFilteredPolicy() : array<string|int, mixed>
- Removes filtered policies and returns the removed rules.
- buildConditions() : array<string|int, string>
- Builds AQL filter conditions from a ptype and a Casbin rule array.
- buildConditionsFromArray() : array<string|int, string>
- Builds AQL conditions from an associative array.
- buildFilterConditions() : array<string|int, string>
- Builds AQL conditions from Filter pairs [[field, value], ...].
- insertPolicyLine() : void
- Inserts a single policy line as a document in the rbac collection.
- loadPolicyFromRow() : void
- Loads a policy line from a raw document row into the Casbin model.
Constants
KEYS
The Casbin policy field keys.
public
array<string|int, mixed>
KEYS
= ['ptype', 'v0', 'v1', 'v2', 'v3', 'v4', 'v5']
Properties
$logger
The optional logger.
protected
LoggerInterface|null
$logger
$model
The Documents model for the rbac collection.
protected
Documents|DocumentsModel
$model
$filtered
Whether the loaded policies have been filtered.
private
bool
$filtered
= false
Methods
__construct()
Creates a new ArangoCasbinAdapter instance.
public
__construct(Documents|DocumentsModel $model[, LoggerInterface|null $logger = null ]) : mixed
Parameters
- $model : Documents|DocumentsModel
-
The Documents model for the rbac collection.
- $logger : LoggerInterface|null = null
-
An optional PSR logger.
addPolicies()
Adds multiple policy rules to the storage.
public
addPolicies(string $sec, string $ptype, array<string|int, mixed> $rules) : void
Parameters
- $sec : string
- $ptype : string
- $rules : array<string|int, mixed>
Tags
addPolicy()
Adds a single policy rule to the storage.
public
addPolicy(string $sec, string $ptype, array<string|int, mixed> $rule) : void
Parameters
- $sec : string
- $ptype : string
- $rule : array<string|int, mixed>
Tags
filterRule()
Filters trailing empty values from a rule array.
public
filterRule(array<string|int, mixed> $rule) : array<string|int, mixed>
Parameters
- $rule : array<string|int, mixed>
Return values
array<string|int, mixed>isFiltered()
Returns whether the loaded policy has been filtered.
public
isFiltered() : bool
Tags
Return values
boolloadFilteredPolicy()
Loads only policy rules that match the filter.
public
loadFilteredPolicy(Model $model, mixed $filter) : void
Supported filter types:
Filterobject : uses$filter->pas field names and$filter->gas valuesClosure: receives($this->model, self::KEYS, &$rows)for custom loadingarray: associative array of field => value conditions
Parameters
- $model : Model
- $filter : mixed
Tags
loadPolicy()
Loads all policy rules from the storage.
public
loadPolicy(Model $model) : void
Parameters
- $model : Model
Tags
removeFilteredPolicy()
Removes policy rules that match the filter from the storage.
public
removeFilteredPolicy(string $sec, string $ptype, int $fieldIndex, string ...$fieldValues) : void
Parameters
- $sec : string
- $ptype : string
- $fieldIndex : int
- $fieldValues : string
Tags
removePolicies()
Removes multiple policy rules from the storage.
public
removePolicies(string $sec, string $ptype, array<string|int, mixed> $rules) : void
Parameters
- $sec : string
- $ptype : string
- $rules : array<string|int, mixed>
Tags
removePolicy()
Removes a single policy rule from the storage.
public
removePolicy(string $sec, string $ptype, array<string|int, mixed> $rule) : void
Parameters
- $sec : string
- $ptype : string
- $rule : array<string|int, mixed>
Tags
savePolicy()
Saves all policy rules to the storage.
public
savePolicy(Model $model) : void
Clears the collection first, then inserts all rules.
Parameters
- $model : Model
Tags
setFiltered()
Sets the filtered flag.
public
setFiltered(bool $filtered) : void
Parameters
- $filtered : bool
updateFilteredPolicies()
Deletes old rules matching the filter and adds new rules.
public
updateFilteredPolicies(string $sec, string $ptype, array<string|int, mixed> $newPolicies, int $fieldIndex, string ...$fieldValues) : array<string|int, mixed>
Parameters
- $sec : string
- $ptype : string
- $newPolicies : array<string|int, mixed>
- $fieldIndex : int
- $fieldValues : string
Tags
Return values
array<string|int, mixed>updatePolicies()
Updates multiple policy rules in the storage.
public
updatePolicies(string $sec, string $ptype, array<string|int, mixed> $oldRules, array<string|int, mixed> $newRules) : void
Parameters
- $sec : string
- $ptype : string
- $oldRules : array<string|int, mixed>
- $newRules : array<string|int, mixed>
Tags
updatePolicy()
Updates a policy rule in the storage.
public
updatePolicy(string $sec, string $ptype, array<string|int, mixed> $oldRule, array<string|int, mixed> $newPolicy) : void
Parameters
- $sec : string
- $ptype : string
- $oldRule : array<string|int, mixed>
- $newPolicy : array<string|int, mixed>
Tags
_removeFilteredPolicy()
Removes filtered policies and returns the removed rules.
protected
_removeFilteredPolicy(string $sec, string $ptype, int $fieldIndex, string ...$fieldValues) : array<string|int, mixed>
Parameters
- $sec : string
- $ptype : string
- $fieldIndex : int
- $fieldValues : string
Tags
Return values
array<string|int, mixed> —The removed rules
buildConditions()
Builds AQL filter conditions from a ptype and a Casbin rule array.
protected
buildConditions(string $ptype, array<string|int, mixed> $rule) : array<string|int, string>
Returns an array of AQL condition strings like :
['doc.ptype == "p"', 'doc.v0 == "role:admin"', ...]
Parameters
- $ptype : string
-
The policy type (p, g, etc.)
- $rule : array<string|int, mixed>
-
The rule values [v0, v1, ...]
Return values
array<string|int, string>buildConditionsFromArray()
Builds AQL conditions from an associative array.
protected
buildConditionsFromArray(array<string|int, mixed> $filter) : array<string|int, string>
Parameters
- $filter : array<string|int, mixed>
-
Associative array [ 'ptype' => 'p', 'v0' => 'role:admin', ... ]
Return values
array<string|int, string>buildFilterConditions()
Builds AQL conditions from Filter pairs [[field, value], ...].
protected
buildFilterConditions(array<string|int, mixed> $pairs) : array<string|int, string>
Parameters
- $pairs : array<string|int, mixed>
Return values
array<string|int, string>insertPolicyLine()
Inserts a single policy line as a document in the rbac collection.
protected
insertPolicyLine(string $ptype, array<string|int, mixed> $rule) : void
Parameters
- $ptype : string
- $rule : array<string|int, mixed>
Tags
loadPolicyFromRow()
Loads a policy line from a raw document row into the Casbin model.
protected
loadPolicyFromRow(array<string|int, mixed> $row, Model $model) : void
Parameters
- $row : array<string|int, mixed>
- $model : Model