alexandrebulete/ddd-symfony-bundle
Composer 安装命令:
composer require alexandrebulete/ddd-symfony-bundle
包简介
Symfony Bundle for DDD Foundation - Messenger Command/Query Bus integration
README 文档
README
Symfony Bundle for DDD Foundation. Provides Messenger integration for Command/Query buses and a base Kernel for DDD projects.
Installation
composer require alexandrebulete/ddd-symfony-bundle
Configuration
Add the bundle to your config/bundles.php:
return [ // ... AlexandreBulete\DddSymfonyBundle\DddSymfonyBundle::class => ['all' => true], ];
Features
DddKernel - Auto-import Bounded Contexts
The bundle provides a DddKernel that automatically imports services, packages, and routes from your Bounded Contexts.
Setup
Extend DddKernel in your application's src/Kernel.php:
<?php declare(strict_types=1); namespace App; use AlexandreBulete\DddSymfonyBundle\DddKernel; class Kernel extends DddKernel { // You can override configureContainer/configureRoutes if needed }
What it does
The DddKernel automatically imports:
- Services:
src/*/Infrastructure/Symfony/config/services.{php,yaml} - Packages:
src/*/Infrastructure/Symfony/config/packages/*.{php,yaml} - Routes:
src/*/Infrastructure/Symfony/routes/*.{php,yaml}
This means each Bounded Context can define its own configuration without modifying the main config/ folder.
Expected BC Structure
src/
├── Post/ # Bounded Context
│ └── Infrastructure/
│ └── Symfony/
│ ├── config/
│ │ ├── services.php # Auto-imported
│ │ └── packages/
│ │ └── doctrine.yaml # Auto-imported
│ └── routes/
│ └── api.yaml # Auto-imported
└── User/ # Another Bounded Context
└── Infrastructure/
└── Symfony/
└── config/
└── services.php # Auto-imported
Command/Query Bus
The bundle automatically configures two Symfony Messenger buses:
command.bus- For write operations (Commands)query.bus- For read operations (Queries)
Automatic Handler Registration
Handlers decorated with #[AsCommandHandler] or #[AsQueryHandler] are automatically registered to their respective buses.
use AlexandreBulete\DddFoundation\Application\Command\AsCommandHandler; use AlexandreBulete\DddFoundation\Application\Command\CommandInterface; readonly class CreatePostCommand implements CommandInterface { public function __construct( public string $title, public string $content, ) {} } #[AsCommandHandler] readonly class CreatePostHandler { public function __invoke(CreatePostCommand $command): void { // Handle the command } }
Using the Buses
use AlexandreBulete\DddFoundation\Application\Command\CommandBusInterface; use AlexandreBulete\DddFoundation\Application\Query\QueryBusInterface; class PostController { public function __construct( private CommandBusInterface $commandBus, private QueryBusInterface $queryBus, ) {} public function create(): Response { $this->commandBus->dispatch(new CreatePostCommand( title: 'My Post', content: 'Content...', )); // ... } public function list(): Response { $posts = $this->queryBus->ask(new GetPostsQuery( page: 1, itemsPerPage: 10, )); // ... } }
Autocomplete Form Field
The bundle provides an Autocomplete Symfony Form field powered by Stimulus + Tom Select (no jQuery).
It is designed for admin back-offices and DDD projects, and works with ID-based values (Value Objects friendly).
Assets setup (Importmap)
If your application uses Importmap / AssetMapper:
php bin/console importmap:require tom-select php bin/console importmap:require tom-select/dist/css/tom-select.default.css
Enable the Stimulus controller in assets/controllers.json:
{
"controllers": {
"@alexandrebulete/ddd-symfony-bundle": {
"autocomplete": {
"enabled": true,
"fetch": "eager",
"path": "@alexandrebulete/ddd-symfony-bundle/autocomplete_controller",
"autoimport": {
"tom-select/dist/css/tom-select.default.css": true
}
}
}
}
}
Usage
use AlexandreBulete\DddSymfonyBundle\Form\Type\AutocompleteType; $builder->add('authorId', AutocompleteType::class, [ 'label' => 'Author', 'remote_url' => $this->urlGenerator->generate('admin_user_autocomplete'), 'placeholder' => 'Search by email…', 'min_length' => 2, ]);
The autocomplete endpoint must return:
{
"results": [
{ "id": "uuid-1", "text": "user@example.com" }
]
}
Options
| Option | Description |
|---|---|
| remote_url | AJAX endpoint URL |
| placeholder | Input placeholder |
| min_length | Minimum characters before search |
| limit | Maximum results returned |
| initial_text | Preselected label (edit forms) |
Customization
Override Messenger Configuration
You can override the messenger configuration by creating your own config/packages/messenger.yaml:
framework: messenger: buses: command.bus: middleware: - doctrine_transaction query.bus: ~
Extend DddKernel
If you need custom container or routes configuration, override the methods:
<?php declare(strict_types=1); namespace App; use AlexandreBulete\DddSymfonyBundle\DddKernel; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; class Kernel extends DddKernel { protected function configureContainer(ContainerConfigurator $container): void { parent::configureContainer($container); // Add your custom imports here $container->import($this->getProjectDir().'/config/custom/*.yaml'); } }
alexandrebulete/ddd-symfony-bundle 适用场景与选型建议
alexandrebulete/ddd-symfony-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 13, 最近一次更新时间为 2026 年 02 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 alexandrebulete/ddd-symfony-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 alexandrebulete/ddd-symfony-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 27
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-05