adachsoft / dynamic-tables-symfony-bundle
Symfony bundle exposing the Dynamic Tables ecosystem through HTTP APIs.
Package info
gitlab.com/a.adach/dynamic-tables-symfony-bundle
Type:symfony-bundle
pkg:composer/adachsoft/dynamic-tables-symfony-bundle
Requires
- php: >=8.3
- adachsoft/dynamic-table-contract: ^1
- adachsoft/dynamic-tables-core: ^0.1.0
- adachsoft/dynamic-tables-form-core: ^0.1.0
- adachsoft/dynamic-tables-form-json: ^0.1.0
- adachsoft/dynamic-tables-report: ^0.1.0
- adachsoft/rule-evaluator-expression-language: ^0.2
- symfony/config: ^7.0 || ^8.0
- symfony/console: ^7.0 || ^8.0
- symfony/dependency-injection: ^7.0 || ^8.0
- symfony/http-foundation: ^7.0 || ^8.0
- symfony/http-kernel: ^7.0 || ^8.0
- symfony/routing: ^7.0 || ^8.0
- zircote/swagger-php: ^5
Requires (Dev)
- adachsoft/auth-symfony-bundle: ^0.5
- adachsoft/dynamic-table-json: ^0.4
- 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
- symfony/framework-bundle: ^7.0 || ^8.0
- symplify/phpstan-rules: ^14.19
Suggests
- adachsoft/auth-symfony-bundle: Enforces the permissions the routes declare and the access of reports and views to their source tables.
Provides
None
Conflicts
None
Replaces
None
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
- PHP
>= 8.3 - Symfony
^7(framework-bundle,http-foundation,http-kernel,routing,dependency-injection,config) adachsoft/dynamic-tables-core^0.1adachsoft/dynamic-tables-report^0.1adachsoft/dynamic-tables-form-core^0.1adachsoft/dynamic-tables-form-json^0.1adachsoft/dynamic-table-contract^1zircote/swagger-php^5
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:
| Service | Required |
|---|---|
AdachSoft\DynamicTableContract\Repository\TableRepositoryInterface | yes |
AdachSoft\DynamicTableContract\Repository\RowRepositoryInterface | yes |
AdachSoft\DynamicTableView\Repository\ViewDefinitionRepositoryInterface | yes |
AdachSoft\DynamicTableView\Repository\ViewRepositoryInterface | yes |
AdachSoft\DynamicTableViewJson\Serializer\ViewDefinitionSerializerInterface | yes |
AdachSoft\DynamicTableContract\Query\Repository\QueryableRowRepositoryInterface | optional (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 fromdynamic-tables-form-jsonin_memory— in-memory repositories fromdynamic-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–selectorautocomplete; 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 whosetargetColumnholds the value offieldof the same form (pick the customer first, then one of that customer's orders). The form schema passes it on aswidgetParams.filterBy; the lookup takes it asfilter[targetColumn]=value. The API enforces it as well: saving an entry whose relation points at a record of another parent is refused with422and the coderelation_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
| Method | Path | Status codes |
|---|---|---|
GET | {prefix}/tables | 200 |
GET | {prefix}/tables/{tableId} | 200, 400, 404 |
POST | {prefix}/tables | 201, 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
| Method | Path | Status codes |
|---|---|---|
GET | {prefix}/tables/{tableId}/entries | 200, 400, 404 |
GET | {prefix}/tables/{tableId}/listing | 200, 400, 404 |
GET | {prefix}/tables/{tableId}/entries/{id} | 200, 400, 404 |
GET | {prefix}/tables/{tableId}/entries/{id}/children | 200, 400, 404 |
POST | {prefix}/tables/{tableId}/entries | 201, 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]=valueandsort=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) andpageSize(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), idis the row identifier assigned by the storage: it cannot be used as a column name, and anidkey among submitted values is ignored.
History and locks — HistoryController, TableLockController
| Method | Path | Purpose |
|---|---|---|
GET | /tables/{tableId}/history | Every recorded change of the table, newest first; ?scope=entries or ?scope=table narrows it |
GET | /tables/{tableId}/entries/{id}/history | Changes of one entry (kept after it is deleted) |
POST | /tables/{tableId}/entries/{id}/history/{changeId}/restore | Put back the values from before a change |
GET | /tables/{tableId}/lock | Whether 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
| Method | Path | Status codes |
|---|---|---|
GET | {prefix}/views | 200 |
GET | {prefix}/views/{viewName} | 200, 400, 404 |
POST | {prefix}/views | 201, 400, 409 |
PUT | {prefix}/views/{viewName} | 200, 400, 404 |
DELETE | {prefix}/views/{viewName} | 204, 400, 404 |
GET | {prefix}/views/{viewName}/data | 200, 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(orfilter[column]=valuefor equality) – all conditions must hold; operatorseq,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.
| Method | Path | Description |
|---|---|---|
GET | /reports | List 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}/data | Run 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/schema | What a definition may contain: types, formats, functions, every step with its options, and the tables and views with their fields |
POST | /report-definitions/validate | Check 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
| Method | Path | Status codes |
|---|---|---|
GET | {prefix}/types | 200 |
Form definitions — DynamicFormDefinitionController
| Method | Path | Status codes |
|---|---|---|
GET | {prefix}/forms | 200 |
GET | {prefix}/forms/{formName} | 200, 404 |
POST | {prefix}/forms | 201, 400, 404, 409, 422 |
PUT | {prefix}/forms/{formName} | 200, 400, 404, 422 |
DELETE | {prefix}/forms/{formName} | 204, 404 |
Form schema — FormSchemaController
| Method | Path | Status codes |
|---|---|---|
GET | {prefix}/tables/{tableId}/form-schema | 200, 304, 404 |
GET | {prefix}/views/{viewName}/form-schema | 200, 304, 404, 422 |
GET | {prefix}/forms/{formName}/schema | 200, 304, 404 |
Schema endpoints support conditional requests via If-None-Match / ETag (EtagResponder).
Lookup — TableLookupController
| Method | Path | Status codes |
|---|---|---|
GET | {prefix}/tables/{tableId}/lookup | 200, 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
| Method | Path | Status codes |
|---|---|---|
GET | {prefix}/tables/{tableId}/display-config | 200, 404 |
PUT | {prefix}/tables/{tableId}/display-config | 200, 400, 404, 422 |
DELETE | {prefix}/tables/{tableId}/display-config | 204, 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:
- Every route names the permission it needs in the
_permissionroute default. A layer that understands the convention -adachsoft/auth-symfony-bundledoes - checks it before the controller runs; without such a layer the default is an unused request attribute and the API is open. - The author of a change is read from the
_actor_idrequest attribute, which that layer sets to the signed-in account. A client cannot set request attributes, so the value cannot be forged; theX-Authorheader is consulted only when the attribute is absent.
| Permission | Routes |
|---|---|
table.read | list and get tables, column types, display config, lock state |
table.create / table.update / table.delete | create a table / change columns and display config / delete a table |
entry.read | entries, listing, child entries, lookup |
entry.create / entry.update / entry.delete | add / change / delete an entry |
history.read / history.restore | read the change history / restore earlier values of an entry |
lock.manage | lock or unlock a table |
view.read / view.manage | read view definitions and data / create, change and delete views |
report.read | list reports, read a definition, the definition schema and validation |
report.run / report.manage | compute a report / save and delete report definitions |
form.read / form.manage | form 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.readon every table the report or view takes rows from (resource.tableId);view.readon every view it reads (resource.viewName), andentry.readon 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:
| Endpoint | Left out or refused |
|---|---|
GET /tables | tables without table.read on them (resource.tableId) |
GET /views | views the caller may not read, including through their sources |
GET /views/{name} | 403 for such a view |
GET /reports | reports that read a table or view the caller may not read |
GET /reports/{name} | 403 for such a report |
GET /report-definitions/schema | tables 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:
| Application | Checker |
|---|---|
| without access control | AllowAllPermissionChecker (default): nothing is restricted |
with adachsoft/auth-symfony-bundle | AuthBundlePermissionChecker, wired automatically |
| with its own access control | alias 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
- Thin HTTP layer — controllers map HTTP ↔ facades; logic stays in
dynamic-tables-coreandform-core. - Contract-first exceptions — controllers catch
*ExceptionInterfacefrom form-contract / table-contract. - Single configuration root —
adachsoft_dynamic_tablesis the only config key. - 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