QueryIDTrait uses trait:short
Provides a consistent mechanism for managing an internal query identifier (`queryId`), which can be used in dynamically constructed queries (e.g., AQL), log tracing, or caching.
This trait:
- Stores a private query identifier string
- Allows programmatic access to get or set the query ID
- Automatically generates a default ID if none is provided
- Supports initialization via associative arrays (e.g., input parameters or config)
Depends on:
ExpressionTrait
for consistent expression formattingParam::QUERY_ID
constant to standardize key accessChar::UNDERLINE
for default ID generation
Tags
Table of Contents
Properties
- $queryId : string
- The internal query identifier.
Methods
- betweenBraces() : string
- Encapsulates an expression between braces (`{}`).
- betweenBrackets() : string
- Encapsulates an expression between brackets (`[]`).
- betweenChars() : mixed
- Encapsulates an expression between specific characters.
- betweenDoubleQuotes() : mixed
- Encapsulates an expression between double quotes.
- betweenParentheses() : string
- Encapsulates an expression between parentheses (`()`).
- betweenQuotes() : mixed
- Encapsulates an expression between single quotes or custom characters.
- clean() : array<string|int, mixed>
- Clean an array by removing null values and empty strings.
- compile() : string
- Compile a list of expressions into a single string using a separator.
- func() : string
- Build a function expression like `NAME(arg1,arg2)`.
- getQueryID() : string
- Returns the internal query identifier.
- key() : string
- Transform a key by optionally prefixing it.
- keyValue() : string
- Build a key-value expression like `key: value`.
- object() : string
- Create an object expression, e.g., `{ name: 'Eka', age: 48 }`.
- predicate() : string
- Generate a predicate expression.
- predicates() : string|null
- Generate a complex logical expression with multiple predicates.
- setQueryID() : void
- Sets the internal query identifier.
- wrap() : string
- Wrap a string in grave accent characters.
Properties
$queryId
The internal query identifier.
protected
string
$queryId
This property holds the unique identifier string used internally for query referencing, debugging, or mapping purposes.
Methods
betweenBraces()
Encapsulates an expression between braces (`{}`).
public
betweenBraces([mixed $expression = Char::EMPTY ][, bool $useBraces = true ][, string $separator = Char::SPACE ]) : string
Parameters
- $expression : mixed = Char::EMPTY
-
The expression to wrap.
- $useBraces : bool = true
-
Whether to apply the braces or not.
- $separator : string = Char::SPACE
-
Separator for arrays (default: space).
Tags
Return values
string —The wrapped string.
betweenBrackets()
Encapsulates an expression between brackets (`[]`).
public
betweenBrackets([mixed $expression = Char::EMPTY ][, bool $useBrackets = true ][, string $separator = Char::SPACE ]) : string
Parameters
- $expression : mixed = Char::EMPTY
-
The expression to wrap.
- $useBrackets : bool = true
-
Whether to apply the brackets.
- $separator : string = Char::SPACE
-
Separator for arrays.
Tags
Return values
string —The wrapped string.
betweenChars()
Encapsulates an expression between specific characters.
public
betweenChars([mixed $expression = null ][, string $left = Char::EMPTY ][, string|null $right = null ][, bool $flag = true ][, string $separator = Char::SPACE ]) : mixed
Parameters
- $expression : mixed = null
-
The expression to encapsulate between two characters.
- $left : string = Char::EMPTY
-
The left character.
- $right : string|null = null
-
The right character. If null, uses the left character.
- $flag : bool = true
-
Indicates whether to apply the wrapping.
- $separator : string = Char::SPACE
-
The separator used to join arrays.
Tags
Return values
mixed —The wrapped string or original expression.
betweenDoubleQuotes()
Encapsulates an expression between double quotes.
public
betweenDoubleQuotes([mixed $expression = Char::EMPTY ][, string $char = Char::DOUBLE_QUOTE ][, bool $useQuotes = true ][, string $separator = Char::SPACE ]) : mixed
Parameters
- $expression : mixed = Char::EMPTY
-
The expression to wrap.
- $char : string = Char::DOUBLE_QUOTE
-
The quote character (default:
"
). - $useQuotes : bool = true
-
Whether to apply quotes.
- $separator : string = Char::SPACE
-
Separator for arrays.
Tags
Return values
mixed —The wrapped string or original.
betweenParentheses()
Encapsulates an expression between parentheses (`()`).
public
betweenParentheses([mixed $expression = Char::EMPTY ][, bool $useParentheses = true ][, string $separator = Char::SPACE ]) : string
Parameters
- $expression : mixed = Char::EMPTY
-
The expression to wrap.
- $useParentheses : bool = true
-
Whether to apply the parentheses.
- $separator : string = Char::SPACE
-
Separator for arrays.
Tags
Return values
string —The wrapped string.
betweenQuotes()
Encapsulates an expression between single quotes or custom characters.
public
betweenQuotes([mixed $expression = Char::EMPTY ][, string $char = Char::SIMPLE_QUOTE ][, bool $useQuotes = true ][, string $separator = Char::SPACE ]) : mixed
Parameters
- $expression : mixed = Char::EMPTY
-
The expression to wrap.
- $char : string = Char::SIMPLE_QUOTE
-
The quote character (default:
'
). - $useQuotes : bool = true
-
Whether to apply the quotes.
- $separator : string = Char::SPACE
-
Separator for arrays.
Tags
Return values
mixed —The wrapped string or original.
clean()
Clean an array by removing null values and empty strings.
public
clean([array<string|int, mixed> $array = [] ]) : array<string|int, mixed>
Parameters
- $array : array<string|int, mixed> = []
-
The array to clean.
Tags
Return values
array<string|int, mixed> —The filtered array.
compile()
Compile a list of expressions into a single string using a separator.
public
compile(string|array<string|int, mixed>|null $expressions[, string $separator = Char::SPACE ]) : string
Parameters
- $expressions : string|array<string|int, mixed>|null
-
The expressions to compile.
- $separator : string = Char::SPACE
-
The separator to use (default: Char::SPACE).
Tags
Return values
string —The compiled string.
func()
Build a function expression like `NAME(arg1,arg2)`.
public
func(string $name[, mixed $arguments = null ][, string $separator = Char::COMMA ]) : string
Parameters
- $name : string
-
The function name.
- $arguments : mixed = null
-
The arguments for the function.
- $separator : string = Char::COMMA
-
The separator between arguments (default: Char::COMMA).
Tags
Return values
string —The function expression.
getQueryID()
Returns the internal query identifier.
public
getQueryID() : string
Tags
Return values
string —The current value of the query ID.
key()
Transform a key by optionally prefixing it.
public
key(string $key, string|null $prefix) : string
Parameters
- $key : string
-
The key to transform.
- $prefix : string|null
-
The prefix to prepend.
Tags
Return values
string —The transformed key.
keyValue()
Build a key-value expression like `key: value`.
public
keyValue(mixed $key, mixed $value) : string
Parameters
- $key : mixed
-
The key.
- $value : mixed
-
The value.
Tags
Return values
string —The key-value expression.
object()
Create an object expression, e.g., `{ name: 'Eka', age: 48 }`.
public
object([string|array<string|int, mixed>|null $keyValues = [] ]) : string
Parameters
- $keyValues : string|array<string|int, mixed>|null = []
-
The properties to include.
Tags
Return values
string —The object-like string expression.
predicate()
Generate a predicate expression.
public
predicate(mixed $leftOperand[, string|null $operator = null ][, mixed $rightOperand = null ]) : string
Parameters
- $leftOperand : mixed
-
The left-hand value.
- $operator : string|null = null
-
The operator (e.g., '==', '!=').
- $rightOperand : mixed = null
-
The right-hand value.
Tags
Return values
string —The predicate expression.
predicates()
Generate a complex logical expression with multiple predicates.
public
predicates(array<string|int, mixed>|null $conditions, string $logicalOperator[, bool $useParentheses = false ]) : string|null
Parameters
- $conditions : array<string|int, mixed>|null
-
List of predicate expressions.
- $logicalOperator : string
-
The logical operator to join predicates (e.g., 'AND', 'OR').
- $useParentheses : bool = false
-
Whether to wrap the result in parentheses.
Tags
Return values
string|null —The combined expression or null if empty.
setQueryID()
Sets the internal query identifier.
public
setQueryID(string|array<string|int, mixed>|null $init) : void
Accepts a string value or an associative array that contains the key Param::QUERY_ID.
If null is passed, a default ID is auto-generated using query_<random>
.
Parameters
- $init : string|array<string|int, mixed>|null
-
The initial ID value, or an array with key Param::QUERY_ID.
Tags
wrap()
Wrap a string in grave accent characters.
public
wrap(string $value) : string
Parameters
- $value : string
-
The value to wrap.
Tags
Return values
string —The wrapped value.