twc/maker-bundle

包装 maker bundle 以引入上下文选项以更改目标模板

安装次数: 15,675

依赖项: 0

建议者: 0

安全性: 0

星标: 14

关注者: 4

分支: 3

开放问题: 0

类型:symfony-bundle

v7.0.2 2024-08-13 17:42 UTC

This package is auto-updated.

Last update: 2024-09-13 17:52:53 UTC


README

build passing

当你的 symfony 架构不同(如 ddd, cqrs, adr, 自定义架构)时,你会失去 makerBundle 的强大功能,因为目录结构不在同一位置。TwcMakerBundle 试图解决这个问题,通过包装 maker 命令并引入 "context" 选项。

安装

composer require twc/maker-bundle --dev

基本用法

通用配置

#config/packages/dev/twc_maker.yaml
twc_maker:
    componentName:
        - { context: 'contextName', target: 'Your\SpecificNamespace' }
        - { context: 'contextName1', target: 'Your\SpecificNamespace' }
        - ...

特定配置

组件实体

对于实体组件,你必须使用 target_entitytarget_repository 而不是 target

#config/packages/dev/twc_maker.yaml
twc_maker:
    entity:
        - { context: 'contextName', target_entity: 'Your\SpecificEntityNamespace', target_repository: 'Your\SpecificRepositoryNamespace' }

组件控制器

对于控制器,你可以指定 dir 来更改生成文件夹(默认 contextName)

#config/packages/dev/twc_maker.yaml
twc_maker:
    controller:
        - { context: 'contextName', target: 'Your\SpecificNamespace', dir: 'my/custom/directory/template' }

控制台

TwcMakerBundle 包装 maker 命令并添加新的选项 --context(快捷键 -c)

带有 CQRS 概念的示例

#config/packages/dev/twc_maker.yaml
twc_maker:
    message:
        - { context: 'post.command', target: 'App\Post\Application\Command' }
        - { context: 'post.query', target: 'App\Post\Application\Query' }

在你的控制台

php bin/console make:twc:message NewPost --context=post.command
php bin/console make:twc:message AllPostsArchivedQuery --context=post.query
#shortcut version
php bin/console make:twc:message NewPost -c post.command
php bin/console make:twc:message AllPostsArchivedQuery -c post.query

结果

created: src/Post/Application/Command/NewPost.php
created: src/Post/Application/Command/NewPostHandler.php
created: src/Post/Application/Query/AllPostArchivedQuery.php
created: src/Post/Application/Query/AllPostArchivedQueryHandler.php

带有 DDD 概念的示例

#config/packages/dev/twc_maker.yaml
twc_maker:
    entity:
        - { context: 'membership', target_entity: 'App\MemberShip\Domain\Entity', target_repository: 'App\MemberShip\Infrastructure\Doctrine\Repository' }
    controller:
        - { context: 'membership', target: 'App\MemberShip\Presenter\Controller' }
    form:
        - { context: 'membership', target: 'App\MemberShip\Presenter\Form' }

在你的控制台

php bin/console make:twc:entity UserMembership -c membership

结果

created: src/Membership/Domain/Entity/UserMemberShip.php
created: src/Membership/Infrastructure/Doctrine/Repository/UserMemberShipRepository.php

故障排除

特定目录未创建

如果你的特定目录未创建,请清理缓存并重试。

php bin/console c:c 

无法确定新类的位置

如果你收到如下错误信息

Could not determine where to locate the new class "xxx" maybe try with a full namespace like 

检查你的 composer.json 中的 PSR-4 配置,可能需要添加你的命名空间,或者尝试使用 App\

支持

实际上 TwcMakerBundle 包装了 9 个组件