1 | <?php |
||
12 | class ClientRepository implements ClientRepositoryInterface |
||
13 | { |
||
14 | /** |
||
15 | * @var EntityManager |
||
16 | */ |
||
17 | private $entityManager; |
||
18 | |||
19 | /** |
||
20 | * @var EntityRepository |
||
21 | */ |
||
22 | private $repository; |
||
23 | |||
24 | /** |
||
25 | * @var callable |
||
26 | */ |
||
27 | private $secretValidator; |
||
28 | |||
29 | /** |
||
30 | * @param EntityManager $entityManager |
||
31 | * @param callable|null $secretValidator |
||
32 | */ |
||
33 | public function __construct(EntityManager $entityManager, callable $secretValidator = null) |
||
39 | |||
40 | /** |
||
41 | * @param string $clientIdentifier |
||
42 | * @param string $grantType |
||
43 | * @param string|null $clientSecret |
||
44 | * @param bool $mustValidateSecret |
||
45 | * @return ClientEntityInterface|null |
||
46 | */ |
||
47 | public function getClientEntity($clientIdentifier, $grantType, $clientSecret = null, $mustValidateSecret = true) |
||
58 | |||
59 | /** |
||
60 | * @return QueryObject |
||
61 | */ |
||
62 | protected function createQuery(): QueryObject |
||
66 | } |
||
67 |
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.