Symfony 6.1获取另一个捆绑配置数据
我正在尝试从我的捆绑包中获取一个捆绑包的配置,并使用新的,简化的捆绑包配置在 https://symfony.com/blog/new-inew-inew-inem-symfony-6-1-1-simpler-bundle-bundle-eastension-extension-astension-uspension-ash-configuration
我的捆绑包具有Symfony/Maker-Bundle作为依赖性,我想知道Maker-Bundle的配置,
maker:
root_namespace: MyApp
我试图弄清楚我可以访问该信息的位置,尤其是因为我不再有明确的mybundleextension类。当我的捆绑包加载时,参数“ maker.root_namespace”不在容器参数袋中。因此,我添加了一个CompilerPass,那里也不可见。
我已经尝试使用prepend()和pedendextension()调用,但是不确定如何将其连接到新的束配置,甚至是正确的位置。
当我在特定情况下使用Symfony/Maker-Bundle时,我经常想知道其他捆绑式配置的值,这似乎是一件很常见的事情。我怀疑在不创建扩展类别的情况下可能是可能的,但不确定如何。
I'm trying to get the configuration of one bundle from within my bundle, configured using the new, simplified bundle configuratation at https://symfony.com/blog/new-in-symfony-6-1-simpler-bundle-extension-and-configuration
My bundle has symfony/maker-bundle as a dependency, and I'd like to know maker-bundle's configuration
maker:
root_namespace: MyApp
I'm trying to figure out where I have access to that information, especially since I no longer have an explicit MyBundleExtension class. When my bundle is loading, the parameter 'maker.root_namespace' is not in the container parameterBag. So I added a CompilerPass, and it's not visible there either.
I've tried using the prepend() and prependExtension() calls, but am not sure how to wire those in to the new bundle configuration, or even if that's the right place.
While I'm using the symfony/maker-bundle in the particular case, I often want to know the values of other bundle configurations, and it seems like a pretty common thing. I suspect it's possible without creating an Extension class, but not sure how.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当前可以在
predendextension()
方法中访问其他捆绑包配置,这是推荐的地方:但是,此方法旨在预先启动更多的配置来不获取/处理这些配置。因此,您必须考虑到它是未经加工和未合并的配置列表,如果另一个扩展名在您自己的扩展程序之后向MakerBundle进行新的配置,则可以更改。
此外,此
root_namespace
的值可以(在这种情况下很可能)参数或env var(毫无意义,但仍然是可能的),这目前尚未解决(原始值)。选项1(安全)
在您的
myMakerBundle :: configure()
方法中创建类似的配置,并预处从MakerBundle扩展名获得的方法:https://symfony.com/doc/current/current/bundles/prepend_extsimpension.htmel.html ),
因为这是仅在开发模式中使用的简单配置,因此您可以直接执行简单的
$ config = array_merge(... $ configs)
以获取$ config [' root_namespace']
value:第二个选项也可以在compilerpass中完成,也可以在不需要创建时间参数的好处。
选项3(风险)
在编译类中,从属于MakerBundle的以下服务之一获取根名称空间值:
maker.generator.generator.generator
参数1(例如$ container-> getDefinition('maker.generator') - > getArgument(1)
)maker.autoloader_finder_finder < / 您可能会期望。
Accessing other bundle configurations is currently possible in the
prependExtension()
method and it's the recommended place to do it:However, this method is meant to prepend more configs not to get/process these configs. So you have to take into account that it's a list of unprocessed and unmerged configs which can change if another extension is prepending a new config to the MakerBundle after your own extension.
Further, the value of this
root_namespace
can be (less probable in this case) a parameter or env var (makes no sense but is still possible) which is not resolved at this point (raw value).Option 1 (Safest)
Create a similar configuration in your
MyMakerBundle::configure()
method and prepend the one obtained from the MakerBundle extension:https://symfony.com/doc/current/bundles/prepend_extension.html
Option 2 (Risky)
Because it's a simple configuration used in dev mode only, you can do a simple
$config = array_merge(...$configs)
directly to get the$config['root_namespace']
value:This second option can be done in a CompilerPass too with the benefit that you wouldn't need to create a temporal parameter.
Option 3 (Risky)
In a CompilerPass class, get the root namespace value from one of the following services belonging to the MakerBundle:
maker.generator
argument 1 (e.g$container->getDefinition('maker.generator')->getArgument(1)
)maker.autoloader_finder
argument 0.I know, so far it's not as simple and intuitive as you might expect.
在公认的答案中:
$容器 - &gt; predendextensionconfig应该是$ builder-&gt; predendextensionconfig
在第15行的“选项1(最安全)”中
In the accepted answer:
$container->prependExtensionConfig should be $builder->prependExtensionConfig
in 'Option 1 (Safest)' on line 15