我正在使用doctrine orm在silex中使用auth系统,并且在这个doc http://silex.sensiolabs.org/doc/providers/security.html#defining-a-custom-user-provider下面的架构中有信息听起来像这样:
“如果您使用的是Doctrine ORM,则Doctrine的Symfony桥提供了一个能够从您的实体加载用户的用户提供程序类 . ”
我正在使用Dotrine ORM提供程序,所以我决定从Symfony \ Bridge \ Doctrine \ Security \ User使用EntityUserProvider类,问题是这个类的构造函数,因为第一个参数有“ManagerRegistry $ registry” .
我应该从silex那里放什么?是否有专门的服务或对象?
1 回答
在Symfony2上下文中,根据Doctrine和Symfony Doctrine Bridge源代码,您需要注入名为
doctrine
的服务,该服务将connection
,entity manager
,default connection
和default entity manager
作为参数 . 此服务在vendor\{...}\Doctrine\Bundle\DoctrineBundle\Resources\config\dbal.xml
中定义 .(此服务是
Doctrine\Bundle\DoctrineBundle\Registry
的一个实例,它扩展了抽象类Symfony\Bridge\Doctrine\ManagerRegistry
,它扩展了最终实现接口Doctrine\Common\Persistence\ManagerRegistry
的Doctrine\Common\Persistence\AbstractManagerRegistry
,这是类型提示类 . )如Silex providers documentation according Doctrine的前几行中所述,未提供ORM服务 . 由于您使用自定义提供程序来使用ORM,因此需要为此
doctrine
服务注入等效项 .