1 | <?php |
||
13 | class Doctrine implements SocialUserStorageInterface |
||
14 | { |
||
15 | /** |
||
16 | * @var EntityManager |
||
17 | */ |
||
18 | protected $em; |
||
19 | |||
20 | /** |
||
21 | * Social user Entity class name |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $entity = SocialUser::class; |
||
26 | |||
27 | 4 | public function __construct(EntityManager $entityManager, array $options = null) |
|
42 | |||
43 | /** |
||
44 | * @param string $provider |
||
45 | * @param string $identifier |
||
46 | * |
||
47 | * @return SocialUserInterface|null |
||
48 | */ |
||
49 | 1 | public function findByProviderIdentifier($provider, $identifier) |
|
58 | |||
59 | /** |
||
60 | * @param int $user_id |
||
61 | * @param string $identifier |
||
62 | * @param string $provider |
||
63 | * |
||
64 | * @return SocialUserInterface |
||
65 | * @throws \Doctrine\ORM\ORMException |
||
66 | */ |
||
67 | 1 | public function addSocialUser($user_id, $identifier, $provider) |
|
80 | } |
||
81 |
The
EntityManager
might become unusable for example if a transaction is rolled back and it gets closed. Let’s assume that somewhere in your application, or in a third-party library, there is code such as the following:If that code throws an exception and the
EntityManager
is closed. Any other code which depends on the same instance of theEntityManager
during this request will fail.On the other hand, if you instead inject the
ManagerRegistry
, thegetManager()
method guarantees that you will always get a usable manager instance.