修改另一个捆绑软件的捆绑软件配置 [英] Modify bundle configuration from another bundle
问题描述
我想知道是否可以从另一个捆绑软件中修改捆绑软件配置。例如,假设我使用FOSUserBundle并具有以下配置:
I was wondering whether there's a possible to modify a bundles configuration from another bundle. Let's say, for example, I'm using the FOSUserBundle with the following configuration:
fos_user:
db_driver: orm
firewall_name: main
user_class: Acme\UserBundle\Entity\User
现在,我想在加载特定扩展名( AcmeFoobarExtension
)时更改用户类。加载
AcmeFoobarExtension
时是否可以更改配置?例如:
And now, I want to change the user class when loading a specific extension (the AcmeFoobarExtension
). Is it possible to change the configuration when loading
the AcmeFoobarExtension
? For example:
<?php
namespace Acme\FoobarBundle\DependencyInjection;
// use statements for dependency injection
class FoobarExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$container->setConfiguration(
'fos_user.user_class',
'Acme\FoobarBundle\Entity\User'
);
}
}
是否可能这样?还是打败了依赖注入的目的?
Is something like this possible? Or defeats it the purpose of dependency injection?
编辑:显然有一个对Symfony 2.2的拉动请求,解决了这个想法/问题。
Apparently there's a pull request for Symfony 2.2 which addresses this idea/issue.
编辑2:现在在Symfony 2.2中可用(带有一个食谱中的文章)。
EDIT 2: This is now available in Symfony 2.2 (with an article in the cookbook).
推荐答案
应该注意,这现在是Symfony的正式功能:
It should be noted that this is now an official feature of Symfony:
http://symfony.com/doc/current/cookbook/bundles/prepend_extension.html
捆绑软件可以在全局配置参数之前添加配置值。为此,bundle扩展必须实现 PrependExtensionInterface
。然后 prepend()
方法可以添加全局配置值。
A bundle can prepend configuration values to the global config parameters. To do that, the bundle extension must implement PrependExtensionInterface
. The prepend()
method can then add global configuration values.
但是请注意,这些值可能会被覆盖
Note, however, that the values may be overwritten by other bundles and in the config file itself.
这篇关于修改另一个捆绑软件的捆绑软件配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!