是的,每个包都有自己的配置文件。
# src/Acme/YourBundle/Resources/config/services.yml
services:
X:
class: X
arguments: [@database_connection]
捆绑配置通过 DIC 加载。所以你的包中的这个文件很重要
// src/Acme/YourBundle/DependencyInjection/AcmeYourBundleExtension.php
namespace Acme\YourBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
/**
* This is the class that loads and manages your bundle configuration
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class AcmeYourExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
}
通常,您应该在特定捆绑包中配置所有服务,services.yml
而不是在config.yml
. 所以你可以重复使用它们。但是该服务对于整个应用程序都是可见的,而不仅仅是捆绑包。但这应该没有问题。