How can i inject dependencies to Symfony Console commands?

后端 未结 7 1022
醉话见心
醉话见心 2020-12-09 08:00

I\'m writing an open source application uses some Symfony components, and using Symfony Console component for interacting with shell.

But, i need to inject dependen

7条回答
  •  情歌与酒
    2020-12-09 08:06

    I'm speaking for symfony2.8. You cannot add a constructor to the class that extends the ContainerAwareCommand because the extended class has a $this->getContainer() which got you covered in getting your services instead of injecting them via the constructor.

    You can do $this->getContainer()->get('service-name');

提交回复
热议问题