adachsoft / dynamic-tables-form-core
Framework-agnostic domain logic for dynamic table forms and form schemas.
Package info
gitlab.com/a.adach/dynamic-tables-form-core
pkg:composer/adachsoft/dynamic-tables-form-core
Requires
- php: >=8.3
- adachsoft/dynamic-table-contract: ^1
- adachsoft/dynamic-tables-form-contract: ^0.1.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
- adachsoft/dynamic-table-view: Enables form-schema generation for table views.
Provides
None
Conflicts
None
Replaces
None
README
Framework-agnostic domain implementation for the dynamic-tables form-schema system.
This package implements the contracts from adachsoft/dynamic-tables-form-contract: facades, domain services, and InMemory repositories (for tests and non-persistent environments).
Namespace: AdachSoft\DynamicTablesFormCore
Requirements
- PHP
>= 8.3 adachsoft/dynamic-table-contract^1adachsoft/dynamic-tables-form-contract^0.1.1
Optional (for view-based schema generation):
adachsoft/dynamic-table-view— required only when wiringViewDefinitionRepositoryInterfaceintoFormSchemaGenerator
Installation
When used from the monorepo root (recommended during development):
composer install
The root composer.json maps:
AdachSoft\DynamicTablesFormCore\ → packages/dynamic-tables-form-core/src/
AdachSoft\DynamicTablesFormCore\Tests\ → packages/dynamic-tables-form-core/tests/
As a standalone library:
composer require adachsoft/dynamic-tables-form-core
Integration
Register the package implementations in your dependency-injection container using the interfaces from adachsoft/dynamic-tables-form-contract. Inject the configured DynamicFormFacadeInterface into the application layer that serves form schemas. A complete usage example is available in docs/examples/generate-form-schema.md.
The included InMemory repositories are suitable for tests and temporary environments. Use persistent adapters implementing the repository contracts for production storage. View-based schema generation additionally requires the optional adachsoft/dynamic-table-view package and a configured ViewDefinitionRepositoryInterface.
Package structure
src/
├── Exception/ Concrete exceptions implementing form-contract interfaces
├── Facade/ DynamicFormFacade, LookupFacade, DisplayConfigFacade
├── Repository/ InMemory form definition and display config repositories
├── Service/ Schema generation, widgets, lookup, labels, ETag
└── Vo/ Relation column configuration value object
Usage
After registering the package services and contracts in your dependency-injection container, retrieve a schema through the facade:
$schema = $dynamicFormFacade->getSchemaForTable('customers');
The returned FormSchemaResponseDto contains the schema fields and its ETag. See the schema generation example for a complete integration snippet.
Facades
| Class | Contract | Responsibility |
|---|---|---|
Facade\DynamicFormFacade | DynamicFormFacadeInterface | Form definition CRUD and schema entry points |
Facade\LookupFacade | LookupFacadeInterface | Relation field lookup |
Facade\DisplayConfigFacade | DisplayConfigFacadeInterface | Per-table label template and searchable fields |
DynamicFormFacade
getAllDefinitions()/getDefinition(string $formName)createDefinition(CreateFormDefinitionDto)/updateDefinition(...)/deleteDefinition(...)getSchemaForTable(string $tableId)getSchemaForView(string $viewName)getSchemaForForm(string $formName)
Validates field overrides and section field names against the target table columns before create/update.
LookupFacade
lookup(string $tableId, LookupQueryDto $query): LookupResponseDto
Thin delegate to TableLookupService.
DisplayConfigFacade
find/get/save/delete
Validates label template placeholders and searchable fields against table columns on save.
Services
| Class | Responsibility |
|---|---|
FormSchemaGenerator | Builds FormSchemaResponseDto for a table or view (with optional form overrides) |
FormSchemaEtagCalculator | Deterministic weak ETag (W/"<sha256>") over schema payload |
WidgetResolver | Maps column type/config to WidgetEnum + widget params (relation threshold aware) |
ColumnTypeMetadataReader | Maps column type/config to validation rule arrays |
TableLookupService | Filtered/paginated lookup items with label rendering |
TableLabelRenderer | Renders {placeholder} label templates (fallback to row id) |
FormSchemaGenerator notes
- Skips the
idcolumn when building fields. - Applies form definition overrides (label, widget, order, hidden, readOnly) when
FormNameVois provided. generateForView:- requires optional
ViewDefinitionRepositoryInterface(from dynamic-table-view); otherwise throws\LogicException - rejects
unionviews withFormSchemaUnavailableForUnionViewException - for join views delegates to
generateForTableusing the primary source table id
- requires optional
WidgetResolver (relation)
Uses RowRepositoryInterface::getAll(targetTableId) and selectThreshold (default 50):
| multiple | count vs threshold | Widget |
|---|---|---|
| false | ≤ threshold | SELECT |
| false | > threshold | AUTOCOMPLETE |
| true | ≤ threshold | CHECKBOX_GROUP |
| true | > threshold | AUTOCOMPLETE |
Missing targetTableId → TableNotConfiguredForLookupException.
InMemory repositories
| Class | Contract |
|---|---|
InMemoryFormDefinitionRepository | FormDefinitionRepositoryInterface |
InMemoryDisplayConfigRepository | DisplayConfigRepositoryInterface |
Suitable for unit tests and environments without file/DB persistence. Production adapters (e.g. JSON) live in separate packages.
Exceptions
Concrete classes under Exception\ implement the corresponding interfaces from form-contract, for example:
FormDefinitionNotFoundExceptionDuplicateFormDefinitionExceptionInvalidFormDefinitionExceptionFormSchemaUnavailableForUnionViewExceptionTableNotConfiguredForLookupExceptionInvalidLabelTemplateExceptionDisplayConfigNotFoundExceptionInvalidDisplayConfigException
Design rules
- Implements contracts only — public surface is defined by form-contract; this package supplies behavior.
- Framework-agnostic — no Symfony/Laravel/Doctrine types in the public API.
- Single enforcement point — validation of form/display config against table metadata lives in facades; repositories enforce existence/duplicate rules.
- Optional view support — view schema generation is wired only when
ViewDefinitionRepositoryInterfaceis provided.
Development
Run package tests from the monorepo root:
./vendor/bin/phpunit packages/dynamic-tables-form-core/tests
Static analysis / style (from monorepo root, paths limited to this package):
./vendor/bin/phpstan analyse packages/dynamic-tables-form-core/src packages/dynamic-tables-form-core/tests
./vendor/bin/rector process packages/dynamic-tables-form-core/src packages/dynamic-tables-form-core/tests
./vendor/bin/php-cs-fixer fix packages/dynamic-tables-form-core/src packages/dynamic-tables-form-core/tests
License
MIT
Author
Arkadiusz Adach