Repository navigation
Internals Database DatabaseManager
Framework Internals · Subsystem overview · Developer guide
Source: awt_src/classes/database/DatabaseManager.php · Snapshot 8411f4287706.
DatabaseManager delegates SQL generation to QueryBuilder, execution to IProvider, and result caching to ICache. Schema builders use MySQL DDL and the framework table registry.
use database\cache\DatabaseCache;
use database\interface\ICache;
use database\interface\IProvider;
use database\provider\DatabaseProvider;
use database\query\QueryBuilder;
use database\trait\DoNotCache;
use PDO;class DatabaseManagerSource description (behavioral corrections are recorded in Known discrepancies):
DatabaseManager
Facade that exposes a fluent, chainable API for all database operations. Every concern is delegated to a dedicated collaborator:
QueryBuilder Assembles parameterised SQL strings and their PDO bindings. IProvider Executes prepared statements against the database connection. ICache Stores SELECT results and evicts them when data changes.
Cache behaviour is determined at construction time by inspecting whether the DoNotCache trait is present on the concrete class. When it is, all cache reads and writes are skipped for the lifetime of the instance; the database is always queried directly.
All dependencies have default values and can be replaced via constructor injection, making the class straightforward to test in isolation.
Declarations below preserve visibility, type, default and modifiers exactly. A typed property without an initializer remains uninitialized until its constructor or another method assigns it. Mutable fields belong to this instance unless marked static; readonly fields can be initialized once. Constructor-promoted properties are also listed below.
| Member | Declaration | Purpose or source contract |
|---|---|---|
| $tables | public array $tables = []; |
@var array Holds the result of the last getTables() call for schema inspection. |
| $lastQuery | private string $lastQuery = ''; |
@var string The SQL string produced by the most recently executed operation. |
| $cacheOn | private bool $cacheOn = true; |
@var bool Controls whether the cache is consulted on reads and populated on misses. Set to false when the DoNotCache trait is detected on the current class or any of its parents. |
| Constructor-promoted | private IProvider $provider = new DatabaseProvider() |
Initialized from the constructor argument; default expression is evaluated when the argument is omitted. |
| Constructor-promoted | private QueryBuilder $builder = new QueryBuilder() |
Initialized from the constructor argument; default expression is evaluated when the argument is omitted. |
| Constructor-promoted | private ICache $cache = new DatabaseCache() |
Initialized from the constructor argument; default expression is evaluated when the argument is omitted. |
| Method | Signature |
|---|---|
| __construct | public function __construct( private IProvider $provider = new DatabaseProvider(), private QueryBuilder $builder = new QueryBuilder(), private ICache $cache = new DatabaseCache(), ) |
| useConnectionFrom | public function useConnectionFrom(DatabaseManager $source): static |
| table | public function table(string $name): self |
| insert | public function insert(array $data): self |
| select | public function select(array $columns = ['*']): self |
| join | public function join(string $table, string $on, string $type = 'INNER'): self |
| where | public function where(array $conditions, bool $useNot = false, string $conjunction = 'AND'): self |
| andWhere | public function andWhere(array $conditions, bool $useNot = false): self |
| orWhere | public function orWhere(array $conditions, bool $useNot = false): self |
| joinOn | public function joinOn(string $table, string $left, string $right, string $type = 'INNER'): self |
| first | public function first(): ?array |
| like | public function like(array $conditions, bool $useNot = false): self |
| orderBy | public function orderBy(string $column, string $direction = 'ASC'): self |
| executeInsert | public function executeInsert(): ?int |
| get | public function get(?int $limit = null, ?int $offset = null): array |
| update | public function update(array $data): bool |
| delete | public function delete(): bool |
| transaction | public function transaction(callable $callback): mixed |
| canCache | private function canCache(string $sql): bool |
| invalidateAfterWrite | private function invalidateAfterWrite(string $table): void |
| queryTable | protected function queryTable(): string |
| builderSupportsCaching | private function builderSupportsCaching(string $sql): bool |
| getTables | public function getTables(): self |
| checkTable | public function checkTable(string $table): bool |
| checkColumn | public function checkColumn(string $table, string $column): bool |
| getLastQuery | public function getLastQuery(): string |
| showDebugTrace | private static function showDebugTrace(): void |
| getCallerChain | private static function getCallerChain(): string |
| class_uses_recursive | private static function class_uses_recursive(object|string $class): array |
public function __construct(
private IProvider $provider = new DatabaseProvider(),
private QueryBuilder $builder = new QueryBuilder(),
private ICache $cache = new DatabaseCache(),
)| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$provider |
private IProvider $provider = new DatabaseProvider() |
Executes SQL against the database. |
$builder |
private QueryBuilder $builder = new QueryBuilder() |
Assembles SQL strings and bindings from fluent calls. |
$cache |
private ICache $cache = new DatabaseCache() |
Stores and invalidates cached query results. |
@param IProvider $provider Executes SQL against the database. @param QueryBuilder $builder Assembles SQL strings and bindings from fluent calls. @param ICache $cache Stores and invalidates cached query results.
State writes: $this->cacheOn.
Implementation, validation guards and interaction order
/**
* @param IProvider $provider Executes SQL against the database.
* @param QueryBuilder $builder Assembles SQL strings and bindings from fluent calls.
* @param ICache $cache Stores and invalidates cached query results.
*/
public function __construct(
private IProvider $provider = new DatabaseProvider(),
private QueryBuilder $builder = new QueryBuilder(),
private ICache $cache = new DatabaseCache(),
) {
$this->cacheOn = !in_array(DoNotCache::class, self::class_uses_recursive($this));
}public function useConnectionFrom(DatabaseManager $source): static| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$source |
DatabaseManager $source |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
Reuse a connection/cache while keeping query-building state independent.
State writes: $this->provider, $this->cache, $this->builder.
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
/** Reuse a connection/cache while keeping query-building state independent. */
public function useConnectionFrom(DatabaseManager $source): static
{
$this->provider = $source->provider;
$this->cache = $source->cache;
$this->builder = new QueryBuilder();
return $this;
}public function table(string $name): self| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$name |
string $name |
Table name. |
Set the table all subsequent query clauses will target.
@param string $name Table name.
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
/**
* Set the table all subsequent query clauses will target.
*
* @param string $name Table name.
*/
public function table(string $name): self
{
$this->builder->table($name);
return $this;
}public function insert(array $data): self| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$data |
array $data |
Associative array of column => value pairs to insert. |
Prepare column/value pairs for an INSERT statement. Must be followed by executeInsert() to run the query.
@param array $data Associative array of column => value pairs to insert.
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
/**
* Prepare column/value pairs for an INSERT statement.
* Must be followed by executeInsert() to run the query.
*
* @param array $data Associative array of column => value pairs to insert.
*/
public function insert(array $data): self
{
$this->builder->insert($data);
return $this;
}public function select(array $columns = ['*']): self| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$columns |
array $columns = ['*'] |
List of column names or expressions to select. |
Set the column list for a SELECT statement. Defaults to wildcard (*) when no columns are provided.
@param array $columns List of column names or expressions to select.
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
/**
* Set the column list for a SELECT statement.
* Defaults to wildcard (*) when no columns are provided.
*
* @param array $columns List of column names or expressions to select.
*/
public function select(array $columns = ['*']): self
{
$this->builder->select($columns);
return $this;
}public function join(string $table, string $on, string $type = 'INNER'): self| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$table |
string $table |
The table to join. |
$on |
string $on |
The ON condition (e.g. "posts.user_id = users.id"). |
$type |
string $type = 'INNER' |
Join type: INNER, LEFT, RIGHT, etc. Defaults to INNER. |
Append a JOIN clause to the current SELECT query. Multiple calls append multiple joins in the order they are called.
@param string $table The table to join. @param string $on The ON condition (e.g. "posts.user_id = users.id"). @param string $type Join type: INNER, LEFT, RIGHT, etc. Defaults to INNER.
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
/**
* Append a JOIN clause to the current SELECT query.
* Multiple calls append multiple joins in the order they are called.
*
* @param string $table The table to join.
* @param string $on The ON condition (e.g. "posts.user_id = users.id").
* @param string $type Join type: INNER, LEFT, RIGHT, etc. Defaults to INNER.
*/
public function join(string $table, string $on, string $type = 'INNER'): self
{
$this->builder->join($table, $on, $type);
return $this;
}public function where(array $conditions, bool $useNot = false, string $conjunction = 'AND'): self| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$conditions |
array $conditions |
Associative array of column => value pairs. |
$useNot |
bool $useNot = false |
When true, uses != instead of = for all conditions. |
$conjunction |
string $conjunction = 'AND' |
Logical operator joining multiple conditions: AND or OR. |
Add a WHERE clause using equality (or inequality) conditions.
All column/value pairs are recorded and later forwarded to the cache layer so that CUD operations can evict only the cache entries whose conditions overlap with the mutation.
@param array $conditions Associative array of column => value pairs. @param bool $useNot When true, uses != instead of = for all conditions. @param string $conjunction Logical operator joining multiple conditions: AND or OR.
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
/**
* Add a WHERE clause using equality (or inequality) conditions.
*
* All column/value pairs are recorded and later forwarded to the cache
* layer so that CUD operations can evict only the cache entries whose
* conditions overlap with the mutation.
*
* @param array $conditions Associative array of column => value pairs.
* @param bool $useNot When true, uses != instead of = for all conditions.
* @param string $conjunction Logical operator joining multiple conditions: AND or OR.
*/
public function where(array $conditions, bool $useNot = false, string $conjunction = 'AND'): self
{
$this->builder->where($conditions, $useNot, $conjunction);
return $this;
}public function andWhere(array $conditions, bool $useNot = false): self| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$conditions |
array $conditions |
Column/value predicate map; values are bound and identifiers validated by QueryBuilder. |
$useNot |
bool $useNot = false |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
public function andWhere(array $conditions, bool $useNot = false): self
{
$this->builder->andWhere($conditions, $useNot);
return $this;
}public function orWhere(array $conditions, bool $useNot = false): self| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$conditions |
array $conditions |
Column/value predicate map; values are bound and identifiers validated by QueryBuilder. |
$useNot |
bool $useNot = false |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
public function orWhere(array $conditions, bool $useNot = false): self
{
$this->builder->orWhere($conditions, $useNot);
return $this;
}public function joinOn(string $table, string $left, string $right, string $type = 'INNER'): self| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$table |
string $table |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$left |
string $left |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$right |
string $right |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$type |
string $type = 'INNER' |
Expected class/type or enum selection according to the signature. |
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
public function joinOn(string $table, string $left, string $right, string $type = 'INNER'): self
{
$this->builder->joinOn($table, $left, $right, $type);
return $this;
}public function first(): ?arrayReturn expressions (including local callbacks): $this->get(1)[0] ?? null.
Implementation, validation guards and interaction order
public function first(): ?array { return $this->get(1)[0] ?? null; }public function like(array $conditions, bool $useNot = false): self| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$conditions |
array $conditions |
Associative array of column => pattern pairs. |
$useNot |
bool $useNot = false |
When true, uses NOT LIKE instead of LIKE. |
Add a WHERE clause using LIKE pattern matching.
@param array $conditions Associative array of column => pattern pairs. @param bool $useNot When true, uses NOT LIKE instead of LIKE.
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
/**
* Add a WHERE clause using LIKE pattern matching.
*
* @param array $conditions Associative array of column => pattern pairs.
* @param bool $useNot When true, uses NOT LIKE instead of LIKE.
*/
public function like(array $conditions, bool $useNot = false): self
{
$this->builder->like($conditions, $useNot);
return $this;
}public function orderBy(string $column, string $direction = 'ASC'): self| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$column |
string $column |
The column to sort by. |
$direction |
string $direction = 'ASC' |
ASC or DESC. Defaults to ASC. |
Append an ORDER BY expression to the SELECT query. Multiple calls append multiple sort expressions in the order called.
@param string $column The column to sort by. @param string $direction ASC or DESC. Defaults to ASC.
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
/**
* Append an ORDER BY expression to the SELECT query.
* Multiple calls append multiple sort expressions in the order called.
*
* @param string $column The column to sort by.
* @param string $direction ASC or DESC. Defaults to ASC.
*/
public function orderBy(string $column, string $direction = 'ASC'): self
{
$this->builder->orderBy($column, $direction);
return $this;
}public function executeInsert(): ?intExecute the INSERT prepared by insert() and return the new row's ID.
After a successful insert, all cached queries for the target table are invalidated. Because an INSERT carries no WHERE conditions, there is no basis for a narrower eviction; the entire table cache is flushed.
@return int|null The auto-increment ID of the inserted row, or null if no ID was generated.
State writes: $this->lastQuery.
Return expressions (including local callbacks): $id ?: null.
Implementation, validation guards and interaction order
/**
* Execute the INSERT prepared by insert() and return the new row's ID.
*
* After a successful insert, all cached queries for the target table are
* invalidated. Because an INSERT carries no WHERE conditions, there is no
* basis for a narrower eviction; the entire table cache is flushed.
*
* @return int|null The auto-increment ID of the inserted row, or null if
* no ID was generated.
*/
public function executeInsert(): ?int
{
$payload = $this->builder->buildInsert();
$this->builder->reset();
$stmt = $this->provider->execute($payload->sql, $payload->bindings);
$stmt->closeCursor();
$id = $this->provider->lastInsertId();
$this->invalidateAfterWrite($payload->table);
$this->lastQuery = $payload->sql;
self::showDebugTrace();
return $id ?: null;
}public function get(?int $limit = null, ?int $offset = null): array| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$limit |
?int $limit = null |
Maximum number of rows to return. |
$offset |
?int $offset = null |
Number of rows to skip before returning results. |
Execute the SELECT prepared by select(), where(), join(), and orderBy(), then return all matching rows as an associative array.
Read path when caching is active:
- Check the cache. On a hit, return the stored rows immediately.
- On a miss, execute the query against the database.
- Store the result in the cache, indexed by the SQL string and the raw WHERE conditions, then return the rows.
When the DoNotCache trait is present, steps 1 and 3 are skipped and the database is always queried directly.
@param int|null $limit Maximum number of rows to return. @param int|null $offset Number of rows to skip before returning results.
@return array Rows as associative arrays, keyed by column name.
State writes: $this->lastQuery.
Return expressions (including local callbacks): $cached; $result.
Implementation, validation guards and interaction order
/**
* Execute the SELECT prepared by select(), where(), join(), and orderBy(),
* then return all matching rows as an associative array.
*
* Read path when caching is active:
* 1. Check the cache. On a hit, return the stored rows immediately.
* 2. On a miss, execute the query against the database.
* 3. Store the result in the cache, indexed by the SQL string and the
* raw WHERE conditions, then return the rows.
*
* When the DoNotCache trait is present, steps 1 and 3 are skipped and the
* database is always queried directly.
*
* @param int|null $limit Maximum number of rows to return.
* @param int|null $offset Number of rows to skip before returning results.
*
* @return array Rows as associative arrays, keyed by column name.
*/
public function get(?int $limit = null, ?int $offset = null): array
{
$payload = $this->builder->buildSelect($limit, $offset);
$this->builder->reset();
$this->lastQuery = $payload->sql;
self::showDebugTrace();
// Include binding values and types; never reuse pre-refactor SQL-only entries.
$cacheKey = 'v2:' . hash('sha256', serialize([$payload->sql, $payload->bindings]));
if ($this->canCache($payload->sql)) {
$cached = $this->cache->get($payload->table, $cacheKey);
if ($cached !== false) {
return $cached;
}
}
$stmt = $this->provider->execute($payload->sql, $payload->bindings);
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ($this->canCache($payload->sql))
$this->cache->set($payload->table, $cacheKey, $result, $payload->conditions);
return $result;
}public function update(array $data): bool| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$data |
array $data |
Associative array of column => new value pairs to set. |
Execute the UPDATE prepared by where() and return whether any rows changed.
After execution, all cached queries for the table are invalidated. This also covers predicates on columns different from the mutation filter.
@param array $data Associative array of column => new value pairs to set.
@return bool True if at least one row was modified, false otherwise.
State writes: $this->lastQuery.
Return expressions (including local callbacks): $result.
Implementation, validation guards and interaction order
/**
* Execute the UPDATE prepared by where() and return whether any rows changed.
*
* After execution, all cached queries for the table are invalidated.
* This also covers predicates on columns different from the mutation filter.
*
* @param array $data Associative array of column => new value pairs to set.
*
* @return bool True if at least one row was modified, false otherwise.
*/
public function update(array $data): bool
{
$payload = $this->builder->buildUpdate($data);
$this->builder->reset();
$stmt = $this->provider->execute($payload->sql, $payload->bindings);
$result = $stmt->rowCount() > 0;
$stmt->closeCursor();
$this->invalidateAfterWrite($payload->table);
$this->lastQuery = $payload->sql;
self::showDebugTrace();
return $result;
}public function delete(): boolExecute the DELETE prepared by where() and return whether any rows were removed.
Calling delete() without a preceding where() call throws a LogicException. To delete all rows intentionally, use where(['1' => '1']) first.
All cached queries for the table are invalidated, as with update().
@return bool True if at least one row was deleted, false otherwise.
@throws \LogicException When no WHERE clause has been set.
State writes: $this->lastQuery.
Return expressions (including local callbacks): $result.
Implementation, validation guards and interaction order
/**
* Execute the DELETE prepared by where() and return whether any rows were removed.
*
* Calling delete() without a preceding where() call throws a LogicException.
* To delete all rows intentionally, use where(['1' => '1']) first.
*
* All cached queries for the table are invalidated, as with update().
*
* @return bool True if at least one row was deleted, false otherwise.
*
* @throws \LogicException When no WHERE clause has been set.
*/
public function delete(): bool
{
$payload = $this->builder->buildDelete();
$this->builder->reset();
$stmt = $this->provider->execute($payload->sql, $payload->bindings);
$result = $stmt->rowCount() > 0;
$stmt->closeCursor();
$this->invalidateAfterWrite($payload->table);
$this->lastQuery = $payload->sql;
self::showDebugTrace();
return $result;
}public function transaction(callable $callback): mixed| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$callback |
callable $callback |
Synchronous callback; its result/failure follows the return/transaction trace below. |
Return expressions (including local callbacks): $this->provider->transaction(fn() => $callback($this)).
Explicit exceptions: \LogicException. The guards in the implementation below show when each is raised; exceptions from collaborators also propagate unless caught.
Implementation, validation guards and interaction order
public function transaction(callable $callback): mixed
{
if (!$this->provider instanceof \database\interface\ITransactionalProvider) {
throw new \LogicException('This provider does not support transactions.');
}
return $this->provider->transaction(fn() => $callback($this));
}private function canCache(string $sql): bool| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$sql |
string $sql |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
Return expressions (including local callbacks): $this->cacheOn && $this->builderSupportsCaching($sql) && !($this->provider instanceof \database\interface\ITransactionalProvider && $this->provider->inTransaction()).
Implementation, validation guards and interaction order
private function canCache(string $sql): bool
{
return $this->cacheOn && $this->builderSupportsCaching($sql)
&& !($this->provider instanceof \database\interface\ITransactionalProvider && $this->provider->inTransaction());
}private function invalidateAfterWrite(string $table): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$table |
string $table |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
Computes or delegates the operation shown below; no explicit receiver property assignment or throw occurs in this method.
Implementation, validation guards and interaction order
private function invalidateAfterWrite(string $table): void
{
$cache = $this->cache;
if ($this->provider instanceof \database\interface\ITransactionalProvider) {
$this->provider->afterCommit(fn() => $cache->invalidateTable($table));
} else $cache->invalidateTable($table);
}protected function queryTable(): stringReturn expressions (including local callbacks): $this->builder->getTable().
Implementation, validation guards and interaction order
protected function queryTable(): string { return $this->builder->getTable(); }private function builderSupportsCaching(string $sql): bool| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$sql |
string $sql |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
Return expressions (including local callbacks): !preg_match('/\bJOIN\b/i', $sql).
Implementation, validation guards and interaction order
private function builderSupportsCaching(string $sql): bool
{
// Join results also depend on other tables. Bypass caching until the cache
// can track all referenced tables rather than only the primary table.
return !preg_match('/\bJOIN\b/i', $sql);
}public function getTables(): selfFetch all table and column definitions from the framework schema tables and store them in $this->tables for use by checkTable() and checkColumn().
Results go through the normal get() path and are cached like any other SELECT query.
State writes: $this->tables.
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
// =========================================================================
// Schema helpers
// =========================================================================
/**
* Fetch all table and column definitions from the framework schema tables
* and store them in $this->tables for use by checkTable() and checkColumn().
*
* Results go through the normal get() path and are cached like any other
* SELECT query.
*/
public function getTables(): self
{
$this->tables = $this->table('awt_table')
->select(['*'])
->where(['1' => 1])
->join('awt_table_structure', 'awt_table.id = awt_table_structure.table_id')
->get();
return $this;
}public function checkTable(string $table): bool| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$table |
string $table |
The table name to look for. |
Check whether a table with the given name exists in the schema.
Calls getTables() automatically if the schema has not been loaded yet.
@param string $table The table name to look for.
@return bool True if the table exists, false otherwise.
Return expressions (including local callbacks): true; false.
Implementation, validation guards and interaction order
/**
* Check whether a table with the given name exists in the schema.
*
* Calls getTables() automatically if the schema has not been loaded yet.
*
* @param string $table The table name to look for.
*
* @return bool True if the table exists, false otherwise.
*/
public function checkTable(string $table): bool
{
if (empty($this->tables)) {
$this->getTables();
}
foreach ($this->tables as $row) {
if (isset($row['name']) && $row['name'] === $table) {
return true;
}
}
return false;
}public function checkColumn(string $table, string $column): bool| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$table |
string $table |
The table to inspect. |
$column |
string $column |
The column name to look for within that table. |
Check whether a specific column exists within a specific table.
Calls getTables() automatically if the schema has not been loaded yet.
@param string $table The table to inspect. @param string $column The column name to look for within that table.
@return bool True if the column exists in the table, false otherwise.
Return expressions (including local callbacks): true; false.
Implementation, validation guards and interaction order
/**
* Check whether a specific column exists within a specific table.
*
* Calls getTables() automatically if the schema has not been loaded yet.
*
* @param string $table The table to inspect.
* @param string $column The column name to look for within that table.
*
* @return bool True if the column exists in the table, false otherwise.
*/
public function checkColumn(string $table, string $column): bool
{
if (empty($this->tables)) {
$this->getTables();
}
foreach ($this->tables as $row) {
if (
isset($row['name'], $row['column_name']) &&
$row['name'] === $table &&
$row['column_name'] === $column
) {
return true;
}
}
return false;
}public function getLastQuery(): stringReturn the SQL string produced by the most recently executed operation. Useful for logging and verifying query output during development.
Return expressions (including local callbacks): $this->lastQuery.
Implementation, validation guards and interaction order
// =========================================================================
// Debug helpers
// =========================================================================
/**
* Return the SQL string produced by the most recently executed operation.
* Useful for logging and verifying query output during development.
*/
public function getLastQuery(): string
{
return $this->lastQuery;
}private static function showDebugTrace(): voidPrint a chain of file/line references showing where the current SQL call originated. Output is suppressed unless both DEBUG and SHOW_SQL_CONNECTIONS_CALLS constants are defined and truthy.
Computes or delegates the operation shown below; no explicit receiver property assignment or throw occurs in this method.
Implementation, validation guards and interaction order
/**
* Print a chain of file/line references showing where the current SQL call
* originated. Output is suppressed unless both DEBUG and
* SHOW_SQL_CONNECTIONS_CALLS constants are defined and truthy.
*/
private static function showDebugTrace(): void
{
if (!defined('DEBUG') || !DEBUG) {
return;
}
if (!defined('SHOW_SQL_CONNECTIONS_CALLS') || !SHOW_SQL_CONNECTIONS_CALLS) {
return;
}
echo 'SQL called by: ' . self::getCallerChain() . '<br>';
}private static function getCallerChain(): stringBuild a human-readable call chain from the current backtrace.
Frames are reversed so the outermost caller appears first, making it easier to trace the origin of a query through layers of nested calls.
@return string File:line pairs joined by " -> ", outermost caller first.
Return expressions (including local callbacks): implode(' -> ', array_reverse($parts)).
Implementation, validation guards and interaction order
/**
* Build a human-readable call chain from the current backtrace.
*
* Frames are reversed so the outermost caller appears first, making it
* easier to trace the origin of a query through layers of nested calls.
*
* @return string File:line pairs joined by " -> ", outermost caller first.
*/
private static function getCallerChain(): string
{
$frames = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$parts = [];
foreach ($frames as $frame) {
if (isset($frame['file'])) {
$parts[] = basename($frame['file']) . ':' . ($frame['line'] ?? '?');
}
}
return implode(' -> ', array_reverse($parts));
}private static function class_uses_recursive(object|string $class): array| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$class |
object|string $class |
The object instance or fully-qualified class name to inspect. |
Collect all traits used by a class and its full parent chain.
PHP's built-in class_uses() only inspects the class it is directly given and does not walk up the inheritance tree. This method merges the trait lists for the given class and every parent class, ensuring that traits declared anywhere in the hierarchy are detected.
Used at construction time to determine whether the DoNotCache trait is present on the concrete class being instantiated.
@param object|string $class The object instance or fully-qualified class name to inspect.
@return array Flat array of fully-qualified trait names found across the hierarchy.
Return expressions (including local callbacks): array_unique($results).
Implementation, validation guards and interaction order
/**
* Collect all traits used by a class and its full parent chain.
*
* PHP's built-in class_uses() only inspects the class it is directly given
* and does not walk up the inheritance tree. This method merges the trait
* lists for the given class and every parent class, ensuring that traits
* declared anywhere in the hierarchy are detected.
*
* Used at construction time to determine whether the DoNotCache trait is
* present on the concrete class being instantiated.
*
* @param object|string $class The object instance or fully-qualified class name to inspect.
*
* @return array Flat array of fully-qualified trait names found across the hierarchy.
*/
private static function class_uses_recursive(object|string $class): array
{
$results = [];
foreach (array_merge([$class], class_parents($class)) as $c) {
$results += class_uses($c);
}
return array_unique($results);
}AWT Framework Wiki · Home · Installation Guide · Developer Guide · Framework Internals
Philosophy · Architecture · Known discrepancies · Verification
Installation Guide
Developer Guide
- Learning sequence
- First package
- Package structure
- Lifecycle
- Runtimes
- Events and objects
- Routing and controllers
- Views and resources
- Database and models
- Storage and caching
- Configuration and CLI
- Responses and errors
- Extension points
Framework Internals
- Architecture
- Bootstrap
- Packages
- Runtime
- Events and context
- Objects
- HTTP routing and controllers
- Rendering
- Blade integration
- Database
- Models
- Storage and caching
- Settings
- CLI
- Identity and sessions
- Responses
- Errors
- Complete source inventory
Documentation notes