Repository navigation
Internals Database Creator Table TableRegistry
Framework Internals · Subsystem overview · Developer guide
Source: awt_src/classes/database/creator/table/TableRegistry.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\creator\interface\ITableRegistry;
use database\DatabaseManager;class TableRegistry implements ITableRegistrySource description (behavioral corrections are recorded in Known discrepancies):
TableRegistry
Manages the framework's schema registry: the awt_table and awt_table_structure tables that record every table and column created by the framework.
All reads and writes go through DatabaseManager so they participate in the same read-through cache and condition-aware invalidation as the rest of the application.
This class handles only registry data. It never issues DDL or touches the real database schema; that is TableSchemaProvider's responsibility.
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 |
|---|---|---|
| Constructor-promoted | private readonly DatabaseManager $db |
Initialized from the constructor argument; default expression is evaluated when the argument is omitted. |
| Method | Signature |
|---|---|
| __construct | public function __construct( private readonly DatabaseManager $db, ) |
| tableExists | public function tableExists(string $name): bool |
| columnExists | public function columnExists(string $table, string $column): bool |
| getTableId | public function getTableId(string $name): ?int |
| registerTable | public function registerTable(string $name, int $creatorId): int |
| registerColumn | public function registerColumn(int $tableId, string $columnName, string $columnType): void |
| unregisterTable | public function unregisterTable(string $name): void |
| unregisterColumn | public function unregisterColumn(string $table, string $column): void |
| updateColumnType | public function updateColumnType(string $table, string $column, string $newType): void |
| renameColumn | public function renameColumn(string $table, string $oldName, string $newName): void |
| findByOwner | public function findByOwner(int $ownerId): array |
public function __construct(
private readonly DatabaseManager $db,
);| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$db |
private readonly DatabaseManager $db |
The database manager used for all registry queries. |
@param DatabaseManager $db The database manager used for all registry queries.
Concrete no-op/default hook: this method performs no work. Override it where the lifecycle or extension contract calls for behavior.
public function tableExists(string $name): bool| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$name |
string $name |
Named key/label selected by this API; its exact scope is shown by the implementation trace. |
{@inheritdoc}
Return expressions (including local callbacks): !empty($rows).
Implementation, validation guards and interaction order
// =========================================================================
// ITableRegistry
// =========================================================================
/** {@inheritdoc} */
public function tableExists(string $name): bool
{
$rows = $this->db
->table('awt_table')
->select(['id'])
->where(['name' => $name])
->get();
return !empty($rows);
}public function columnExists(string $table, string $column): bool| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$table |
string $table |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$column |
string $column |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
{@inheritdoc}
Return expressions (including local callbacks): false; !empty($rows).
Implementation, validation guards and interaction order
/** {@inheritdoc} */
public function columnExists(string $table, string $column): bool
{
$tableId = $this->getTableId($table);
if ($tableId === null) {
return false;
}
$rows = $this->db
->table('awt_table_structure')
->select(['id'])
->where(['table_id' => $tableId, 'column_name' => $column])
->get();
return !empty($rows);
}public function getTableId(string $name): ?int| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$name |
string $name |
Named key/label selected by this API; its exact scope is shown by the implementation trace. |
{@inheritdoc}
Return expressions (including local callbacks): !empty($rows) ? (int) $rows[0]['id'] : null.
Implementation, validation guards and interaction order
/** {@inheritdoc} */
public function getTableId(string $name): ?int
{
$rows = $this->db
->table('awt_table')
->select(['id'])
->where(['name' => $name])
->get();
return !empty($rows) ? (int) $rows[0]['id'] : null;
}public function registerTable(string $name, int $creatorId): int| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$name |
string $name |
Named key/label selected by this API; its exact scope is shown by the implementation trace. |
$creatorId |
int $creatorId |
Package ownership ID written into schema registry records. |
{@inheritdoc}
Return expressions (including local callbacks): (int) $this->db ->table('awt_table') ->insert(['name' => $name, 'creator' => $creatorId]) ->executeInsert().
Implementation, validation guards and interaction order
/** {@inheritdoc} */
public function registerTable(string $name, int $creatorId): int
{
return (int) $this->db
->table('awt_table')
->insert(['name' => $name, 'creator' => $creatorId])
->executeInsert();
}public function registerColumn(int $tableId, string $columnName, string $columnType): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$tableId |
int $tableId |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$columnName |
string $columnName |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$columnType |
string $columnType |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
{@inheritdoc}
Computes or delegates the operation shown below; no explicit receiver property assignment or throw occurs in this method.
Implementation, validation guards and interaction order
/** {@inheritdoc} */
public function registerColumn(int $tableId, string $columnName, string $columnType): void
{
$this->db
->table('awt_table_structure')
->insert([
'table_id' => $tableId,
'column_name' => $columnName,
'column_type' => strtolower($columnType),
])
->executeInsert();
}public function unregisterTable(string $name): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$name |
string $name |
Named key/label selected by this API; its exact scope is shown by the implementation trace. |
{@inheritdoc}
Explicit exceptions: \RuntimeException. The guards in the implementation below show when each is raised; exceptions from collaborators also propagate unless caught.
Implementation, validation guards and interaction order
/** {@inheritdoc} */
public function unregisterTable(string $name): void
{
$tableId = $this->getTableId($name);
if ($tableId === null) {
return;
}
// Remove all column entries first to satisfy any foreign key constraints
// on awt_table_structure that reference awt_table.id.
$this->db->transaction(function () use ($tableId, $name): void {
// Tables with no registered columns legitimately delete zero column rows.
$this->db->table('awt_table_structure')->where(['table_id' => $tableId])->delete();
if (!$this->db->table('awt_table')->where(['id' => $tableId])->delete()) {
throw new \RuntimeException("Failed to unregister table: {$name}");
}
});
}public function unregisterColumn(string $table, string $column): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$table |
string $table |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$column |
string $column |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
{@inheritdoc}
Delegates to getTableId().
Implementation, validation guards and interaction order
/** {@inheritdoc} */
public function unregisterColumn(string $table, string $column): void
{
$tableId = $this->getTableId($table);
if ($tableId === null) {
return;
}
$this->db
->table('awt_table_structure')
->where(['table_id' => $tableId, 'column_name' => $column])
->delete();
}public function updateColumnType(string $table, string $column, string $newType): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$table |
string $table |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$column |
string $column |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$newType |
string $newType |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
{@inheritdoc}
Delegates to getTableId().
Implementation, validation guards and interaction order
/** {@inheritdoc} */
public function updateColumnType(string $table, string $column, string $newType): void
{
$tableId = $this->getTableId($table);
if ($tableId === null) {
return;
}
$this->db
->table('awt_table_structure')
->where(['table_id' => $tableId, 'column_name' => $column])
->update(['column_type' => strtolower($newType)]);
}public function renameColumn(string $table, string $oldName, string $newName): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$table |
string $table |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$oldName |
string $oldName |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$newName |
string $newName |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
{@inheritdoc}
Delegates to getTableId().
Implementation, validation guards and interaction order
/** {@inheritdoc} */
public function renameColumn(string $table, string $oldName, string $newName): void
{
$tableId = $this->getTableId($table);
if ($tableId === null) {
return;
}
$this->db
->table('awt_table_structure')
->where(['table_id' => $tableId, 'column_name' => $oldName])
->update(['column_name' => $newName]);
}public function findByOwner(int $ownerId): array| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$ownerId |
int $ownerId |
Owning record ID or null. |
{@inheritdoc}
Return expressions (including local callbacks): array_column($rows, 'name').
Implementation, validation guards and interaction order
/** {@inheritdoc} */
public function findByOwner(int $ownerId): array
{
$rows = $this->db->table('awt_table')->select(['name'])
->where(['creator' => $ownerId])->get();
return array_column($rows, 'name');
}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