Search by

adachsoft / dynamic-tables-symfony-bundle

Arkadiusz Adach

Symfony bundle exposing the Dynamic Tables ecosystem through HTTP APIs.

Package info

gitlab.com/a.adach/dynamic-tables-symfony-bundle

Issues

Type:symfony-bundle

pkg:composer/adachsoft/dynamic-tables-symfony-bundle

Statistics

Installs: 4

Dependents: 0

Suggesters: 0

Stars: 0

v0.2.0 2026-11-26 23:27 UTC

This package is auto-updated.

Last update: 2026-11-26 22:27:33 UTC


README

Symfony Bundle integration layer for the Dynamic Tables ecosystem.

This package exposes the whole ecosystem over HTTP in a Symfony application: table definitions, table entries, views, column types, form schema, lookup and display config. It provides the controllers, DI extension, configuration, request mappers, ETag handling and OpenAPI attributes.

Namespace: AdachSoft\DynamicTablesSymfonyBundle

Requirements

Installation

Install the package in your Symfony application:

composer require adachsoft/dynamic-tables-symfony-bundle

For local development in this repository, install its declared dependencies:

composer install

Composer maps the AdachSoft\DynamicTablesSymfonyBundle\ namespace to src/ and AdachSoft\DynamicTablesSymfonyBundle\Tests\ to tests/.

Register the bundle

// config/bundles.php
return [
    // ...
    AdachSoft\DynamicTablesSymfonyBundle\AdachSoftDynamicTablesBundle::class => ['all' => true],
];

Import routes

# config/routes.yaml
adachsoft_dynamic_tables:
    resource: '@AdachSoftDynamicTablesBundle/Resources/config/routes.yaml'

Required application services

The host application must register:

ServiceRequired
AdachSoft\DynamicTableContract\Repository\TableRepositoryInterfaceyes
AdachSoft\DynamicTableContract\Repository\RowRepositoryInterfaceyes
AdachSoft\DynamicTableView\Repository\ViewDefinitionRepositoryInterfaceyes
AdachSoft\DynamicTableView\Repository\ViewRepositoryInterfaceyes
AdachSoft\DynamicTableViewJson\Serializer\ViewDefinitionSerializerInterfaceyes
AdachSoft\DynamicTableContract\Query\Repository\QueryableRowRepositoryInterfaceoptional (lookup search is delegated to the storage; otherwise rows are filtered in memory)

Missing required services are reported at compile time by RequiredServicesCompilerPass. The bundle does not choose the storage: register the implementations you want (e.g. the JSON repositories from adachsoft/dynamic-table-json). Services registered by the application override the defaults registered by the bundle.

Configuration

# config/packages/adachsoft_dynamic_tables.yaml
adachsoft_dynamic_tables:
    tables:
        definitions_dir: '%kernel.project_dir%/config/dynamic_tables'
    views:
        definitions_dir: '%kernel.project_dir%/config/dynamic_views'
    entries:
        default_page_size: 25    # GET {prefix}/tables/{tableId}/listing
        max_page_size: 500
    form:
        storage:
            type: json   # json | in_memory
            json_dir: '%kernel.project_dir%/var/dynamic-tables/forms'
        widget:
            select_threshold: 50
            default_page_size: 20
    display_config:
        storage:
            type: json   # json | in_memory
            json_dir: '%kernel.project_dir%/var/dynamic-tables/display-configs'
    routing:
        prefix: /api
    openapi:
        tags:
            form_schema: 'Dynamic Tables - Form Schema'
            lookup: 'Dynamic Tables - Lookup'
            display_config: 'Dynamic Tables - Display Config'

All nodes are optional and use the defaults above.

  • form.storage.type / display_config.storage.type:
    • json — file repositories from dynamic-tables-form-json
    • in_memory — in-memory repositories from dynamic-tables-form-core (useful in tests)

Shipping tables with the application

Tables an application needs out of the box are kept as JSON files, one table per file, in the shape accepted by POST /tables. A file may also carry the table's display config (the shape accepted by PUT /tables/{tableId}/display-config):

