jbsnewmedia/ddm-bundle

Data Definition Model Bundle for VIS

Installs: 9

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 0

Forks: 0

Open Issues: 0

Type:symfony-bundle

pkg:composer/jbsnewmedia/ddm-bundle

1.1.0 2026-02-20 17:32 UTC

This package is auto-updated.

Last update: 2026-02-23 20:48:51 UTC


README

Packagist Version Packagist Downloads PHP Version Require Symfony Version License Tests PHP CS Fixer PHPStan Rector codecov

DDMBundle (Data Definition Model) is a Symfony bundle for the VIS ecosystem that simplifies the definition and handling of data models for datatables and forms. It provides a structured way to centrally define fields, validations, and rendering logic.

πŸš€ Features

  • Centralized Data Definition via DDM and DDMField
  • Automated Datatable Engine for server-side processing (sorting, searching, pagination)
  • Advanced Search Functionality via DDMDatatableSearchHandler
  • Flexible Form Handler for AJAX-based form processing and validation
  • Attribute-based Field Configuration for easy integration into entities
  • Extensive Validation (Required, String, Unique, Email, etc.)
  • Twig Integration for easy rendering of forms and tables
  • Seamless Integration into the VIS ecosystem

βš™οΈ Requirements

  • PHP 8.2 or higher
  • Symfony Framework 7.4 or higher
  • Doctrine ORM

πŸ“¦ Installation

Use Composer to install the bundle:

composer require jbsnewmedia/ddm-bundle

πŸ›  Setup & Configuration

1. Define Fields

Fields are defined as services and can be configured with the #[DDMFieldAttribute] attribute to associate them with specific entities or contexts. In the __construct method or via initialization, field properties such as identifier, name, and behavior can be set.

use JBSNewMedia\DDMBundle\Attribute\DDMFieldAttribute;
use JBSNewMedia\DDMBundle\Service\DDMField;

#[DDMFieldAttribute(entity: 'User', order: 10)]
class UserNameField extends DDMField
{
    public function __construct()
    {
        $this->setIdentifier('username');
        $this->setName('Username');
        $this->setSortable(true);
        $this->setLivesearch(true);
    }
}

2. Create DDM Instance

Use the DDMFactory to create a DDM instance for an entity and a context:

use JBSNewMedia\DDMBundle\Service\DDMFactory;

public function index(DDMFactory $ddmFactory)
{
    $ddm = $ddmFactory->create(User::class, 'admin_list');
    // ...
}

πŸ“‹ Usage Examples

Using Datatable in a Controller

The DDMDatatableEngine handles all the logic for providing the data:

use JBSNewMedia\DDMBundle\Service\DDMDatatableEngine;
use JBSNewMedia\DDMBundle\Service\DDMFactory;
use Symfony\Component\HttpFoundation\Request;

public function list(Request $request, DDMFactory $ddmFactory, DDMDatatableEngine $engine)
{
    $ddm = $ddmFactory->create(User::class, 'list');
    
    if ($request->isXmlHttpRequest()) {
        return $engine->handleRequest($request, $ddm);
    }
    
    return $this->render('user/list.html.twig', [
        'ddm' => $ddm
    ]);
}

Processing a Form

The DDMDatatableFormHandler automates loading, validating, and saving entities. It returns either a rendered form or a JSON response.

use JBSNewMedia\DDMBundle\Service\DDMDatatableFormHandler;
use Symfony\Component\HttpFoundation\Response;

public function edit(Request $request, User $user, DDMDatatableFormHandler $formHandler)
{
    $ddm = $this->ddmFactory->create(User::class, 'edit');
    
    $response = $formHandler->handle($request, $ddm, $user);
    
    return $response;
}

🎨 Template Integration

Datatable Rendering

<div id="user-datatable" 
     data-avalynx-datatable-url="{{ path('user_list_ajax') }}"
     data-avalynx-datatable-config="{{ ddm.datatableConfig|json_encode }}">
    <!-- The engine provides data suitable for AvalynX Datatable -->
</div>

πŸ“ Architecture Overview

Core Components

src/
β”œβ”€β”€ Attribute/           # PHP Attributes for field configuration
β”œβ”€β”€ Contract/            # Interfaces for fields, validators and values
β”œβ”€β”€ DependencyInjection/ # Bundle configuration & extension
β”œβ”€β”€ Doctrine/            # Doctrine-specific extensions (e.g. CAST function)
β”œβ”€β”€ Service/
β”‚   β”œβ”€β”€ DDM.php              # Central model of a data definition
β”‚   β”œβ”€β”€ DDMFactory.php       # Factory for creating DDM instances
β”‚   β”œβ”€β”€ DDMField.php         # Base class for all fields
β”‚   β”œβ”€β”€ DDMDatatableEngine.php # Engine for datatable requests
β”‚   β”œβ”€β”€ DDMDatatableFormHandler.php # Handler for form logic
β”‚   └── DDMDatatableSearchHandler.php # Handler for datatable search
β”œβ”€β”€ Trait/               # Shared functionalities (e.g. entity access)
β”œβ”€β”€ Validator/           # Validators (Required, String, Unique, Email, etc.)
β”œβ”€β”€ Value/               # Value objects (String, Array, etc.)
└── DDMBundle.php        # Bundle class

πŸ§ͺ Developer Tools

The following commands are available for development:

# Tool installation
composer bin-ecs-install
composer bin-phpstan-install
composer bin-phpunit-install
composer bin-rector-install

# Code quality checks
composer bin-ecs           # PHP-CS-Fixer check
composer bin-phpstan       # Static analysis
composer bin-rector        # Code transformation (dry-run)
composer test              # PHPUnit tests

# Automatic fixes
composer bin-ecs-fix       # Fix coding standards
composer bin-rector-process # Apply code transformation

# CI Pipelines
composer ci                # Execute all checks

πŸ“œ License

This bundle is licensed under the MIT License. See the LICENSE file for more details.

Developed by JΓΌrgen Schwind and other contributors.

🀝 Contributing

Contributions are welcome! If you would like to contribute, please create a pull request or open an issue.

πŸ“« Contact

If you have questions or problems, please open an issue in our GitHub repository.

Data Definition Model. Modular. Efficient. VIS-Ready.