Search by

adachsoft / dynamic-tables-form-core

Arkadiusz Adach

Framework-agnostic domain logic for dynamic table forms and form schemas.

Package info

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

Issues

pkg:composer/adachsoft/dynamic-tables-form-core

Statistics

Installs: 12

Dependents: 1

Suggesters: 0

Stars: 0

v0.1.0 2026-11-26 19:19 UTC

This package is auto-updated.

Last update: 2026-11-26 18:19:47 UTC


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

Optional (for view-based schema generation):

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

ClassContractResponsibility
Facade\DynamicFormFacadeDynamicFormFacadeInterfaceForm definition CRUD and schema entry points
Facade\LookupFacadeLookupFacadeInterfaceRelation field lookup
Facade\DisplayConfigFacadeDisplayConfigFacadeInterfacePer-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

ClassResponsibility
FormSchemaGeneratorBuilds FormSchemaResponseDto for a table or view (with optional form overrides)
FormSchemaEtagCalculatorDeterministic weak ETag (W/"<sha256>") over schema payload
WidgetResolverMaps column type/config to WidgetEnum + widget params (relation threshold aware)
ColumnTypeMetadataReaderMaps column type/config to validation rule arrays
TableLookupServiceFiltered/paginated lookup items with label rendering
TableLabelRendererRenders {placeholder} label templates (fallback to row id)

FormSchemaGenerator notes

  • Skips the id column when building fields.
  • Applies form definition overrides (label, widget, order, hidden, readOnly) when FormNameVo is provided.
  • generateForView:
    • requires optional ViewDefinitionRepositoryInterface (from dynamic-table-view); otherwise throws \LogicException
    • rejects union views with FormSchemaUnavailableForUnionViewException
    • for join views delegates to generateForTable using the primary source table id

WidgetResolver (relation)

Uses RowRepositoryInterface::getAll(targetTableId) and selectThreshold (default 50):

multiplecount vs thresholdWidget
false≤ thresholdSELECT
false> thresholdAUTOCOMPLETE
true≤ thresholdCHECKBOX_GROUP
true> thresholdAUTOCOMPLETE

Missing targetTableId → TableNotConfiguredForLookupException.

InMemory repositories

ClassContract
InMemoryFormDefinitionRepositoryFormDefinitionRepositoryInterface
InMemoryDisplayConfigRepositoryDisplayConfigRepositoryInterface

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:

  • FormDefinitionNotFoundException
  • DuplicateFormDefinitionException
  • InvalidFormDefinitionException
  • FormSchemaUnavailableForUnionViewException
  • TableNotConfiguredForLookupException
  • InvalidLabelTemplateException
  • DisplayConfigNotFoundException
  • InvalidDisplayConfigException

Design rules

  1. Implements contracts only — public surface is defined by form-contract; this package supplies behavior.
  2. Framework-agnostic — no Symfony/Laravel/Doctrine types in the public API.
  3. Single enforcement point — validation of form/display config against table metadata lives in facades; repositories enforce existence/duplicate rules.
  4. Optional view support — view schema generation is wired only when ViewDefinitionRepositoryInterface is 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