{
    "id": "animal",
    "displayConfig": {"labelTemplate": "{name}", "searchableFields": ["name"], "title": "Animals"},
    "columns": [
        {"name": "name", "type": "string", "required": true, "displayConfig": {"label": "Name"}},
        {"name": "pet_owner_id", "type": "relation", "config": {"target_table_id": "pet_owner"}}
    ]
}
php bin/console dynamic-tables:install                 # reads tables.definitions_dir
php bin/console dynamic-tables:install some/dir        # or an explicit directory
php bin/console dynamic-tables:install --add-columns   # also append columns missing from existing tables

The command creates the tables that do not exist yet and saves a display config for tables that have none. It never changes or removes existing columns, rows or display configs, so it can be run on every deployment. With --add-columns, columns present in a definition and missing from an existing table are appended. All files are parsed before the first table is created; a malformed file fails the run.

Views are shipped the same way: one {"name", "type", "definition"} object per file (the body of POST /views) in views.definitions_dir (default config/dynamic_views, which may be missing). Missing views are created in file name order, so a view built on another view needs a later file name; existing views are never changed.

Presentation options

  • Column displayConfig.label – human readable column name; the form schema uses it as the field label.
  • Display config title – human readable table name.
  • Display config labelTemplate – how a record is labelled in lookups and relations.
  • Relation column displayConfig.widget – select or autocomplete; without it small tables are listed and large ones searched.
  • Relation column displayConfig.filterBy – {"field": "customer_id", "targetColumn": "customer_id"} offers only the records of the related table whose targetColumn holds the value of field of the same form (pick the customer first, then one of that customer's orders). The form schema passes it on as widgetParams.filterBy; the lookup takes it as filter[targetColumn]=value. The API enforces it as well: saving an entry whose relation points at a record of another parent is refused with 422 and the code relation_mismatch (RelationDependencyGuard).
  • Relation column displayConfig.quickAdd: true – the form may add a record of the related table without leaving the entry being edited (widgetParams.quickAdd); single relations only.
  • Date and datetime column displayConfig.defaultValue: "now" – a new entry starts with the current moment (widgetParams.defaultValue).

HTTP API

Default route prefix: /api (configurable via routing.prefix).

Tables — TableController

MethodPathStatus codes
GET{prefix}/tables200
GET{prefix}/tables/{tableId}200, 400, 404
POST{prefix}/tables201, 400, 409
PUT{prefix}/tables/{tableId}200, 400, 404
DELETE{prefix}/tables/{tableId}204, 400, 404

A table is {id, title, locked, columns, referencedBy}: title is the human readable name from the display config (null when none was set), locked tells whether its entries are protected against deletion, and referencedBy lists the relation columns pointing at the table ([{tableId, column}]), i.e. where its entries can have child entries.

A column is {name, type, required, order, config, displayConfig}. config carries the type-specific options listed by GET {prefix}/types, e.g. for a relation {"target_table_id": "owners"}.

Entries — TableEntryController

MethodPathStatus codes
GET{prefix}/tables/{tableId}/entries200, 400, 404
GET{prefix}/tables/{tableId}/listing200, 400, 404
GET{prefix}/tables/{tableId}/entries/{id}200, 400, 404
GET{prefix}/tables/{tableId}/entries/{id}/children200, 400, 404
POST{prefix}/tables/{tableId}/entries201, 400, 404, 422
PUT{prefix}/tables/{tableId}/entries/{id}200, 400, 404, 422
DELETE{prefix}/tables/{tableId}/entries/{id}204, 400, 404

An entry is a flat object: id plus one property per column. 422 carries {"error": "Validation failed", "errors": [{"column": "...", "code": "..."}]}.

GET .../entries returns every row at once. GET .../listing is what a list screen needs, so a client does not search or page in memory:

  • q — text looked for, case-insensitively, in the identifier, in every value and in the labels of related rows,
  • filter[column][operator]=value and sort=column,-other — as for view data; relation columns sort by label, empty values come last,
  • page (from 1; a page past the end gives the last one) and pageSize (default and limit: entries.* config).

It answers {items, labels, totalCount, page, pageSize, pageCount}. labels holds, per relation column, the label of each referenced row by its key — {"owner_id": {"2": "Anna Nowak"}} — built from the label template of the target table.

GET .../entries/{id}/children returns the entries of other tables that point at the entry through a relation column, one group per table and column: [{table, column, items, labels}]. Groups without entries are included.

Data integrity rules of entries:

  • an entry referenced by a relation column of another entry cannot be deleted (409); delete or re-point the referencing entries first,
  • a table that a relation column of another table points at cannot be deleted (409),
  • id is the row identifier assigned by the storage: it cannot be used as a column name, and an id key among submitted values is ignored.

History and locks — HistoryController, TableLockController

MethodPathPurpose
GET/tables/{tableId}/historyEvery recorded change of the table, newest first; ?scope=entries or ?scope=table narrows it
GET/tables/{tableId}/entries/{id}/historyChanges of one entry (kept after it is deleted)
POST/tables/{tableId}/entries/{id}/history/{changeId}/restorePut back the values from before a change
GET/tables/{tableId}/lockWhether the table is locked
PUT/tables/{tableId}/lock{"locked": true|false}

Changes of the table itself are recorded too: table_create and table_update hold the column definitions by column name in before / after, so changes lists the columns that were added, removed or altered.

Every created, updated and deleted entry is written to an append-only change log with the moment, the values before and after, and the author. The author is the account of the signed-in caller when an authenticating layer provides one (see Authentication and permissions); otherwise it is taken from the X-Author request header (percent-encoded when not ASCII), and the host application decides what it sends there.

A change is {id, entryId, operation, at, author, before, after, changes, restorable}. id identifies the change within the history of its table, changes lists the columns whose value differs ([{column, before, after}]) and restorable is true for an update of an entry that still exists. Restoring is an ordinary update: it is validated against the current table schema (422), recorded in the history, and refused with 409 for a change that holds no earlier values.

A locked table keeps its entries: they can be added and corrected, but neither an entry nor the table can be deleted (423). The lock can be lifted and set again at any time, and both are recorded in the table history. A table definition file may carry "locked": true to lock the table when it is installed.

adachsoft_dynamic_tables:
    audit:
        storage:
            type: json   # json | in_memory
            json_dir: '%kernel.project_dir%/var/dynamic-tables/audit'

Views — ViewDefinitionController, ViewDataController

MethodPathStatus codes
GET{prefix}/views200
GET{prefix}/views/{viewName}200, 400, 404
POST{prefix}/views201, 400, 409
PUT{prefix}/views/{viewName}200, 400, 404
DELETE{prefix}/views/{viewName}204, 400, 404
GET{prefix}/views/{viewName}/data200, 400, 404

Query parameters of /data: page, pageSize (pagination applies only when both are given).

Query parameters of GET /views/{viewName}/data:

  • page, pageSize – pagination (applied only when both are given),
  • filter[column][operator]=value (or filter[column]=value for equality) – all conditions must hold; operators eq, ne, gt, gte, lt, lte, contains, in (comma separated), null (true/false),
  • sort=column,-other – - sorts descending.

For join views columns are named alias.column. Numbers compare numerically and other values as text, so ISO dates compare chronologically: filter[v.visited_at][gte]=2026-11-01&filter[v.visited_at][lt]=2026-12-01.

View types: join (inner join of a primary source with further sources), union, and aggregate (group-by with count, sum, avg, min, max) for reports.

Reports — ReportController

Configurable reports of adachsoft/dynamic-tables-report, fed with the rows of dynamic tables and views. A report is a JSON definition (parameters, datasets with steps, sections); running it returns values that are ready to be shown, so a client only presents them.

MethodPathDescription
GET/reportsList of reports (name, title, description), sorted by title
GET/reports/{name}Definition of a report
PUT/reports/{name}Create or replace a report; the definition is validated completely (422 with the path of the problem)
DELETE/reports/{name}Delete a report
GET/reports/{name}/dataRun a report; other query parameters are the report's parameters (?from=2026-11-01&to=2026-11-30)
GET/reports/{name}/export/{format}The same report as a file to download: csv, xlsx or pdf; takes the same query parameters (400 for another format)
GET/report-definitions/schemaWhat a definition may contain: types, formats, functions, every step with its options, and the tables and views with their fields
POST/report-definitions/validateCheck a definition without saving it: {"valid": bool, "error": string\|null}

The last two exist for editors of report definitions. The schema is all an editor needs to offer the right inputs, so a step registered by the application appears in it without any change on the client; the form editor @adachsoft/report-editor is built on it.

Reports shipped with the application live in reports.definitions_dir (default config/dynamic_reports, one definition per file) and are installed by dynamic-tables:install. Existing reports are left alone, because they may have been edited; --update-reports replaces them with the shipped definitions.

adachsoft_dynamic_tables:
    reports:
        definitions_dir: '%kernel.project_dir%/config/dynamic_reports'
        locale: pl                 # alphabetical order of text
        time_zone: Europe/Warsaw   # what "today" is; PHP default when null
        export:                    # how values are written into exported files
            decimal_separator: ','
            true_text: tak
            false_text: nie
            csv_delimiter: ';'
        storage:
            type: json             # or in_memory
            json_dir: '%kernel.project_dir%/var/dynamic-tables/reports'

Column types — ColumnTypeController

MethodPathStatus codes
GET{prefix}/types200

Form definitions — DynamicFormDefinitionController

MethodPathStatus codes
GET{prefix}/forms200
GET{prefix}/forms/{formName}200, 404
POST{prefix}/forms201, 400, 404, 409, 422
PUT{prefix}/forms/{formName}200, 400, 404, 422
DELETE{prefix}/forms/{formName}204, 404

Form schema — FormSchemaController

MethodPathStatus codes
GET{prefix}/tables/{tableId}/form-schema200, 304, 404
GET{prefix}/views/{viewName}/form-schema200, 304, 404, 422
GET{prefix}/forms/{formName}/schema200, 304, 404

Schema endpoints support conditional requests via If-None-Match / ETag (EtagResponder).

Lookup — TableLookupController

MethodPathStatus codes
GET{prefix}/tables/{tableId}/lookup200, 404

Query parameters: q, ids[], page, pageSize, filter[column]=value (only the rows holding the value in that column; a column with several values has to contain it).

Display config — DisplayConfigController

MethodPathStatus codes
GET{prefix}/tables/{tableId}/display-config200, 404
PUT{prefix}/tables/{tableId}/display-config200, 400, 404, 422
DELETE{prefix}/tables/{tableId}/display-config204, 404

Body of PUT: {labelTemplate, title?, searchableFields?}. When searchableFields is left out, records are searched by the columns used in the label template.

Error format

Every error response is {"error": "<message>"}; validation errors add an errors list.

Authentication and permissions

The bundle neither authenticates callers nor decides what they may do, and it depends on no security library. It only declares two things an authorization layer can act on:

  1. Every route names the permission it needs in the _permission route default. A layer that understands the convention - adachsoft/auth-symfony-bundle does - checks it before the controller runs; without such a layer the default is an unused request attribute and the API is open.
  2. The author of a change is read from the _actor_id request attribute, which that layer sets to the signed-in account. A client cannot set request attributes, so the value cannot be forged; the X-Author header is consulted only when the attribute is absent.
PermissionRoutes
table.readlist and get tables, column types, display config, lock state
table.create / table.update / table.deletecreate a table / change columns and display config / delete a table
entry.readentries, listing, child entries, lookup
entry.create / entry.update / entry.deleteadd / change / delete an entry
history.read / history.restoreread the change history / restore earlier values of an entry
lock.managelock or unlock a table
view.read / view.manageread view definitions and data / create, change and delete views
report.readlist reports, read a definition, the definition schema and validation
report.run / report.managecompute a report / save and delete report definitions
form.read / form.manageform definitions and schemas / create, change and delete form definitions

The route parameters are available to grant conditions, so a role can be limited to some tables: {"permission": "entry.delete", "condition": "resource.tableId != 'visit'"}. Reading (GET) never needs more than a *.read or report.run permission.

Tables read by reports and views

A report or a view shows rows of other tables, and which ones is known only when it is calculated. So besides the permission of the route, the caller needs:

  • entry.read on every table the report or view takes rows from (resource.tableId);
  • view.read on every view it reads (resource.viewName), and entry.read on the tables of that view, however deeply views are nested.

Otherwise the answer is 403 with {"error", "code": "forbidden", "permission", "resource"} naming what was missing - a role limited to some tables cannot get around the limit with a report. Only tableId or viewName is available to grant conditions in these checks.

Names do not leak either. What the caller may not read is left out of lists and descriptions:

EndpointLeft out or refused
GET /tablestables without table.read on them (resource.tableId)
GET /viewsviews the caller may not read, including through their sources
GET /views/{name}403 for such a view
GET /reportsreports that read a table or view the caller may not read
GET /reports/{name}403 for such a report
GET /report-definitions/schematables and views that cannot be a source of the caller's report

A table whose entries are hidden (entry.read) but whose structure may be seen (table.read) stays in GET /tables; to hide a table completely limit both permissions.

A list route such as GET /tables has no tableId, so a grant condition must tolerate its absence, for example (resource.tableId ?? '') != 'medicine'. The list is then allowed and each table in it is checked on its own; a condition that reads a missing field fails to evaluate.

The check goes through Access\PermissionCheckerInterface:

ApplicationChecker
without access controlAllowAllPermissionChecker (default): nothing is restricted
with adachsoft/auth-symfony-bundleAuthBundlePermissionChecker, wired automatically
with its own access controlalias PermissionCheckerInterface to your implementation

Package structure

src/
├── AdachSoftDynamicTablesBundle.php
├── Controller/            HTTP controllers (tables, entries, views, types, forms, lookup, display config)
├── Access/                Permission checks for the tables that reports and views read
├── DependencyInjection/   Extension, Configuration, compiler passes
├── Http/
│   ├── JsonBodyReader.php
│   ├── RequestMapper/     Request → DTO mappers
│   └── Response/          EtagResponder
├── OpenApi/               RoutePrefixProcessor
└── Resources/config/      routes.yaml, services.yaml

OpenAPI

Controllers are annotated with zircote/swagger-php attributes (#[OA\…]). Paths are documented relative to routing.prefix, because the prefix belongs to the host application. When generating the application's OpenAPI document, scan the bundle controllers and add RoutePrefixProcessor, which prepends the prefix to the bundle's paths:

use AdachSoft\DynamicTablesSymfonyBundle\OpenApi\RoutePrefixProcessor;
use OpenApi\Generator;
use OpenApi\Pipeline;
use OpenApi\Processors\BuildPaths;

$openApi = (new Generator())
    ->withProcessorPipeline(
        static fn (Pipeline $pipeline): Pipeline => $pipeline->insert(new RoutePrefixProcessor('/api'), BuildPaths::class),
    )
    ->generate([
        __DIR__ . '/src/Controller',                  // your own controllers (must define #[OA\Info])
        RoutePrefixProcessor::controllerDirectory(),  // this bundle
    ]);

The prefix is available as the container parameter adachsoft_dynamic_tables.routing.prefix.

Design rules

  1. Thin HTTP layer — controllers map HTTP ↔ facades; logic stays in dynamic-tables-core and form-core.
  2. Contract-first exceptions — controllers catch *ExceptionInterface from form-contract / table-contract.
  3. Single configuration root — adachsoft_dynamic_tables is the only config key.
  4. Compile-time safety — required host services are validated by a compiler pass.

Development

Run the package tests from this repository's root:

./vendor/bin/phpunit --configuration phpunit.xml

Run static analysis and code style checks from this repository's root:

./vendor/bin/phpstan analyse src tests
./vendor/bin/rector process src tests
./vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php src tests

License

MIT

Author

Arkadiusz Adach