1 | <?php |
||
13 | class ScopeRepository implements ScopeRepositoryInterface |
||
14 | { |
||
15 | /** |
||
16 | * @var EntityManager |
||
17 | */ |
||
18 | private $entityManager; |
||
19 | |||
20 | /** |
||
21 | * @var EntityRepository |
||
22 | */ |
||
23 | private $repository; |
||
24 | |||
25 | /** |
||
26 | * @param EntityManager $entityManager |
||
27 | */ |
||
28 | public function __construct(EntityManager $entityManager) |
||
33 | |||
34 | /** |
||
35 | * @param string $identifier |
||
36 | * @return ScopeEntityInterface |
||
37 | */ |
||
38 | public function getScopeEntityByIdentifier($identifier) |
||
42 | |||
43 | /** |
||
44 | * @param array $scopes |
||
45 | * @param string $grantType |
||
46 | * @param ClientEntityInterface $clientEntity |
||
47 | * @param string|null $userIdentifier |
||
48 | * @return ScopeEntityInterface[] |
||
49 | */ |
||
50 | public function finalizeScopes( |
||
59 | |||
60 | /** |
||
61 | * @return QueryObject |
||
62 | */ |
||
63 | protected function createQuery(): QueryObject |
||
67 | } |
||
68 |
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.