Symfony Maker Bundle 自己的 Crud Maker

Symfony4 MakerBundle Own Crud Maker

我想自定义新的 makerbundle crud maker 的样板代码。没有像在 SensioGeneratorBundle 中那样简单地覆盖模板。我试图根据原始代码生成自定义 MyMakeCrud - 但我对注入的 DoctrineEntityHelper $entityHelper 感到困惑。

 Cannot autowire service "App\Maker\MakeMyCrud": argument "$entityHelper" of
 method "__construct()" references class "Symfony\Bundle\MakerBundle\Doctri
 ne\DoctrineEntityHelper" but no such service exists. You should maybe alias
 this class to the existing "maker.doctrine_entity_helper" service.

现有的 maker.doctrine_entity_helper 在制造商包中定义为私有。我怎样才能注射到运行?

你能帮帮我吗?有没有人有定制 crud 生成的例子? SF4 中的新内容。

您必须为它定义一个服务,如下所示:

    app.maker.make_crud:
    class: App\Maker\MakeCrud
    arguments: ['@maker.doctrine_helper']
    calls:
        - [configureCommand, ['@security.command.user_password_encoder', '@?']]
        - [interact, ['@?', '@?', '@security.command.user_password_encoder']]
    tags:
        - { name: maker.command }

我把这个放在 config/services.yaml.

App\Maker\MakeCrud 是你的污垢制造者 class。

真的应该把它放在 services_dev.yaml 文件中。

希望对您有所帮助。

非常感谢你们 post。我也必须自定义 MakeCrud 命令。 这是版本 5 对我有用的配置。

app.maker.make_crud:
    class: App\Maker\MakeCrudCommand
    arguments: ['@maker.doctrine_helper', '@maker.renderer.form_type_renderer']
    calls:
        - [configureCommand, ['@security.command.user_password_encoder', '@?']]
        - [interact, ['@?', '@?', '@security.command.user_password_encoder']]
    tags:
        - { name: maker.command }