4

我正在使用教义 orm 在 silex 中开发身份验证系统,并且在此文档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那里放什么?是否有专门的服务或对象?

4

1 回答 1

1

在 Symfony2 上下文中,根据 Doctrine 和 Symfony Doctrine Bridge 源代码,您需要注入调用的服务,该服务doctrine接受 a connection、 an entity manager、 thedefault connection和 thedefault entity manager作为参数。该服务定义在vendor\{...}\Doctrine\Bundle\DoctrineBundle\Resources\config\dbal.xml.

(此服务是扩展抽象类的实例,Doctrine\Bundle\DoctrineBundle\Registry该抽象类Symfony\Bridge\Doctrine\ManagerRegistry扩展Doctrine\Common\Persistence\AbstractManagerRegistry最终实现接口Doctrine\Common\Persistence\ManagerRegistry,即类型提示类。)

正如根据 Doctrine 的 Silex 提供程序文档的前几行所述,不提供 ORM 服务。由于您使用自定义提供程序来使用 ORM,因此您需要注入此doctrine服务的等效项。

于 2013-09-24T06:15:33.810 回答