我只是问一个问题,我们可以将所有教条(orm和dbal)配置放在供应商包中本地化的config.yml文件中吗?以及如何在此捆绑包之外访问此实体管理器?
先谢谢
EDIT1:
我认为通过使用PrependExtensionInterface可以实现:
//vendor/XXXXBundle/DependencyInjection/XXXXExtension.php
class XXXXExtension extends Extension implements PrependExtensionInterface
{
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');
}
public function prepend(ContainerBuilder $container)
{
$configFile = __DIR__ . '/../Resources/config/config.yml';
$content = Yaml::parse(
file_get_contents($configFile)
);
$container->prependExtensionConfig('', $content);
}
}
# vendor/XXXXBundle/Resources/config/config.yml
imports:
- { resource: parameters.yml }
doctrine:
dbal:
default_connection: default_conn
connections:
default:
driver: "%XXXXBundle.database_driver%"
host: "%XXXXBundle.database_host%"
port: "%XXXXBundle.database_port%"
dbname: "%XXXXBundle.database_name%"
user: "%XXXXBundle.database_user%"
password: "%XXXXBundle.database_password%"
charset: UTF8
orm:
default_entity_manager: default_em
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
entity_managers:
default_em:
connection: default_conn
mappings:
XXXXBundle:
type: annotation
is_bundle: false
dir: %kernel.root_dir%/../vendor/awcb/Aw/Common/Model/XXXXBundle/Entity
prefix: Aw\Common\Model\XXXXBundle\Entity
alias: XXXXBundle
# vendor/YYYYBundle/Resources/config/services.yml
services:
common_business_profile:
class: Aw\Common\Business\ProfileBundle\Lib\ProfileLibrary
arguments: ["@doctrine.orm.default_em"] # already tried default_entity_manager and entity_manager
我收到错误:
服务" common_business_profile"依赖于不存在的服务" doctrine.orm.entity_manager"。
你可以注意到一个php应用程序/控制台容器:debug显示没有教条。*已加载... 你能帮帮我吗? :)
此致