adachsoft / dynamic-tables-core
Framework-agnostic application layer for dynamic tables, entries, views, and column types
Requires
- php: >=8.3
- adachsoft/dynamic-table-contract: ^1
Requires (Dev)
- adachsoft/php-code-style: ^0.7.4
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^13.0
- rector/rector: ^2.9
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Framework-agnostic application layer of the Dynamic Tables ecosystem: facades for managing
table definitions, table entries (rows), views and column types on top of
adachsoft/dynamic-table-contract.
The package contains no storage and no HTTP code. Storage is whatever implements the contract
repositories (JSON files, SQL, …); HTTP is provided by adachsoft/dynamic-tables-symfony-bundle.
Namespace: AdachSoft\DynamicTablesCore
Installation
Install the package with Composer:
composer require adachsoft/dynamic-tables-core
Integration
The library is framework-agnostic and does not provide storage. Integrate it by supplying implementations of the repository interfaces from adachsoft/dynamic-table-contract to the facades in your application's composition root. Use your framework's dependency injection container to register those adapters and the facades as services. For Symfony applications, the adachsoft/dynamic-tables-symfony-bundle package provides framework integration.
Once the facades are available in your application, define a table and create entries through their public APIs:
$tableFacade->createTable(new CreateTableDto('visits', [
new ColumnDefinitionDto('note', 'string', required: false, order: 0),
]));
$entry = $entryFacade->createEntry('visits', ['note' => 'checkup']);
Requirements
- PHP
>= 8.3 adachsoft/dynamic-table-contract^1(shipsdynamic-table-viewanddynamic-table-view-json)
Usage
Use the injected facades to create table definitions and entries. See the examples below and in docs/examples/.
Facades
| Interface | Responsibility | Depends on |
|---|---|---|
Table\Facade\TableFacadeInterface | CRUD of table definitions (columns with config / displayConfig) | TableRepositoryInterface |
Entry\Facade\EntryFacadeInterface | CRUD of rows; values are validated by the row repository | RowRepositoryInterface, TableRepositoryInterface |
View\Facade\ViewFacadeInterface | CRUD of view definitions and reading view data | ViewDefinitionRepositoryInterface, ViewRepositoryInterface, ViewDefinitionSerializerInterface |
ColumnType\Facade\ColumnTypeFacadeInterface | Describes available column types and their options | ColumnTypeRegistryInterface, TypeDescriptorReader |
$tableFacade->createTable(new CreateTableDto('visits', [
new ColumnDefinitionDto('owner_id', 'relation', required: true, order: 0, config: [
'target_table_id' => 'owners',
]),
new ColumnDefinitionDto('note', 'string', required: false, order: 1),
]));
$entryFacade->createEntry('visits', ['owner_id' => 1, 'note' => 'checkup']);
Installing predefined tables
Table\Installer\TableInstaller::installFromDirectory() reads *.json table definitions (id + columns, the
shape mapped by Table\Mapper\TableDefinitionMapper) and creates the tables that do not exist yet. Existing tables
are left untouched unless $addMissingColumns is set; then columns the definition has and the table lacks are
appended. Existing columns and rows are never changed, so the call is safe to repeat. It returns a
TableInstallResultDto with the created, updated and skipped table identifiers.
Errors
Facades do not wrap storage errors: they let the exception interfaces defined by the contract propagate, so callers catch one vocabulary regardless of the storage in use.
| Situation | Exception |
|---|---|
Table id does not match [a-z_]+ | Table\Exception\InvalidTableIdException (\InvalidArgumentException) |
| Unknown table | DynamicTableContract\Exception\TableNotFoundExceptionInterface |
| Table already exists | DynamicTableContract\Exception\DuplicateTableExceptionInterface |
| Unknown row | DynamicTableContract\Exception\RowNotFoundExceptionInterface |
| Row values break the schema | DynamicTableContract\Exception\ValidationExceptionInterface |
| Unknown / duplicate view | DynamicTableView\Exception\ViewDefinitionNotFoundExceptionInterface / DuplicateViewDefinitionExceptionInterface |
EntryFacade checks that the table exists before every operation, because a row repository
is free to return an empty collection for an unknown table.
Querying without native query support
Query\InMemoryQueryableRowRepository decorates any RowRepositoryInterface and implements
QueryableRowRepositoryInterface by filtering rows in memory. Use it with storages that cannot
query on their own (e.g. JSON files). Sorting, pagination and projection are left to the caller.
Data integrity
EntryFacade::deleteEntry()throwsEntryReferencedExceptionInterfacewhen a relation column of any table points at the entry's row identifier.EntryFacadedrops anidkey from submitted values, andTableFacaderejects a column namedidand duplicated column names: the row identifier is assigned by the storage.InMemoryQueryableRowRepository, given a table repository, completes every row withnullfor table columns it lacks, so queries and views can address columns added after a row was stored.
Change history and locks
Audit\ChangeRecorderappends every change made throughEntryFacadeto aChangeLogRepositoryInterface(JsonLinesChangeLogRepository: one append-only.jsonlfile per table;InMemoryChangeLogRepository).Audit\Facade\HistoryFacadereads it per table or per entry.Lock\Facade\TableLockFacadelocks and unlocks a table;EntryFacade::deleteEntry()andTableFacade::deleteTable()throwTableLockedExceptionInterfacefor a locked table. Deleting a table removes its lock and change log.- Both are optional constructor arguments of the facades: without them nothing is recorded or locked.
Design rules
- No framework, no storage — only contract interfaces are injected.
- Thin facades — mapping between public DTOs and contract DTOs; no pass-through service layer.
- One id rule —
Table\Vo\TableIdVois the single place validating table identifiers.
Development
./vendor/bin/phpunit --configuration phpunit.xml
./vendor/bin/phpstan analyse src tests
License
MIT