我正在使用 Doctrine 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那里放什么?是否有专门的服务或对象?
最佳答案
在 Symfony2 上下文中,根据 Doctrine 和 Symfony Doctrine Bridge 源代码,您需要注入(inject)名为 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\AbstractManagerRegistry
,它最终实现了接口(interface) Doctrine\Common\Persistence\ManagerRegistry
,它是类型提示类。)
正如 Silex providers documentation according Doctrine 的前几行所述,不提供 ORM 服务。由于您使用自定义提供程序来使用 ORM,因此您需要注入(inject)与此 doctrine
等效的内容。服务。
关于symfony - 带有 Doctrine ORM 的 Silex 身份验证系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15284837/