Search by

adachsoft / dynamic-tables-form-json

Arkadiusz Adach

File-based JSON persistence for dynamic table form definitions and display configurations

Package info

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

Issues

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

Statistics

Installs: 9

Dependents: 1

Suggesters: 0

Stars: 0

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

This package is auto-updated.

Last update: 2026-11-26 18:58:08 UTC


README

File-based JSON persistence for the dynamic-tables form-schema system.

This package provides concrete repository implementations of FormDefinitionRepositoryInterface and DisplayConfigRepositoryInterface from adachsoft/dynamic-tables-form-contract, backed by local JSON files.

It is framework-agnostic — no Symfony or other framework dependencies. Responsibility is limited to DTO ↔ JSON serialization and filesystem I/O. Domain exceptions (FormDefinitionNotFoundException, DuplicateFormDefinitionException, DisplayConfigNotFoundException) come from adachsoft/dynamic-tables-form-core. I/O and JSON parse errors are wrapped in the local FormJsonStorageException.

Namespace: AdachSoft\DynamicTablesFormJson

Requirements

Installation

Install the package and its dependencies with Composer:

composer require adachsoft/dynamic-tables-form-json

Composer's PSR-4 autoloader maps the library namespace to src/.

Package structure

src/
├── Exception/     Storage-specific exceptions
├── Repository/    File-based repository implementations
└── Serializer/    DTO ↔ JSON serializers

Components

ClassResponsibility
Repository\FileFormDefinitionRepositoryCRUD for form definitions as {storageDir}/{name}.json
Repository\FileDisplayConfigRepositoryUpsert/read/delete display config as {storageDir}/{tableId}.json
Serializer\FormDefinitionSerializerSerialize/deserialize FormDefinitionResponseDto
Serializer\DisplayConfigSerializerSerialize/deserialize DisplayConfigResponseDto
Exception\FormJsonStorageExceptionWrapper for I/O and JSON errors

Usage

Form definitions

use AdachSoft\DynamicTablesFormJson\Repository\FileFormDefinitionRepository;
use AdachSoft\DynamicTablesFormJson\Serializer\FormDefinitionSerializer;
use AdachSoft\DynamicTablesFormContract\Vo\FormNameVo;

$repository = new FileFormDefinitionRepository(
    storageDir: '/var/data/form-definitions',
    formDefinitionSerializer: new FormDefinitionSerializer(),
);

// Create
$repository->create($formDefinitionResponseDto);

// Read
$dto = $repository->get(new FormNameVo('animal_form'));
$all = $repository->getAll();
$byTable = $repository->findForTable('animals'); // ?FormDefinitionResponseDto

// Update / delete
$repository->update($formDefinitionResponseDto);
$repository->delete(new FormNameVo('animal_form'));

Display config

use AdachSoft\DynamicTablesFormJson\Repository\FileDisplayConfigRepository;
use AdachSoft\DynamicTablesFormJson\Serializer\DisplayConfigSerializer;

$repository = new FileDisplayConfigRepository(
    storageDir: '/var/data/display-configs',
    displayConfigSerializer: new DisplayConfigSerializer(),
);

// Upsert (create or overwrite)
$repository->save($displayConfigResponseDto);

// Read
$dto = $repository->get('animals');
$maybe = $repository->find('animals'); // null when missing

// Delete
$repository->delete('animals');

JSON schema

Both serializers write _schemaVersion: 1 for future migrations.

Form definition file ({name}.json)

{
  "name": "animal_form",
  "tableId": "animals",
  "theme": "default",
  "fieldOverrides": [
    {
      "fieldName": "name",
      "label": "Name",
      "widget": "text",
      "widgetParams": null,
      "hidden": false,
      "order": 1,
      "readOnly": false
    }
  ],
  "sections": [
    {
      "name": "main",
      "label": "Main",
      "fieldNames": ["name"]
    }
  ],
  "_schemaVersion": 1
}

Display config file ({tableId}.json)

{
  "tableId": "animals",
  "labelTemplate": "{name}",
  "searchableFields": ["name", "code"],
  "_schemaVersion": 1
}

Exceptions

ExceptionSourceWhen
FormJsonStorageExceptionthis packageI/O failure, invalid JSON, missing required keys
FormDefinitionNotFoundExceptionform-coreget / update / delete on missing form
DuplicateFormDefinitionExceptionform-corecreate when file already exists
DisplayConfigNotFoundExceptionform-coreget / delete on missing display config

Design rules

  1. Infrastructure only — no domain rules beyond repository contracts.
  2. Single storage exception — all I/O and parse failures go through FormJsonStorageException.
  3. Domain exceptions from core — not-found / duplicate semantics stay in dynamic-tables-form-core.
  4. Framework-agnostic — plain PHP filesystem APIs; no framework types.
  5. Auto-create storage directory — create / save create $storageDir when missing.

Development

Run the test suite and quality tools from the package root:

vendor/bin/phpunit --configuration phpunit.xml
vendor/bin/phpstan analyse src tests
vendor/bin/rector process src tests
vendor/bin/php-cs-fixer fix src tests

License

MIT

Author

Arkadiusz Adach