Search by

adachsoft / dynamic-tables-core

Arkadiusz Adach

Framework-agnostic application layer for dynamic tables, entries, views, and column types

Package info

gitlab.com/a.adach/dynamic-tables-core

Issues

pkg:composer/adachsoft/dynamic-tables-core

Statistics

Installs: 9

Dependents: 1

Suggesters: 0

Stars: 0

v0.1.0 2026-11-26 14:42 UTC

This package is auto-updated.

Last update: 2026-11-26 13:42:47 UTC


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 (ships dynamic-table-view and dynamic-table-view-json)

Usage

Use the injected facades to create table definitions and entries. See the examples below and in docs/examples/.

Facades

InterfaceResponsibilityDepends on
Table\Facade\TableFacadeInterfaceCRUD of table definitions (columns with config / displayConfig)TableRepositoryInterface
Entry\Facade\EntryFacadeInterfaceCRUD of rows; values are validated by the row repositoryRowRepositoryInterface, TableRepositoryInterface
View\Facade\ViewFacadeInterfaceCRUD of view definitions and reading view dataViewDefinitionRepositoryInterface, ViewRepositoryInterface, ViewDefinitionSerializerInterface
ColumnType\Facade\ColumnTypeFacadeInterfaceDescribes available column types and their optionsColumnTypeRegistryInterface, 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.

SituationException
Table id does not match [a-z_]+Table\Exception\InvalidTableIdException (\InvalidArgumentException)
Unknown tableDynamicTableContract\Exception\TableNotFoundExceptionInterface
Table already existsDynamicTableContract\Exception\DuplicateTableExceptionInterface
Unknown rowDynamicTableContract\Exception\RowNotFoundExceptionInterface
Row values break the schemaDynamicTableContract\Exception\ValidationExceptionInterface
Unknown / duplicate viewDynamicTableView\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() throws EntryReferencedExceptionInterface when a relation column of any table points at the entry's row identifier.
  • EntryFacade drops an id key from submitted values, and TableFacade rejects a column named id and duplicated column names: the row identifier is assigned by the storage.
  • InMemoryQueryableRowRepository, given a table repository, completes every row with null for table columns it lacks, so queries and views can address columns added after a row was stored.

Change history and locks

  • Audit\ChangeRecorder appends every change made through EntryFacade to a ChangeLogRepositoryInterface (JsonLinesChangeLogRepository: one append-only .jsonl file per table; InMemoryChangeLogRepository). Audit\Facade\HistoryFacade reads it per table or per entry.
  • Lock\Facade\TableLockFacade locks and unlocks a table; EntryFacade::deleteEntry() and TableFacade::deleteTable() throw TableLockedExceptionInterface for 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

  1. No framework, no storage — only contract interfaces are injected.
  2. Thin facades — mapping between public DTOs and contract DTOs; no pass-through service layer.
  3. One id rule — Table\Vo\TableIdVo is the single place validating table identifiers.

Development

./vendor/bin/phpunit --configuration phpunit.xml
./vendor/bin/phpstan analyse src tests

License

MIT