Override symfony2 console commands?

后端 未结 4 1930
囚心锁ツ
囚心锁ツ 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:22

    You can override a bundle's console command(s) if you create (or already have) your own bundle which is a child of that bundle (see Bundle Inheritance). Then by placing a class in your bundle with the same location/name as the original command you effectively override it.

    So for example, to override FOS/UserBundle/Command/CreateUserCommand.php, create MyCompany/UserBundle/Command/CreateUserCommand where MyCompanyUserBundle has FOSUserBundle as it's parent.

    Your command class could extend the FOS command class in order to re-use (bits of) it. However, having looked at the FOS CreateUserCommand I think you would need to override all the methods to add more input fields in which case there is no benefit to doing this. Of course this also means you could just create your own command in any bundle but in my opinion it's better to keep the customisation of FOSUserBundle in a child bundle.

提交回复
热议问题