Skip to content

Leverage Symfony's MakerBundle to generate boilerplate code. #13

Closed
@b00gizm

Description

@b00gizm

In order to make it easier for users to adopt DDD, it would be great to provide custom Makers to generate boilerplate code and organize code in a more DDD-preferred/conform way.

Some ideas:

MakeModel

  • Lives in src/Domain/Model
  • Can inherit from AggregateRoot
  • Can have a dedicated identity value object (e.g. OrderOrderId / OrderUuid)
  • If also used as Doctrine entity, choice between annotations and separate config in src/Infrastructure/Doctrine/ORM/config
    • If used with annotations, the Doctrine config must be updated to accommodate for the custom path

MakeRepsitory

  • Lives (as interface) in src/Domain/Repository
  • Extends the Repository contract from geekcell/php-ddd
  • Can have a Doctrine implementation, which lives in src/Infrastructure/Doctrine/ORM/Repository
    • Inherits from GeekCell\DddBundle\Infrastructure\Doctrine\Repository
    • Parent constructor needs to know about the managed entity

MakeCommand / MakeQuery

  • Lives in src/Application/{Command,Query}
  • Implements the Command / Query contract from geekcell/ddd
  • Has a corresponding command/query handler
    • Same name as command/query with Handler suffix
    • Implements the CommandHandler / QueryHandler contract from geekcell/ddd
    • Has a #[AsMessageHandler] annotation
    • Has a __invoke method with the corresponding command/query as argument

MakeResource

  • API Platform resource (> 2.7)
  • Lives in src/Infrasturcture/ApiPlatform/Resource
  • Has a corresponding model (e.g. OrderOrderResource)
  • The resource has a convenience method public static fromModel(...)
    • Choice between annotations or separate config
    • config/packages/api_platform.yaml needs to be updated with the custom resource path
    • Can have one or more data provider (read operations) which live in src/Infrasturcture/ApiPlatform/State
      • Has a query bus
    • Can have one or more data processors (write operations) which live in src/Infrasturcture/ApiPlatform/State
      • Has a command bus

MakeController

  • Lives in src/Infrastructure/Http/Controller
  • Can have a command bus, a query bus, or both
  • Other than that → standard Symfony configuration
### Makers to implement
- [x] Add Maker for domain models (`MakeModel`) https://github.com/geekcell/ddd-symfony-bundle/pull/14
- [x] Add Maker for repositories (`MakeRepository`) https://github.com/geekcell/ddd-symfony-bundle/pull/14
- [x] Add Maker for commands and queries (`MakeCommand`, `MakeQuery`) https://github.com/geekcell/ddd-symfony-bundle/pull/21
- [x] Add Maker for API Platform resources (`MakeResource`) https://github.com/geekcell/ddd-symfony-bundle/pull/25
- [x] Add Maker for controllers `MakeController`) https://github.com/geekcell/ddd-symfony-bundle/pull/22

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requesthelp wantedExtra attention is needed

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions