1 | <?php |
||
20 | class DoctrineORMStorage implements StorageInterface |
||
21 | { |
||
22 | /** |
||
23 | * @var \Doctrine\ORM\EntityManager |
||
24 | */ |
||
25 | protected $em; |
||
26 | /** |
||
27 | * @var \Doctrine\ORM\EntityRepository |
||
28 | */ |
||
29 | protected $repository; |
||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $class; |
||
34 | /** |
||
35 | * @param EntityManager $em |
||
36 | * @param string $class |
||
37 | */ |
||
38 | public function __construct(EntityManager $em, $class) |
||
44 | /** |
||
45 | * @param string $key |
||
46 | * @return mixed|null Null if the value is not found |
||
47 | */ |
||
48 | public function get($key) |
||
57 | /** |
||
58 | * @param string $key |
||
59 | * @param mixed $value |
||
60 | */ |
||
61 | public function set($key, $value) |
||
73 | /** |
||
74 | * @param string $key |
||
75 | */ |
||
76 | public function remove($key) |
||
84 | } |
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.