Oihana PHP System

QueryIDTrait

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)
Tags
example
use oihana\traits\QueryIDTrait;

class MyQueryBuilder
{
   use QueryIDTrait;

   public function __construct(array $options = [])
   {
       $this->setQueryID($options);
   }
}

$builder = new MyQueryBuilder(['queryId' => 'custom_query']);
echo $builder->getQueryID(); // 'custom_query'

$builder->setQueryID(null);
echo $builder->getQueryID(); // 'query_8237412' (random suffix)
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Constants

QUERY  = 'query'
The 'query' parameter constant.
QUERY_ID  = 'queryId'
The 'queryId' parameter constant.

Properties

$queryId  : string
The internal query identifier.

Methods

getQueryID()  : string
Returns the internal query identifier.
setQueryID()  : void
Sets the internal query identifier.

Constants

QUERY

The 'query' parameter constant.

public mixed QUERY = 'query'

QUERY_ID

The 'queryId' parameter constant.

public mixed QUERY_ID = 'queryId'

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

getQueryID()

Returns the internal query identifier.

public getQueryID() : string
Tags
example
$id = $this->getQueryID();
Return values
string

The current value of the query ID.

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 'queryId'. 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 'queryId'.

Tags
example
$this->setQueryID('my_query'); // sets queryId to 'my_query'

$this->setQueryID(['queryId' => 'users_by_name']);

$this->setQueryID(null); // auto-generates ID like 'query_2384721'

        
On this page

Search results