Override symfony2 console commands?

后端 未结 4 1936
囚心锁ツ
囚心锁ツ 2020-12-10 04:56

Is it possible to override symfony2 app/console commands? For example, in the FOS UserBundle I\'d like to add a few more fields it asks when it creates a user with its cons

4条回答
  •  孤城傲影
    2020-12-10 05:23

    Symfony 4 has removed bundle inheritance, but you can still override commands by decorating them. It's cleaner and doesn't require a bundle. Just add this to services.yaml:

    services:
        App\Command\MyCustomCommand:
            decorates: command_you_want_to_override
    

    Note that command_you_want_to_override is a service name. For older, pre-Symfony 3.3 commands it will be something in lowercase with dots and underscores (eg. doctrine_migrations.diff_command), for newer ones it will be a class name. You can find this name by inspecting its bundle's service config or by searching through output of debug:container. On Linux or macOS it would be:

    php bin/console debug:container | grep Command
    

提交回复
热议问题