Php 如何在Symfony 4中将配置从一个包添加到另一个包

Php 如何在Symfony 4中将配置从一个包添加到另一个包,php,symfony,configuration,bundle,Php,Symfony,Configuration,Bundle,我在中找到PrependExtensionInterface,并认为它可以用于解决以下问题:我想添加security.access_控件的路径,就像它们对细枝和主题所做的那样。所以我试着: public function prepend(ContainerBuilder $container) { $bundles = $container->getParameter('kernel.bundles'); if (isset($bundle

我在中找到PrependExtensionInterface,并认为它可以用于解决以下问题:我想添加security.access_控件的路径,就像它们对细枝和主题所做的那样。所以我试着:

    public function prepend(ContainerBuilder $container)
    {
        $bundles = $container->getParameter('kernel.bundles');

        if (isset($bundles['SecurityBundle'])) {
            $config = $this->processConfiguration(new Configuration(), $container->getExtensionConfig('security'));
            $config['access_control'][] = ['path' => '^my/new/path', 'role' =>'IS_AUTHENTICATED_ANONYMOUSLY'];
            $container->prependExtensionConfig('security', $config);
        }
    }
但是我在processConfiguration()中遇到一个错误,它告诉我安全性中的所有密钥都是未知的,并显示了包中的已知密钥:

Unrecognized options "providers, role_hierarchy, encoders, firewalls" under "<name of my bundle>". Available options are ... (keys from my bundle configuration)
现在我使用了正确的配置,但无法正常工作:

Unrecognized options "anonymous, guard, remember_me" under "security.firewalls.main". Available options are "access_denied_handler", "access_denied_url", "context", "entry_point", "host", "logout", "logout_on_user_change", "methods", "pattern", "provider", "request_matcher", "security", "stateless", "switch_user", "user_checker".

我想我错过了一些工厂,但我无法为此重新设计整个安全包…

它的行为是这样的,因为您正在加载的
配置
类来自您的包,而不是安全包。一个更好的问题是你为什么要这么做?也许有更好的解决办法。查看安全包,看看它发布了哪些参数,也许您可以从that.Thx中获得所需的值。我理解。不幸的是,要实例化安全包的配置,您需要另外两个对象,我没有。因此,此解决方案不适用于安全性,但可能适用于具有正常配置对象的其他捆绑包。是否有其他通用解决方案可在您自己的捆绑包的外部捆绑包配置中添加值或设置默认值?
Unrecognized options "anonymous, guard, remember_me" under "security.firewalls.main". Available options are "access_denied_handler", "access_denied_url", "context", "entry_point", "host", "logout", "logout_on_user_change", "methods", "pattern", "provider", "request_matcher", "security", "stateless", "switch_user", "user_checker".