我已经使用保护设置了一个自定义身份验证器并自动连接了服务。这是经过测试的,只配置了 MySQL 就可以正常工作。
我现在指定了第二个数据库连接(oracle),但是 Symfony 现在不允许在我的服务配置中自动装配,因为它不知道在将 EntityManager 注入自定义 Authenticator 类时要使用哪个数据库连接。
知道如何配置依赖注入以使用特定的数据库连接,这样我就可以继续使用 AutoWire。
Unable to autowire argument of type "Doctrine\ORM\EntityManager" for the service "user.security.login_form_authenticator". Multiple services exist for this class (doctrine.orm.prism_entity_manager, doctrine.orm.baan_entity_manager).
这是我在 config.yml 中的教义配置
doctrine:
dbal:
connections:
prism:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/../var/data/data.sqlite"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
#path: "%database_path%"
baan:
driver: oci8
host: "%baan_host%"
port: "%baan_port%"
dbname: "%baan_db_name%"
user: "%baan_user%"
password: "%baan_password%"
charset: AL32UTF8
orm:
default_entity_manager: prism
auto_generate_proxy_classes: "%kernel.debug%"
entity_managers:
auto_mapping: true
prism:
naming_strategy: doctrine.orm.naming_strategy.underscore
connection: prism
mappings:
UserBundle:
type: annotation
baan:
connection: baan
mappings:
BaanBundle:
type: annotation
这是我的 Authenticator 类中的构造函数
private $formFactory;
private $em;
private $router;
public function __construct(FormFactoryInterface $formFactory, EntityManager $em, RouterInterface $router)
{
$this->formFactory = $formFactory;
$this->em = $em;
$this->router = $router;
}