InjectFilterTrait
Provides filter injection helpers for ArangoDB-based controllers.
Allows programmatic injection of filters that are transparently merged
with user-provided URL filters. Injected filters do NOT appear in the
response URL — they are passed via the $init array, not via query params.
Usage in a controller:
public function list( ?Request $request , ?Response $response , array $args = [] , array $init = [] ) :mixed
{
$this->injectFilter( $init , 'userId' , $userKey ) ; // $init is passed by reference
return parent::list( $request , $response , $args , $init ) ;
}
Overrides prepareFilter() to merge URL filters with injected filters.
Tags
Table of Contents
Constants
- INJECTED_FILTERS : string = '__injectedFilters'
- Init key for injected filters (internal, not exposed to user).
Methods
- injectFilter() : void
- Injects a single filter into the `$init` array — modified in place.
- injectFilters() : void
- Injects multiple filters into the `$init` array at once — modified in place.
- prepareFilter() : array<string|int, mixed>|null
- Overrides PrepareFilter::prepareFilter to merge URL filters with injected filters.
Constants
INJECTED_FILTERS
Init key for injected filters (internal, not exposed to user).
protected
string
INJECTED_FILTERS
= '__injectedFilters'
Methods
injectFilter()
Injects a single filter into the `$init` array — modified in place.
protected
injectFilter(array<string|int, mixed> &$init, string $key, mixed $value[, string $op = FilterComparator::EQ ][, string|null $alt = null ]) : void
The filter will be transparently merged with any user-provided URL filters
in prepareFilter() without appearing in the response URL.
Parameters
- $init : array<string|int, mixed>
-
The init array to enrich (passed by reference).
- $key : string
-
The field name to filter on.
- $value : mixed
-
The filter value.
- $op : string = FilterComparator::EQ
-
The comparison operator (default: FilterComparator::EQ).
- $alt : string|null = null
-
Optional alteration function (e.g., 'lower', 'length').
injectFilters()
Injects multiple filters into the `$init` array at once — modified in place.
protected
injectFilters(array<string|int, mixed> &$init, array<string|int, mixed> $filters) : void
Each filter is an array with keys from FilterParam (KEY, VAL, OP, ALT).
Example:
$this->injectFilters( $init ,
[
[ FilterParam::KEY => 'agent' , FilterParam::VAL => $userKey ] ,
[ FilterParam::KEY => 'method' , FilterParam::VAL => 'DELETE' ] ,
[ FilterParam::KEY => 'created' , FilterParam::VAL => '2026-01-01' , FilterParam::OP => FilterComparator::GE ] ,
]) ;
Parameters
- $init : array<string|int, mixed>
-
The init array to enrich (passed by reference).
- $filters : array<string|int, mixed>
-
Array of filter definitions.
prepareFilter()
Overrides PrepareFilter::prepareFilter to merge URL filters with injected filters.
protected
prepareFilter(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = null ]) : array<string|int, mixed>|null
URL filters are processed normally (stored in $params for URL display). Injected filters are appended transparently (NOT stored in $params).
Parameters
- $request : ServerRequestInterface|null
-
The PSR-7 request.
- $args : array<string|int, mixed> = []
-
The init/args array (may contain INJECTED_FILTERS).
- $params : array<string|int, mixed>|null = null
-
Reference to params array for URL generation.
Tags
Return values
array<string|int, mixed>|null —The merged filter array or null.