How do I get a list of bundles in symfony2/symfony3?

前端 未结 5 860
被撕碎了的回忆
被撕碎了的回忆 2021-02-02 12:14

I\'ve just started using symfony and I\'d like to get a list of bundles from a particular vendor, iterate through them and call a $bundle->renderSomething() function on each def

5条回答
  •  -上瘾入骨i
    2021-02-02 12:36

    1. You can define a static function in each bundle. Ex: YourBundle::yourStaticFunction();
    2. Use $this->container->getParameter('kernel.bundles') to get the list of bundles. This only returns the bundle class names instead of the Bundle object. Go through each bundle, check if the bundle has the function yourStaticFunction(), Hint: Use method_exists(). If the method exists, then call ::yourStaticFunction();

提交回复
热议问题