awd-studio/es-lib-maker-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

awd-studio/es-lib-maker-bundle

Composer 安装命令:

composer require awd-studio/es-lib-maker-bundle

包简介

A Symfony bundle providing maker commands for seamless integration with Event Sourcing patterns. Features code generation tools for event-sourced aggregates, value objects, and domain events following DDD principles.

README 文档

README

A Symfony bundle providing maker commands for seamless integration with Event Sourcing patterns. Features code generation tools for event-sourced aggregates, value objects, and domain events following Domain-Driven Design principles.

MIT License PHP Version Symfony Version

Overview

ES Lib Maker Bundle is part of the ES Lib ecosystem, designed to simplify the implementation of Event Sourcing in Symfony applications. This bundle provides maker commands that generate boilerplate code for event-sourced entities, following best practices and patterns.

Installation

Prerequisites

  • PHP 8.3 or higher
  • Symfony 7.0 or higher
  • Composer

Steps

  1. Require the bundle via Composer as a dev dependency:
composer require --dev awd-studio/es-lib-maker-bundle

The bundle will be automatically registered in your config/bundles.php for the dev environment.

If the bundle is not registered automatically, you can register it manually by adding the following line to your config/bundles.php file:

return [
    // ...
    AwdEs\EsLibMakerBundle\EsLibMakerBundle::class => ['dev' => true],
];

Usage

Creating an Event-Sourced Entity

The bundle provides a maker command to generate event-sourced entities:

# Create an aggregate root
php bin/console make:es:entity "YourNamespace\YourAggregate" -

# Create a child entity
php bin/console make:es:entity "YourNamespace\YourAggregate\ChildEntity" "App\YourNamespace\Domain\YourAggregate"

Command Options

  • entity-name: The fully qualified class name for the entity (e.g., Foo\FooAggregate)
  • aggregate-root: The root for the aggregate (use - to configure the aggregate root itself)
  • --machine-name: A unique name for the entity (e.g., FOO_AGGREGATE)
  • --main-value-type: The type for the main value (default: string)
  • --main-value-name: The name for the main value (default: value)

Generated Code Structure

For each entity, the bundle generates:

  1. Entity Class: The main entity class with event handlers
  2. Events:
    • WasCreated: Event for entity creation
    • WasChanged: Event for entity changes
    • WasActivated/WasDeactivated: Events for entity activation/deactivation (for simple entities)
  3. Repository:
    • Interface
    • Implementation
  4. Factory:
    • Interface
    • Implementation
  5. Exceptions:
    • NotFound: Exception for when an entity is not found
    • PersistenceError: Exception for persistence errors

Examples

Creating an Aggregate Root

Basic String-Based Aggregate

php bin/console make:es:entity "Product\ProductAggregate" - --main-value-type="string" --main-value-name="name"

This will generate:

  • App\Product\Domain\ProductAggregate - The aggregate root class
  • Events, repository, factory, and exceptions for the aggregate

Integer-Based Aggregate with Custom Machine Name

php bin/console make:es:entity "Order\OrderAggregate" - --main-value-type="int" --main-value-name="orderNumber" --machine-name="CUSTOMER_ORDER"

This will generate:

  • App\Order\Domain\OrderAggregate - The aggregate root class with an integer main value
  • Events, repository, factory, and exceptions for the aggregate
  • The machine name "CUSTOMER_ORDER_ROOT" will be used in the entity attributes

DateTime-Based Aggregate

php bin/console make:es:entity "Appointment\AppointmentAggregate" - --main-value-type="IDateTime" --main-value-name="scheduledAt"

This will generate:

  • App\Appointment\Domain\AppointmentAggregate - The aggregate root class with a DateTime main value
  • Special comparison logic for DateTime objects in the change method

Creating Child Entities

Basic String-Based Child Entity

php bin/console make:es:entity "Product\ProductAggregate\ProductVariant" "App\Product\Domain\ProductAggregate" --main-value-type="string" --main-value-name="sku"

This will generate:

  • App\Product\Domain\Entity\ProductVariant\ProductVariant - The child entity class
  • Events, repository, factory, and exceptions for the child entity

Boolean-Based Child Entity (Simple Entity)

php bin/console make:es:entity "User\UserAggregate\UserPreference" "App\User\Domain\UserAggregate" --main-value-type="bool" --main-value-name="isEnabled"

This will generate:

  • App\User\Domain\Entity\UserPreference\UserPreference - A simple child entity with boolean state
  • Activation/deactivation events and methods

Nested Child Entity with Custom Machine Name

php bin/console make:es:entity "Order\OrderAggregate\OrderItem\ItemDiscount" "App\Order\Domain\OrderAggregate" --main-value-type="float" --main-value-name="amount" --machine-name="ORDER_ITEM_DISCOUNT"

This will generate:

  • App\Order\Domain\Entity\OrderItem\ItemDiscount\ItemDiscount - A nested child entity
  • The machine name "ORDER_ITEM_DISCOUNT" will be used in the entity attributes

Related Projects

The ES Lib ecosystem includes the following projects:

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

awd-studio/es-lib-maker-bundle 适用场景与选型建议

awd-studio/es-lib-maker-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「library」 「ddd」 「es」 「code-generator」 「event-sourcing」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 awd-studio/es-lib-maker-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 awd-studio/es-lib-maker-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 awd-studio/es-lib-maker-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-30