1 | <?php |
||
13 | class DoctrineStorage implements StorageInterface |
||
14 | { |
||
15 | /** |
||
16 | * @var EntityManager |
||
17 | */ |
||
18 | private $entityManager; |
||
19 | |||
20 | /** |
||
21 | * @var EntityRepository |
||
22 | */ |
||
23 | private $repository; |
||
24 | |||
25 | /** |
||
26 | * @param EntityManager $em |
||
27 | * @param EntityRepository $repository |
||
28 | */ |
||
29 | public function __construct( |
||
37 | |||
38 | /** |
||
39 | * @return array |
||
40 | */ |
||
41 | public function all() |
||
45 | |||
46 | /** |
||
47 | * {@inheritdoc} |
||
48 | */ |
||
49 | public function find(QueueName $queueName, $server = null, $procId = null) |
||
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | */ |
||
57 | public function set(QueueName $queueName, $server, $procId) |
||
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | */ |
||
72 | public function get(QueueName $queueName, $server, $procId) |
||
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | public function remove(QueueName $queueName, $server, $procId) |
||
88 | |||
89 | /** |
||
90 | * {@inheritdoc} |
||
91 | */ |
||
92 | public function removeForce(QueueName $queueName, $server) |
||
100 | |||
101 | |||
102 | /** |
||
103 | * @param QueueName $queueName |
||
104 | * @param string|null $server |
||
105 | * @param string|null $procId |
||
106 | * @return array |
||
107 | */ |
||
108 | protected function createCriteria(QueueName $queueName, $server = null, $procId = null) |
||
128 | |||
129 | } |
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.